public InvestmentViewModel(Investment investment) { Symbol = investment.Symbol; PurchaseDate = investment.PurchaseDate; PurchasePrice = investment.PurchasePrice / 100; Quantity = investment.Quantity; PurchaseTotal = Quantity * PurchasePrice; if (investment.SellReason != null) { SellReason = investment.SellReason.ToString(); if (investment.SellReason == Mia.Core.SellReason.HighPrice) LabelType = "label-success"; else if (investment.SellReason == Mia.Core.SellReason.LowPrice) LabelType = "label-important"; SellDate = investment.SellDate; SellPrice = investment.SellPrice / 100; SellTotal = Quantity * SellPrice; PriceDifference = (double)((SellPrice.Value - PurchasePrice) / PurchasePrice); PriceDifferenceLabel = (PriceDifference > 0) ? "label-success" : "label-important"; } else { SellReason = "-"; } }
public PlayerViewModel(Investment investment, Quote latestQuote, Player player) { Name = player.Name; Description = player.Description; Symbol = investment.Symbol; CompanyName = latestQuote.Name; CurrentPrice = latestQuote.LastTradePrice.Value / 100; PurchasePrice = investment.PurchasePrice / 100; PurchasedOn = investment.PurchaseDate; ShareQuantity = investment.Quantity; PercentageChange = (double) ((CurrentPrice - PurchasePrice) / PurchasePrice); }
public void ShouldSellInvestment_No_Change() { // Arrange Investment investment = new Investment() { Symbol = "BLAH", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today }; Quote quote = new Quote() { Symbol = "BLAH", LastTradePrice = 1.0m }; // Act StockEngine engine = new YahooStockEngine(); foreach (Player player in engine.GetAllPlayers()) { bool shouldSell = player.ShouldSellInvestment(quote, investment); // Assert Assert.False(shouldSell, "Failed ShouldSellInvestment being false for " + player.Name); Assert.IsNull(investment.SellReason, "Failed SellReason being null for " + player.Name); } }
public void ShouldSellInvestment_Low_Price() { // Arrange Investment investment = new Investment() { Symbol = "BLAH", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today }; Quote quote = new Quote() { Symbol = "BLAH", LastTradePrice = 0.7m }; // Act StockEngine engine = new YahooStockEngine(); foreach (Player player in engine.GetAllPlayers()) { bool shouldSell = player.ShouldSellInvestment(quote, investment); // Assert Assert.True(shouldSell, "Failed ShouldSellInvestment being true for " + player.Name); Assert.That(investment.SellReason, Is.EqualTo(SellReason.LowPrice), "Failed SellReason being Low for " + player.Name); } }
public void ShouldSellInvestment_Boundaries() { // Arrange Investment investment1 = new Investment() { Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today }; Investment investment2 = new Investment() { Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today }; Investment investment3 = new Investment() { Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today }; Investment investment4 = new Investment() { Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today }; Investment investment5 = new Investment() { Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today }; Investment investment6 = new Investment() { Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today }; Investment investment7 = new Investment() { Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today }; Investment investment8 = new Investment() { Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today }; Investment investment9 = new Investment() { Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today }; Quote highQuote1 = new Quote() { Symbol = "BLAH", LastTradePrice = 1.05m }; Quote highQuote2 = new Quote() { Symbol = "BLAH", LastTradePrice = 1.06m }; Quote highQuote3 = new Quote() { Symbol = "BLAH", LastTradePrice = 3.99m }; Quote lowQuote1 = new Quote() { Symbol = "BLAH", LastTradePrice = 0.95m }; Quote lowQuote2 = new Quote() { Symbol = "BLAH", LastTradePrice = 0.49m }; Quote lowQuote3 = new Quote() { Symbol = "BLAH", LastTradePrice = 0 }; Quote noChangeQuote1 = new Quote() { Symbol = "BLAH", LastTradePrice = 0.96m }; Quote noChangeQuote2 = new Quote() { Symbol = "BLAH", LastTradePrice = 1.04m }; Quote noChangeQuote3 = new Quote() { Symbol = "BLAH", LastTradePrice = null }; // Act Chris chris = new Chris(); // 5% change bool shouldSellHigh1 = chris.ShouldSellInvestment(highQuote1, investment1); bool shouldSellHigh2 = chris.ShouldSellInvestment(highQuote2, investment2); bool shouldSellHigh3 = chris.ShouldSellInvestment(highQuote3, investment3); bool shouldSellLow1 = chris.ShouldSellInvestment(lowQuote1, investment4); bool shouldSellLow2 = chris.ShouldSellInvestment(lowQuote2, investment5); bool shouldSellLow3 = chris.ShouldSellInvestment(lowQuote3, investment6); bool shouldSellNoChange1 = chris.ShouldSellInvestment(noChangeQuote1, investment7); bool shouldSellNoChange2 = chris.ShouldSellInvestment(noChangeQuote2, investment8); bool shouldSellNoChange3 = chris.ShouldSellInvestment(noChangeQuote3, investment9); // Assert Assert.True(shouldSellHigh1, "High price 1 to 1.05"); Assert.That(investment1.SellReason, Is.EqualTo(SellReason.HighPrice)); Assert.True(shouldSellHigh2, "High price 1 to 1.06"); Assert.That(investment2.SellReason, Is.EqualTo(SellReason.HighPrice)); Assert.True(shouldSellHigh3, "High price 1 to 3.99"); Assert.That(investment3.SellReason, Is.EqualTo(SellReason.HighPrice)); Assert.True(shouldSellLow1, "Low price 1 to 0.95"); Assert.That(investment4.SellReason, Is.EqualTo(SellReason.LowPrice)); Assert.True(shouldSellLow2, "Low price 1 to 0.49"); Assert.That(investment5.SellReason, Is.EqualTo(SellReason.LowPrice)); Assert.True(shouldSellLow3, "Low price 1 to 0"); Assert.That(investment6.SellReason, Is.EqualTo(SellReason.LowPrice)); Assert.False(shouldSellNoChange1, "No change 1 to 0.96"); Assert.False(shouldSellNoChange2, "No change 1 to 1.04"); Assert.False(shouldSellNoChange3, "No change 1 to (null)"); }
public void SellInvestment() { // Arrange StockEngine engine = new YahooStockEngine(); IEnumerable<Quote> stocks = engine.AllQuotes(); Investment investment = new Investment() { Id = Guid.NewGuid() }; decimal newPrice = 1.1m; // Act engine.SellInvestment(investment.Id, newPrice, SellReason.HighPrice, DateTime.Today); // Assert }
/// <summary> /// /// </summary> /// <param name="player"></param> /// <param name="quote"></param> /// <param name="walletSize">The size of your wallet, in £</param> public void InitializePlayer(Player player, Quote quote, decimal walletSize) { walletSize *= 100; int quantity = (int)(walletSize / quote.LastTradePrice.Value); Investment investment = new Investment() { Id = Guid.NewGuid(), PlayerName = player.GetType().Name, PurchaseDate = DateTime.Now, PurchasePrice = quote.LastTradePrice.Value, Quantity = quantity, Symbol = quote.Symbol }; using (DbConnection connection = Db.CreateConnection()) { connection.Open(); connection.Insert<Investment>(investment); Log.Information("Initialized {0} with symbol {1}", investment.PlayerName, investment.Symbol); } }