public static List<decimal> GetMinimumPath(PortfolioPath[] paths, int steps) { IEnumerable<decimal> endingValues = paths.Select(x => (decimal)x.endingPortfolioValue).ToArray(); decimal minEndingValue = endingValues.Min(); var minPathQuery = paths.Where(path => (decimal)path.endingPortfolioValue == minEndingValue).ToArray(); List<decimal> minPathSequence = minPathQuery[0].portfolioValueList; return minPathSequence; }
public static PortfolioPath[] RunSimulation(int yearsUntilRetirement, int nPaths, double expectedReturn, double variance, double initialPortfolioValue, double annualContributions, double incomeDraw, int yearsPlannedRetirement) { PortfolioPath[] paths = new PortfolioPath[nPaths]; Func<int, PortfolioPath> creator = x => new PortfolioPath(yearsUntilRetirement, expectedReturn, variance, initialPortfolioValue, annualContributions, incomeDraw, yearsPlannedRetirement); IEnumerable<int> indices = Enumerable.Range(0, nPaths - 1); paths = indices.AsParallel().Select(creator).ToArray(); return paths; }
public static List<decimal> GetAveragePath(PortfolioPath[] paths, int steps) { List<decimal> avgPathSequence = new List<decimal>(); for (int i = 0; i < steps - 1; i++) { decimal[] avgValuesArray = paths.Select(x => (decimal)x.portfolioValueList[i]).ToArray(); decimal avgValue = avgValuesArray.Average(); avgPathSequence.Add(avgValue); } return avgPathSequence; }
public static PortfolioPath[] RunSimulation(int yearsUntilRetirement, int nPaths, double expectedReturn, double variance, double initialPortfolioValue, double annualContributions, double incomeDraw, int yearsPlannedRetirement) { PortfolioPath[] paths = new PortfolioPath[nPaths]; Func <int, PortfolioPath> creator = x => new PortfolioPath(yearsUntilRetirement, expectedReturn, variance, initialPortfolioValue, annualContributions, incomeDraw, yearsPlannedRetirement); IEnumerable <int> indices = Enumerable.Range(0, nPaths - 1); paths = indices.AsParallel().Select(creator).ToArray(); return(paths); }