Esempio n. 1
0
 public static PortfolioPath[] CalculateMonteCarlo(MonteCarloViewModel fullMonte, ApplicationUser user )
 {
     int yearsUntilRetirement = fullMonte.PreferredRetirementAge - (DateTime.Now.Year - user.DateOfBirth.Year);
     int steps = yearsUntilRetirement + fullMonte.EstimatedRetirementSpan;
     const int nPaths = 250000;
     PortfolioViewModel p = fullMonte.PortfolioViewModel;
     PortfolioPath[] paths = MonteCarlo.RunSimulation(yearsUntilRetirement, nPaths, p.ExpectedReturnDouble, (double)p.Variance, (double)p.DollarValue, fullMonte.AnnualContribution, fullMonte.AnnualRetirementIncomeDraw, fullMonte.EstimatedRetirementSpan);
     return paths;
 }
Esempio n. 2
0
        public IActionResult Index(MonteCarloViewModel fullMonte)
        {
            fullMonte.PortfolioViewModel = HttpContext.Session.GetObjectFromJson<PortfolioViewModel>("selected_port_viewmodel");

            bool inputCheck = true;
            if (string.IsNullOrWhiteSpace(fullMonte.AnnualContribution.ToString()))
            {
                inputCheck = false;
            }
            if (string.IsNullOrWhiteSpace(fullMonte.PreferredRetirementAge.ToString()))
            {
                inputCheck = false;
            }
            if (string.IsNullOrWhiteSpace(fullMonte.EstimatedRetirementSpan.ToString()))
            {
                inputCheck = false;
            }
            if (string.IsNullOrWhiteSpace(fullMonte.AnnualRetirementIncomeDraw.ToString()))
            {
                inputCheck = false;
            }

            if (inputCheck == false)
            {
                return View(fullMonte.PortfolioViewModel.ID); 
            }

            ApplicationUser currentUser = _context.Users.Single(u => u.Id == HttpContext.User.GetUserId());
            fullMonte.StartingAge = (DateTime.Now.Year - currentUser.DateOfBirth.Year);
            int steps = (fullMonte.PreferredRetirementAge - fullMonte.StartingAge) + fullMonte.EstimatedRetirementSpan;
            PortfolioPath[] monteCarloPathResults = MonteCarloProcessor.CalculateMonteCarlo(fullMonte, currentUser);
            List<decimal> monteCarloAvgResults = PathAnalysis.GetAveragePath(monteCarloPathResults, steps);
            List<decimal> monteCarloMaxResults = PathAnalysis.GetMaximumPath(monteCarloPathResults, steps);
            List<decimal> monteCarloMinResults = PathAnalysis.GetMinimumPath(monteCarloPathResults, steps);
            List<string> ageList = new List<string>();
            for (int i = fullMonte.StartingAge; i < fullMonte.PreferredRetirementAge + fullMonte.EstimatedRetirementSpan; i++)
            {
                ageList.Add(i.ToString());
            }

            fullMonte.MonteCarloAvgResults = monteCarloAvgResults;
            fullMonte.MonteCarloMaxResults = monteCarloMaxResults;
            fullMonte.MonteCarloMinResults = monteCarloMinResults;
            fullMonte.ageSpan = ageList;

            return View(fullMonte);
        }
Esempio n. 3
0
        public IActionResult Index(int? id)
        {
            if (id == null)
            {
                return HttpNotFound();
            }

            PortfolioViewModel portfolioViewModel = HttpContext.Session.GetObjectFromJson<PortfolioViewModel>("selected_port_viewmodel");
            if (portfolioViewModel == null)
            {
                Portfolio portfolio = _context.Portfolio.Include(p => p.PortfolioAssets).Single(m => m.ID == id);
                if ((portfolio == null) || (portfolioViewModel.ID != id))
                {
                    return HttpNotFound();
                }
                Builder builder = new Builder(_context);
                PortfolioDomainModel portfolioDomainModel = builder.GetPortfolioDomainModel(portfolio);
                portfolioViewModel = builder.GetPortfolioViewModel(portfolioDomainModel);
                HttpContext.Session.SetObjectAsJson("selected_port_viewmodel", portfolioViewModel);
            }
            MonteCarloViewModel blankMonte = new MonteCarloViewModel();
           // blankMonte.PortfolioViewModel = portfolioViewModel;
            return View(blankMonte);
        }