LIVE·WAITING…
connecting to the live quote stream…
--:--:--UTC
#04
Bond price & duration
easyFinanceacceptance —~15 min
Implement bond_price_duration(face, coupon_rate, ytm, years, freq) for a plain fixed-coupon bond: freq coupons per year of face·coupon_rate/freq, principal at maturity, yield ytm compounded freq times a year. Return [price, macaulay_duration] — duration in years.
Price tells you what it costs; duration tells you how much it moves when yields shift by one percent. Return both rounded to 4 decimal places.
example 1
input
face=1000.0, coupon_rate=0.05, ytm=0.06, years=5, freq=1
output
[957.8764, 4.5347]
example 2
input
face=1000.0, coupon_rate=0.05, ytm=0.06, years=5, freq=2
output
[957.349, 4.4717]
constraints
- face > 0
- 0 ≤ coupon_rate, ytm ≤ 0.2
- 1 ≤ years ≤ 30
- freq ∈ {1, 2, 4}
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 bond_price_duration()
face=1000.0, coupon_rate=0.05, ytm=0.06, years=5, freq=1
expected
[957.8764, 4.5347]
the judge calls bond_price_duration() 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