예제 #1
0
        // fund 1, bigger than fund 2;
        // makeing fund 1;
        public void printToTextBox()
        {
            richTextBox2.Text += String.Format("\nFund 1: " + Fund1.Money + "  |  Fund 2: " + Fund2.Money);

            Fund1.setShares();
            Fund2.setShares();
            if (tempBool)
            {
                richTextBox1.Text += "\nFunds are about to Trade : " + stopWatch.Elapsed.ToString() + " Buy | Buy" + " " + Fund1.Shares * 1000f + " | " + Fund2.Shares * 1000f;
            }
            else if (tempBool1)
            {
                richTextBox1.Text += "\nFunds are about to Trade : " + stopWatch.Elapsed.ToString() + " Buy | Sell" + " " + Fund1.Shares * 1000f + " | " + Fund2.Shares * 1000f;
            }
            else if (tempBool2)
            {
                richTextBox1.Text += "\nFunds are about to Trade : " + stopWatch.Elapsed.ToString() + " Sell | Buy" + " " + Fund1.Shares * 1000f + " | " + Fund2.Shares * 1000f;
            }
            else if (tempBool3)
            {
                richTextBox1.Text += "\nFunds are about to Trade : " + stopWatch.Elapsed.ToString() + " Sell | Sell" + " " + Fund1.Shares * 1000f + " | " + Fund2.Shares * 1000f;
            }
            else if (tempBool4)
            {
                richTextBox1.Text += "\nFunds are about to Trade : " + stopWatch.Elapsed.ToString() + " Buy | Neutral" + " " + Fund1.Shares * 1000f + " | " + Fund2.Shares * 1000f;
            }
            else if (tempBool5)
            {
                richTextBox1.Text += "\nFunds are about to Trade : " + stopWatch.Elapsed.ToString() + " Sell | Neutral" + " " + Fund1.Shares * 1000f + " | " + Fund2.Shares * 1000f;
            }
            else if (tempBool6)
            {
                richTextBox1.Text += "\nFunds are about to Trade : " + stopWatch.Elapsed.ToString() + " Neutral | Buy" + " " + Fund1.Shares * 1000f + " | " + Fund2.Shares * 1000f;
            }
            else if (tempBool7)
            {
                richTextBox1.Text += "\nFunds are about to Trade : " + stopWatch.Elapsed.ToString() + " Neutral | Sell" + " " + Fund1.Shares * 1000f + " | " + Fund2.Shares * 1000f;
            }
            tempBool  = false;
            tempBool1 = false;
            tempBool2 = false;
            tempBool3 = false;
            tempBool4 = false;
            tempBool5 = false;
            tempBool6 = false;
            tempBool7 = false;
        }
예제 #2
0
        private void getNextEconPrice()
        {
            while (true)
            {
                // random price change of market
                // Simulates efficient market hypothesis which states that the market is unpredictible and is close to being totally random

                double max1 = variables.price * 0.06f;
                double min1 = variables.price * 0.04f;
                double max2 = variables.price * 0.05f;
                double min2 = variables.price * 0.03f;

                int randomInt = random.Next(1, 10);
                if (randomInt < 5)
                {
                    // generates and adds that random price to the equity
                    variables.price += random.NextDouble() * (random.NextDouble() * (max1 - min1) + min1);
                }
                else
                {
                    // generates and subtracts that random price from the equity
                    variables.price -= random.NextDouble() * (random.NextDouble() * (max2 - min2) + min2);
                }

                // Models the effect of funds on the equity
                // the underlying assumption is that the funds have a higher effect on stocks than randomness does

                if (Fund1.returnIntent() == "buy" || Fund1.returnIntent() == "sell" || Fund2.returnIntent() == "buy" || Fund2.returnIntent() == "sell")
                {
                    if (Fund1.returnIntent() == "buy" && Fund2.returnIntent() == "buy")
                    {
                        tempBool         = true;
                        variables.price += variables.price * Sigmoid(Fund1.returnIntensity() + Fund2.returnIntensity()) * 0.01f;
                    }
                    if (Fund1.returnIntent() == "buy" && Fund2.returnIntent() == "sell")
                    {
                        tempBool1        = true;
                        variables.price += variables.price * Sigmoid(Math.Abs(Fund1.returnIntensity() - Fund2.returnIntensity())) * 0.01f;
                    }
                    if (Fund1.returnIntent() == "sell" && Fund2.returnIntent() == "buy")
                    {
                        tempBool2        = true;
                        variables.price -= variables.price * Sigmoid(Math.Abs(Fund1.returnIntensity() - Fund2.returnIntensity())) * 0.01f;
                    }
                    if (Fund1.returnIntent() == "sell" && Fund2.returnIntent() == "sell")
                    {
                        tempBool3        = true;
                        variables.price -= variables.price * Sigmoid(Fund1.returnIntensity() + Fund2.returnIntensity()) * 0.01f;
                    }
                    if (Fund1.returnIntent() == "buy")
                    {
                        tempBool4        = true;
                        variables.price += variables.price * Sigmoid(Fund1.returnIntensity()) * 0.01f;
                    }
                    if (Fund1.returnIntent() == "sell")
                    {
                        tempBool5        = true;
                        variables.price -= variables.price * Sigmoid(Fund1.returnIntensity()) * 0.01f;
                    }
                    if (Fund2.returnIntent() == "buy")
                    {
                        tempBool6        = true;
                        variables.price += variables.price * Sigmoid(Fund2.returnIntensity()) * 0.01f;
                    }
                    if (Fund2.returnIntent() == "sell")
                    {
                        tempBool7        = true;
                        variables.price -= variables.price * Sigmoid(Fund2.returnIntensity()) * 0.01f;
                    }

                    Fund1.buyIntent  = false;
                    Fund2.buyIntent  = false;
                    Fund1.sellIntent = false;
                    Fund2.sellIntent = false;
                }
                // adds the random price to the equity array
                variables.economyArray[variables.economyArray.Length - 1]       = variables.price;
                variables.Fund1MoneyArray[variables.Fund1MoneyArray.Length - 1] = Fund1.Money;
                variables.Fund2MoneyArray[variables.Fund2MoneyArray.Length - 1] = Fund2.Money;
                variables.Fund1Return[variables.Fund1Return.Length - 1]         = Fund1.returnGainsLosses();
                variables.Fund2Return[variables.Fund2Return.Length - 1]         = Fund2.returnGainsLosses();

                // copying array
                Array.Copy(variables.economyArray, 1, variables.economyArray, 0, variables.economyArray.Length - 1);
                Array.Copy(variables.Fund1MoneyArray, 1, variables.Fund1MoneyArray, 0, variables.Fund1MoneyArray.Length - 1);
                Array.Copy(variables.Fund2MoneyArray, 1, variables.Fund2MoneyArray, 0, variables.Fund2MoneyArray.Length - 1);
                Array.Copy(variables.Fund1Return, 1, variables.Fund1Return, 0, variables.Fund1Return.Length - 1);
                Array.Copy(variables.Fund2Return, 1, variables.Fund2Return, 0, variables.Fund2Return.Length - 1);

                if (chart1.IsHandleCreated)
                {
                    // makes delegatet to update chart
                    this.Invoke((MethodInvoker) delegate { UpdateEquityChart(); });
                    this.Invoke((MethodInvoker) delegate { printToTextBox(); });
                }
                else
                {
                    //do something
                }

                Thread.Sleep(100);
            }
        }