Example #1
0
        public void Test_StocksVolumeWeightedStockPrice()
        {
            string stock        = "GIN";
            double lastDividend = 0;
            double stockPrice   = 25;


            CommonStock testStock = new CommonStock(stock, lastDividend, stockPrice);

            //Add 10 trades

            testStock.addTrade(DateTime.Now.AddMinutes(-3), 100, true, 250);   //Sell 100 shares now at 250
            testStock.addTrade(DateTime.Now.AddMinutes(-1), 300, false, 260);  //Buy 300 shares now at 260
            testStock.addTrade(DateTime.Now.AddMinutes(-6), 10, true, 240);    //Sell 10 shares now at 240
            testStock.addTrade(DateTime.Now, 400, true, 230);                  //Sell 400 shares now at 230
            testStock.addTrade(DateTime.Now.AddMinutes(-8), 1000, false, 235); //Sell 1000 shares now at 235
            testStock.addTrade(DateTime.Now.AddMinutes(-30), 100, true, 250);  //Sell 100 shares now at 250
            testStock.addTrade(DateTime.Now.AddMinutes(-16), 300, false, 260); //Buy 300 shares now at 260
            testStock.addTrade(DateTime.Now.AddMinutes(-5), 10, true, 240);    //Sell 10 shares now at 240
            testStock.addTrade(DateTime.Now.AddMinutes(-2), 400, true, 230);   //Sell 400 shares now at 230
            testStock.addTrade(DateTime.Now.AddMinutes(-7), 1000, false, 235); //Sell 1000 shares now at 235

            double expectedResult = (100 * 250.0 + 300 * 260 + 10 * 240 + 400 * 230 + 1000 * 235 + 10 * 240 + 400 * 230 + 1000 * 235) / (100 + 300 + 10 + 400 + 1000 + 10 + 400 + 1000);

            double vwsp = testStock.volumeWeightedStockPrice();

            Assert.AreEqual(expectedResult, vwsp);
        }
Example #2
0
        public void Test_StocksAddTrades()
        {
            string stock        = "GIN";
            double lastDividend = 0;
            double stockPrice   = 25;


            CommonStock testStock = new CommonStock(stock, lastDividend, stockPrice);

            //Add 5 trades

            testStock.addTrade(DateTime.Now.AddMinutes(-3), 100, true, 250);   //Sell 100 shares now at 250
            testStock.addTrade(DateTime.Now.AddMinutes(-1), 300, false, 260);  //Buy 300 shares now at 260
            testStock.addTrade(DateTime.Now.AddMinutes(-6), 10, true, 240);    //Sell 10 shares now at 240
            testStock.addTrade(DateTime.Now, 400, true, 230);                  //Sell 400 shares now at 230
            testStock.addTrade(DateTime.Now.AddMinutes(-8), 1000, false, 235); //Sell 1000 shares now at 235

            Assert.AreEqual(5, testStock.stockTrades.Count);                   //Check there are 5 trades
            Assert.AreEqual(230, testStock.stockTrades.Values[0].tradePrice);  //Check the first trade in the list has a price of 235 - i.e. the most recent trade
        }
Example #3
0
        public void Test_StocksVolumeWeightedStockPriceException()
        {
            string stock        = "GIN";
            double lastDividend = 0;
            double stockPrice   = 25;


            CommonStock testStock = new CommonStock(stock, lastDividend, stockPrice);

            //Add 10 trades

            testStock.addTrade(DateTime.Now.AddMinutes(-23), 100, true, 250);   //Sell 100 shares now at 250
            testStock.addTrade(DateTime.Now.AddMinutes(-21), 300, false, 260);  //Buy 300 shares now at 260
            testStock.addTrade(DateTime.Now.AddMinutes(-26), 10, true, 240);    //Sell 10 shares now at 240
            testStock.addTrade(DateTime.Now.AddMinutes(-22), 400, true, 230);   //Sell 400 shares now at 230
            testStock.addTrade(DateTime.Now.AddMinutes(-28), 1000, false, 235); //Sell 1000 shares now at 235
            testStock.addTrade(DateTime.Now.AddMinutes(-30), 100, true, 250);   //Sell 100 shares now at 250
            testStock.addTrade(DateTime.Now.AddMinutes(-16), 300, false, 260);  //Buy 300 shares now at 260
            testStock.addTrade(DateTime.Now.AddMinutes(-25), 10, true, 240);    //Sell 10 shares now at 240
            testStock.addTrade(DateTime.Now.AddMinutes(-42), 400, true, 230);   //Sell 400 shares now at 230
            testStock.addTrade(DateTime.Now.AddMinutes(-17), 1000, false, 235); //Sell 1000 shares now at 235

            double vwsp = testStock.volumeWeightedStockPrice();
        }