LIVE
connecting to the live quote stream…
--:--:--UTC
easyFinance○
#06

PV of a cash-flow ladder

easyFinanceacceptance —~10 min

Implement present_value(cashflows, rate, terminal) — the present value of a ladder of cash flows paid at the end of periods 1..n at a flat per-period rate, plus a terminal amount paid together with the last flow.

Every dividend model, bond and annuity is this loop. Return the value rounded to 4 decimal places.

example 1
input
cashflows=[100.0, 100.0, 100.0], rate=0.05, terminal=0.0
output
272.3248
example 2
input
cashflows=[5.0, 5.0, 5.0, 5.0, 5.0], rate=0.04, terminal=100.0
output
104.4518
constraints
  • 1 ≤ n ≤ 600
  • 0 ≤ rate ≤ 0.5
  • terminal ≥ 0
teacher · 2 hints · the first is free
●solution.py· utf-8 · spaces:4
ln 1, col 1tab indent · esc leave editor
python 3.13 · pyodide
+ 6 hidden on submit
input · keyword arguments to present_value()
cashflows=[100.0, 100.0, 100.0], rate=0.05, terminal=0.0
expected
272.3248

the judge calls present_value() with exactly these inputs · outputs are compared to 6 decimal places

● standing bypython 3.13 in your browser · pyodide 0.28.3 · judged on the server to 6 dp⌘↵ run · ⌘⇧↵ submit
paper only · educational · not advice