public void AllYearsProcessesCorrectly() { var input = new InputData() { PeriodsWithinSimulation = 50, LastYearOfDataUsed = 1939, StartYear = 1930, }; input.IncomeAndExpenses.Add(new ExpenseOffset() { StartMonth = 380, OffsetAmount = 1050.AsMoney(), }); input.FilePath = Path; var sim = new AllYearsSimulation(); var result1 = sim.ExecuteSimulate(input); var result2 = sim.ExecuteSimulate(input); CompareLogic compareLogic = new CompareLogic(); var comp = compareLogic.Compare(result1, result2); Assert.IsTrue(comp.AreEqual, "Verify data is consistently processed. Diff: " + comp.DifferencesString); Assert.AreEqual(120, result1.Count, "Verify only 120 (12 months * 10 years) months were executed."); }
public void AllYearsProcessSameAsExcel() { var initialAmt = 630_000; var incomeAndExpenseList = new List <ExpenseOffset> { new ExpenseOffset() { OffsetAmount = (((initialAmt * .043M) / 12) * -1).AsMoney() } }; var input = new InputData() { PeriodsWithinSimulation = 600, LastYearOfDataUsed = 1905, StartYear = 1905, InitialAmount = initialAmt, IncomeAndExpenses = incomeAndExpenseList, Portfolio = new Portfolio() { InvestmentAmount = initialAmt.AsMoney(), Investments = new Dictionary <string, decimal>() { { "Bond", 25 }, { "Equity", 25 }, { "Gold", 25 }, { "Cash", 25 } } }, Adjustments = new List <IPortfolioAdjustments>() { new AdjustByIncomeAndExpenses(incomeAndExpenseList), new AdjustIncomeByStockPerformance() }, }; input.IncomeAndExpenses.Add(new ExpenseOffset() { StartMonth = 360, OffsetAmount = 1050.AsMoney(), }); input.FilePath = Path; var sim = new AllYearsSimulation(); var result1 = sim.ExecuteSimulate(input); input.DisplayNameToCsvHeader = new Dictionary <string, string>() { { "Equity", CsvMapper.Equity_Return.Replace(" Return", "") }, { "Bond", "10Y BM" }, { "Cash", CsvMapper.Cash_Return.Replace(" Return", "") }, { "Gold", CsvMapper.Gold_Return.Replace(" Return", "") } }; //TODO Remove this test code used to compare two different spreadsheets. //FileName = "Stock_Bond_Returns_new.csv"; //input.FilePath = Path; //var result2 = sim.ExecuteSimulate(input); //CompareLogic compareLogic = new CompareLogic() //{ // Config = new ComparisonConfig() // { // MembersToIgnore = new List<string>() // { // "Input", // }, // } //}; //var comp = compareLogic.Compare(result1, result2); //Assert.IsTrue(comp.AreEqual, "Verify data is consistently processed. Diff: " + comp.DifferencesString); Assert.AreEqual(12, result1.Count, "Verify only 12 months were executed."); //All the asserts aassumed a specific spreadsheet was correct. I don't think calculating P&L of negative portfolio is reasonable, so now P&L is set to 0 if the investment amount/portfolio is less than 0. Assert.AreEqual(-474620.50.AsMoney().Normalize(MidpointRounding.AwayFromZero), result1[0].Outcomes[599].NewPortfolio.InvestmentAmount.Normalize(MidpointRounding.AwayFromZero)); //Calculated based upon big ern spreadsheet model. //Used from old spreadsheet. New spreadsheet gives new value I need to validate again... //Assert.AreEqual(-614296.48.AsMoney().Normalize(MidpointRounding.AwayFromZero), result1[0].Outcomes[599].NewPortfolio.InvestmentAmount.Normalize(MidpointRounding.AwayFromZero)); //Assert.AreEqual(-614296.48.AsMoney().Normalize(MidpointRounding.AwayFromZero), result2[0].Outcomes[599].NewPortfolio.InvestmentAmount.Normalize(MidpointRounding.AwayFromZero)); }