public void GetOptimalProfitPeriod_ShouldPriceValuesWhenTradeHistoryOfOne() { var price = TradePrice.Create(new DateTime(2010, 01, 01), 56, 93); var set = new HashSet <TradePrice> { price }; var stockHistory = new StockHistory(set); var optimalProfit = stockHistory.GetOptimalProfitPeriod(); Assert.IsTrue(ValuesEqual(price, optimalProfit)); }
public void GetOptimalProfitPeriod_ShouldReturnSecondDetailsWhenSecondHistoryItemHigherProfit() { var prices = new TradePrice[] { TradePrice.Create(new DateTime(2010, 01, 01), 35, 30), TradePrice.Create(new DateTime(2010, 01, 02), 30, 35) }; var optimalProfit = GetOptimalProfit(prices); Assert.IsTrue(ValuesEqual(prices.ElementAt(1), optimalProfit)); }
private HashSet <TradePrice> CreatePriceSet() { return(new HashSet <TradePrice> { TradePrice.Create(new DateTime(2009, 03, 05), 117, 112), TradePrice.Create(new DateTime(2009, 03, 06), 112, 110), TradePrice.Create(new DateTime(2009, 03, 07), 110, 122), TradePrice.Create(new DateTime(2009, 03, 08), 122, 129), TradePrice.Create(new DateTime(2009, 03, 09), 129, 124), TradePrice.Create(new DateTime(2009, 03, 10), 124, 134), TradePrice.Create(new DateTime(2009, 03, 11), 134, 133), TradePrice.Create(new DateTime(2009, 03, 12), 133, 132), TradePrice.Create(new DateTime(2009, 03, 13), 132, 131), TradePrice.Create(new DateTime(2009, 03, 14), 131, 130) }); }
public void GetOptimalProfitPeriod_ShouldReturnFirstOpeningSecondClosingDetails() { var prices = new TradePrice[] { TradePrice.Create(new DateTime(2010, 01, 01), 30, 33), TradePrice.Create(new DateTime(2010, 01, 02), 33, 36) }; var optimalProfit = GetOptimalProfit(prices); var correctProfit = new ProfitAnalysis( purchaseDate: prices[0].Date, saleDate: prices[1].Date, purchasePrice: prices[0].OpeningPrice, salePrice: prices[1].ClosingPrice ); Assert.AreEqual(correctProfit, optimalProfit); }