public ActionResult Page3(InvestmentCalculator c) { double total = Math.Round(c.Principle, 2); //dollar amount of your total double n = c.Term * c.Time; //n, or the number of periods double interest = c.Interest / 100; //changes percentage to form used for calculations double totalEarned = 0; //dollar amount of interest earned string interestType = ""; //compound or simple string termString = ""; //string for how often it was calculated or compounded string yearString = ""; //whether it's a year or multiple years if (c.Time == 1) { yearString = " year"; } else { yearString = " years"; } if (c.Term == 365) { termString = "daily"; } else if (c.Term == 52) { termString = "weekly"; } else if (c.Term == 12) { termString = "monthly"; } else { termString = "annually"; } if (c.Compound) { totalEarned = Math.Round((c.Principle * Math.Pow((1 + interest), n) - c.Principle), 2); interestType = " compounded "; } else { totalEarned = Math.Round((c.Principle * interest * n), 2); interestType = " calculated "; } total += totalEarned; ViewBag.Message = "An investment of $" + Math.Round(c.Principle, 2) + " with a " + c.Interest + "% interest rate " + interestType + termString + " over " + c.Time + yearString + " would earn $" + String.Format("{0:n}", totalEarned) + " for a total ending balance of $" + String.Format("{0:n}", total) + "."; return(View("Page3Result", "~/Views/Shared/_Layout.cshtml", ViewBag.Message)); } //manipulation of data from Page3
public void C01TestSample0175PercentProfitOfInvestment25PercentTax_FearlessInvestment() { var bankAccount = new BankAccount(); var initialBalance = 100; bankAccount.Deposit(initialBalance); var fearlessInvestment = new FearlessInvestment(); var investmentCalculator = new InvestmentCalculator(); var profitOfInvestment = investmentCalculator.Calculate(bankAccount, fearlessInvestment); bankAccount.Deposit(profitOfInvestment * 0.75); var expectedBalance = initialBalance + (initialBalance * fearlessInvestment.Factor * 0.75); Assert.AreEqual(expectedBalance, bankAccount.Balance); }
public async Task UpdateLimitOrdersAsync() { IReadOnlyCollection <string> assets = await GetAssetsAsync(); await CancelLimitOrdersAsync(assets); if (!await ValidateIndexPricesAsync()) { return; } IReadOnlyCollection <Token> tokens = await _tokenService.GetAllAsync(); IReadOnlyCollection <Position> positions = await GetCurrentPositionsAsync(); IReadOnlyCollection <IndexPrice> indexPrices = await _indexPriceService.GetAllAsync(); IReadOnlyCollection <IndexSettings> indicesSettings = await _indexSettingsService.GetAllAsync(); IReadOnlyDictionary <string, Quote> assetPrices = await GetAssetPricesAsync(assets); IReadOnlyCollection <AssetInvestment> assetInvestments = InvestmentCalculator.Calculate(assets, indicesSettings, tokens, indexPrices, positions, assetPrices); _log.InfoWithDetails("Investments calculated", assetInvestments); IReadOnlyCollection <HedgeLimitOrder> hedgeLimitOrders = await CreateLimitOrdersAsync(assetInvestments); await ValidateHedgeLimitOrdersAsync(hedgeLimitOrders); _log.InfoWithDetails("Hedge limit orders calculated", hedgeLimitOrders); _investmentService.Update(assetInvestments); await ApplyLimitOrdersAsync(assets, hedgeLimitOrders); }
public void Calculate_With_Investments_And_Zero_Positions() { // arrange var assets = new[] { "BTC", "LTC", "XRP" }; var indicesSettings = new[] { new IndexSettings { Name = "LCI", AssetId = "TLYCI" } }; var tokens = new[] { new Token { AssetId = "TLYCI", OpenVolume = 10, OppositeVolume = 1000 } }; var indexPrices = new[] { new IndexPrice { Name = "LCI", Price = 100, Value = 101, Weights = new[] { new AssetWeight("BTC", .5m, 1, false), new AssetWeight("LTC", .3m, 1, false), new AssetWeight("XRP", .2m, 1, false) } } }; var positions = new Position[0]; var assetPrice = new Dictionary <string, Quote> { ["BTC"] = new Quote("BTCUSD", DateTime.UtcNow, 4000, 3900, "source"), ["LTC"] = new Quote("LTCUSD", DateTime.UtcNow, 32, 31, "source"), ["XRP"] = new Quote("XRPUSD", DateTime.UtcNow, .4m, .3m, "source") }; var expectedAssetInvestments = new[] { new AssetInvestment { AssetId = "BTC", Volume = 0, TotalAmount = 500, RemainingAmount = -500, Indices = new[] { new AssetIndexInvestment { Name = "LCI", Amount = 500 } } }, new AssetInvestment { AssetId = "LTC", Volume = 0, TotalAmount = 300, RemainingAmount = -300, Indices = new[] { new AssetIndexInvestment { Name = "LCI", Amount = 300 } } }, new AssetInvestment { AssetId = "XRP", Volume = 0, TotalAmount = 200, RemainingAmount = -200, Indices = new[] { new AssetIndexInvestment { Name = "LCI", Amount = 200 } } } }; Complete(expectedAssetInvestments, assetPrice, indicesSettings, indexPrices, tokens); // act IReadOnlyCollection <AssetInvestment> actualAssetInvestments = InvestmentCalculator.Calculate(assets, indicesSettings, tokens, indexPrices, positions, assetPrice); // assert Assert.IsTrue(AreEqual(expectedAssetInvestments, actualAssetInvestments)); }
public static void Initialize(IServiceProvider service) { using (var context = new InvestmentContext( service.GetRequiredService <DbContextOptions <InvestmentContext> >())) { Random rand = new Random(); var inv1 = new Investment() { Id = 1, UserId = 100, Name = "APPL", TimeOfPurchase = DateTime.Now }; var inv2 = new Investment() { Id = 2, UserId = 100, Name = "TSLA", TimeOfPurchase = DateTime.Now }; var inv3 = new Investment() { Id = 3, UserId = 100, Name = "NKE", TimeOfPurchase = DateTime.Now }; var inv1Detail = new InvestmentDetail() { SystemId = 100, InvestmentId = 1, Shares = rand.Next(1, 20), CostBasisPerShare = Math.Round(rand.NextDouble() * 500, 2), CurrentPrice = 0, CurrentValue = 0, Term = 0, NetValuation = 0 }; var inv2Detail = new InvestmentDetail() { SystemId = 101, InvestmentId = 2, Shares = rand.Next(1, 20), CostBasisPerShare = Math.Round(rand.NextDouble() * 500, 2), CurrentPrice = 0, CurrentValue = 0, Term = 0, NetValuation = 0 }; var inv3Detail = new InvestmentDetail() { SystemId = 102, InvestmentId = 3, Shares = rand.Next(1, 20), CostBasisPerShare = Math.Round(rand.NextDouble() * 500, 2), CurrentPrice = 0, CurrentValue = 0, Term = 1, NetValuation = 0 }; inv1Detail.CurrentPrice = InvestmentCalculator.GeneratePrice(inv1Detail.CostBasisPerShare); inv1Detail.CurrentValue = InvestmentCalculator.DetermineValue(inv1Detail.Shares, inv1Detail.CurrentPrice); inv1Detail.NetValuation = InvestmentCalculator.DetermineNetValuation(inv1Detail.CurrentValue, inv1Detail.Shares, inv1Detail.CostBasisPerShare); inv2Detail.CurrentPrice = InvestmentCalculator.GeneratePrice(inv2Detail.CostBasisPerShare); inv2Detail.CurrentValue = InvestmentCalculator.DetermineValue(inv2Detail.Shares, inv2Detail.CurrentPrice); inv2Detail.NetValuation = InvestmentCalculator.DetermineNetValuation(inv2Detail.CurrentValue, inv2Detail.Shares, inv2Detail.CostBasisPerShare); inv3Detail.CurrentPrice = InvestmentCalculator.GeneratePrice(inv3Detail.CostBasisPerShare); inv3Detail.CurrentValue = InvestmentCalculator.DetermineValue(inv3Detail.Shares, inv3Detail.CurrentPrice); inv3Detail.NetValuation = InvestmentCalculator.DetermineNetValuation(inv3Detail.CurrentValue, inv3Detail.Shares, inv3Detail.CostBasisPerShare); context.Investments.Add(inv1); context.Investments.Add(inv2); context.Investments.Add(inv3); context.InvestmentDetails.Add(inv1Detail); context.InvestmentDetails.Add(inv2Detail); context.InvestmentDetails.Add(inv3Detail); context.SaveChanges(); } }