private void Percentiles(List <OutcomeSummary> list, InputData input) { WriteManager.Write($" * Percentile Outcomes:"); var outcomeInvestmentAmount = new List <Narvalo.Money>(); foreach (var outcome in list) { outcomeInvestmentAmount.Add(outcome.Outcomes.Last().NewPortfolio.InvestmentAmount); } outcomeInvestmentAmount.Sort(); var outcomesAsDecimal = new List <decimal>(); foreach (var outcome in outcomeInvestmentAmount) { outcomesAsDecimal.Add(outcome.Amount); } WriteManager.Write($" - Min: {outcomeInvestmentAmount.First().ToDecimal().MakeReadable()}"); foreach (var item in new double[] { .001, .01, .03, .05, .08, .10, .25, .40, .50, .60, .75, .85, .95, .99, .999 }) { var value = $"000{item * 100}"; WriteManager.Write($" - {value.Substring(value.Length-4)}%'tile: {outcomesAsDecimal.ToPercentile(item).MakeReadable()}"); } WriteManager.Write($" - Max: {outcomeInvestmentAmount.Last().ToDecimal().MakeReadable()}"); }
public void ParseAndDispatch(string[] args) { var pArgs = GenericArgsParser.Parse(args); if (!string.IsNullOrEmpty(pArgs.ErrorMessage)) { WriteManager.Write(pArgs.ErrorMessage); return; } switch (pArgs.DispatchMode) { case DispatchModes.Test: new DispatchTest().Execute(pArgs); break; case DispatchModes.Input: new DispatchInputData().Execute(pArgs); break; case DispatchModes.Help: new DispatchHelp().Execute(pArgs); break; case DispatchModes.Create: new DispatchCreateFile().Execute(pArgs); break; //TODO Help. default: WriteManager.Write($"Invalid Mode: {pArgs.DispatchMode}"); return; } }
public override void Report(List <OutcomeSummary> list, InputData input) { foreach (var item in CreateCsvReport(list, input)) { WriteManager.Write($"Writing data to {item.Key}"); System.IO.File.WriteAllText(item.Key, item.Value); } }
public override void Report(List <OutcomeSummary> list, InputData input) { //I'm imagining a time where an external program like a website call the exe and wants only this output... WriteManager.Writer = WriterToResetTo; var text = CreateGiantCsv(list, input); WriteManager.Write(text); }
public override void Report(List <OutcomeSummary> list, InputData input) { var filename = $"Execution_{Guid.NewGuid()}.csv"; var path = System.IO.Path.GetTempPath(); var fullPath = path + filename; var text = CreateGiantCsv(list, input); WriteManager.Write($"Writing data to {fullPath}"); System.IO.File.WriteAllText(fullPath, text); }
public void Report(List <OutcomeSummary> list, InputData input) { var percentage = input.PercentageOfInitialPortolioIsClose * 100; WriteManager.Write($" * Simulations: {list.Count}"); WriteManager.Write($" * Failures: {list.Count(a => a.IsFail)}"); WriteManager.Write($" * Close to Failures, but not failed ({percentage}% or less initial portfolio): {list.Count(a => a.IsClose && !a.IsFail)}"); WriteManager.Write($" * Failure Probability: {((decimal)((decimal)list.Count(a => a.IsFail) / (decimal)list.Count) * 100M).MakeReadable()}%"); Percentiles(list, input); PercentageDropFromInitialInvestment(list, input); }
public void Execute(GenericArgsParser args) { var input = ArgsToInputData(args); var method = args.EvaluationMethod; var defaultMethod = "AllYears"; if (method == null || !Simulation.ContainsKey(method)) { WriteManager.Write($"Invalid evaluation method '{method}'. Replacing with '{defaultMethod}'"); method = defaultMethod; } Simulation[method].Mode = args.Mode; Simulation[method].ExecuteSimulate(input); }
public static InputData FromFileSafe(string path, InputData defaultValue) { InputData data; if (!File.Exists(path)) { WriteManager.Write($"Unable to find '{path}'. Using default values."); data = defaultValue; } else { data = FromString(File.ReadAllText(path)); } return(data); }
public void Report(List <OutcomeSummary> list, InputData input) { foreach (var summary in list) { WriteManager.Write($"***********Run # {summary.RowNumber}***********"); WriteManager.Write("-----"); WriteManager.Write($"Started: {summary.PortolioStartTime.PrettyDate()} "); WriteManager.Write($"- Is Failure: {summary.IsFail}"); WriteManager.Write($"- Is Close: {summary.IsClose}"); WriteManager.Write($"- Worst Month: {summary.WorstMonth}"); WriteManager.Write($"- Worst Amount: {summary.WorstAmount.MakeReadable()}"); WriteManager.Write($"- Total Returns By Category: {summary.TotalReturnsByCategory.DictToString()}"); WriteManager.Write("-----"); var period = 0; foreach (var item in summary.Outcomes) { period++; WriteManager.Write($"Period: {period} - {item}"); } WriteManager.Write($"***********End of Run # {summary.RowNumber}***********"); } }
private void PercentageDropFromInitialInvestment(List <OutcomeSummary> list, InputData input) { WriteManager.Write($" * % of portfolios that fell between:"); var initAmt = input.InitialAmount; var tenPercentOfInitAmt = initAmt / 10; var outcomeInvestmentAmount = new List <decimal>(); //var lowestValue = initAmt; foreach (var outcomeSummary in list) { //foreach (var outcome in outcomeSummary.Outcomes) //{ // var checkedValue = outcome.NewPortfolio.InvestmentAmount; // if (lowestValue>checkedValue) // { // lowestValue = checkedValue; // } //} outcomeInvestmentAmount.Add(outcomeSummary.WorstAmount); //lowestValue = initAmt; } WriteManager.Write($" - Portfolios that fell between 0-10% of initial investment: {PercentageDropCalculation(outcomeInvestmentAmount, decimal.MinValue, tenPercentOfInitAmt)}"); foreach (var item in new decimal[] { 10, 20, 30, 40, 50, 60, 70, 80 }) { var dec = .1M * item; WriteManager.Write($" - Portfolios that fell between {item}-{item+10}% of initial investment: {PercentageDropCalculation(outcomeInvestmentAmount, dec * tenPercentOfInitAmt, (dec+1) * tenPercentOfInitAmt)}"); } WriteManager.Write($" - Portfolios that fell between 90-100% of initial investment: {PercentageDropCalculation(outcomeInvestmentAmount, tenPercentOfInitAmt * 9, decimal.MaxValue)}"); }
public void Execute(GenericArgsParser args) { var input = new InputData(); input.IncomeAndExpenses.Add( new ExpenseOffset() { OffsetAmount = (((InputData.InitialAmt * .043M) / 12) * -1).AsMoney() }); input.IncomeAndExpenses.Add(new ExpenseOffset() { StartMonth = 380, OffsetAmount = 1099.AsMoney(), }); input.IncomeAndExpenses.Add(new ExpenseOffset() { StartMonth = 40, EndMonth = 200, OffsetAmount = 800.AsMoney(), }); input.FilePath = ""; input.Adjustments.Clear(); input.AdjustmentTranslation = new List <AdjustmentTranslationData>() { new AdjustmentTranslationData() { Type = "AdjustByGlide", NameToStringValue = new Dictionary <string, List <string> > { { "from", new List <string>() { "Equity" } }, { "to", new List <string>() { "Bond" } }, }, NameToDecimalValue = new Dictionary <string, decimal>() { { "glide", 5m / 12 } } }, new AdjustmentTranslationData() { Type = "AdjustByMaxValues", NameToDecimalValue = new Dictionary <string, decimal>() { { "Equity", 75 } } }, new AdjustmentTranslationData() { Type = "AdjustByMinValues", NameToDecimalValue = new Dictionary <string, decimal>() { { "Bond", 5 }, { "Equity", 20 }, { "Gold", 15 }, } }, new AdjustmentTranslationData() { Type = "AdjustByCapeRatio", NameToStringValue = new Dictionary <string, List <string> > { { "from", new List <string>() { "Bond" } }, { "to", new List <string>() { "Equity" } }, }, NameToDecimalValue = new Dictionary <string, decimal>() { { "max_cape_before_action", 20 }, { "percentage_to_adjust_by", .2M }, { "amount_of_cape_excess_to_increase_adjustment", 10M } } } }; Input.ToFile(input, args.InputFilePath); WriteManager.Write("Execution Completed."); }
public override void PrintSimulationSpecificDetails(List <OutcomeSummary> list) { WriteManager.Write($" * Failure Details: \n - {string.Join("\n - ", list.Where(a => a.IsFail).OrderBy(b => b.IsCloseFirstMonth).Select(b => $" Initial Date: {b.PortolioStartTime.PrettyDate()}, First Close Month: {b.IsCloseFirstMonth}, First Failure Month: {b.FirstFailureMonth}, Worst Month: {b.WorstMonth}, Worst Amount: {b.WorstAmount.MakeReadable()}").ToList())}"); WriteManager.Write($" * Close Details: \n - {string.Join("\n - ", list.Where(a => a.IsClose && !a.IsFail).OrderBy(b => b.IsCloseFirstMonth).Select(b => $" Initial Date: {b.PortolioStartTime.PrettyDate()}, First Close Month: {b.IsCloseFirstMonth}, Worst Month: {b.WorstMonth}, Worst Amount: {b.WorstAmount.MakeReadable()}").ToList())}"); WriteManager.Write($" * Top 10 Worst Details: \n - {string.Join("\n - ", list.OrderBy(a => a.WorstAmount).Take(10).Select(b => $" Initial Date: {b.PortolioStartTime.PrettyDate()}, Worst Month: {b.WorstMonth}, Worst Amount: {b.WorstAmount.MakeReadable()}").ToList())}"); }
public void Write(string write) { WriteManager.Write(write); }