def monte_carlo(): form = MonteCarloForm() if form.rate.data is not None: rate = float(form.rate.data) else: rate = 0.07 if form.sigma.data is not None: sigma = float(form.sigma.data) else: sigma = 0.15 if form.time.data is not None: time = int(form.time.data) else: time = 10 if form.start_val.data is not None: start_value = float(form.start_val.data) else: start_value = all_accounts_sum() paths = gen_monte_carlo_paths(start_value, r=rate, sigma=sigma, time=time) session['paths'] = paths[:, :20] session['final_prices'] = paths[-1] stats = stats_from_paths(paths) mean = locale.currency(paths[-1].mean(), grouping=True) return render_template("monte_carlo.html", paths=paths, stats=stats, start_value=("{:.2f}".format(start_value)), start_val_for=locale.currency(start_value, grouping=True), rate=rate, sigma=sigma, time=time, mean=mean, form=form)
def index(): accounts = Account.query.all() if request.args.get('current'): update_account_prices(accounts, db) accounts_total = locale.currency(all_accounts_sum(), grouping=True) return render_template("index.html", accounts=accounts, total=accounts_total, account_type_sums=account_by_retirement_sub_type(), account_owner_sums=format_sums(account_by_owner_sums()), retirement_class_sums=format_sums(retirement_class_sums()) )
def test_all_accounts_sum(self): self.seed_db() total = all_accounts_sum() self.assertEqual(total, 2020.38 * 100 + 50 * 25.05 + 152.63 * 2020.38)