Public
Edited
Feb 6, 2023
Insert cell
Insert cell
viewof interest = Inputs.range([0, 11], {value: 5, step: 0.1, label: "Interest rate"})
Insert cell
yearly_invest = 10000
Insert cell
max_years = 50
Insert cell
invest_years = 18
Insert cell
cumulative = {
const tmp = Array(max_years);
tmp[0] = {year: 1, input: yearly_invest, cum_input: yearly_invest, value: yearly_invest};
for (let i = 1; i < max_years; i++) {
const yearly_invest_w_cutoff = i >= invest_years ? 0 : yearly_invest;
tmp[i] = {year: i+1, input: yearly_invest_w_cutoff, cum_input: tmp[i-1].cum_input + yearly_invest_w_cutoff, value: +(tmp[i-1].value * (1 + interest/100) + yearly_invest_w_cutoff).toFixed(0)};
;
}
return tmp
}
Insert cell
viewof rows = Inputs.table(cumulative)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more