σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademySkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
Skills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
Python skill›Module 4 · Fixed income & options pricing›Topic 4.1·~40 minIntermediate

Present value and discounting

Skill positionModule 4 of 11 · Topic 1 of 16
4.1 Present value and discounting
—Lab score— / 100Total XP—Streak—

A euro tomorrow is not a euro today

If you can earn 5% a year, 100 today becomes 105 in a year. So 105 promised in a year is worth only 100 today. That is discounting: converting a future cash amount to its present value by removing the interest it could have earned. For an annual rate r and t years, PV = cash / (1 + r) ** t. Every bond, loan, annuity and pension is priced this way, which makes it the base of fixed income and option pricing in the next topics.

PV = cash / (1 + r)^t FV = PV * (1 + r)^t
def present_value(cash, rate, years):
    return cash / (1 + rate) ** years

print(round(present_value(100, 0.05, 3), 4))        # 86.3838   100 received in 3 years, worth 86.38 today
print(round(present_value(100, 0.05, 0), 4))        # 100.0     no waiting, no discount
print(round(present_value(100, 0.10, 3), 4))        # 75.1315   a higher rate discounts harder

Net present value

Real investments pay in streams: a bond pays coupons and a final principal, a project costs money now and returns it over years. The net present value (NPV) discounts each cash flow by its own time and adds them up. List the flows with the first at time 0, so the times are 0, 1, 2, ... (np.arange(len(flows))), and discount the whole array in one call. A positive NPV means the investment earns more than the discount rate; negative means it earns less. As the rate rises, the NPV falls.

import numpy as np

flows = np.array([-100.0, 30.0, 40.0, 50.0])      # pay 100 now, receive 30, 40 and 50 over the next three years
times = np.arange(len(flows))                      # 0, 1, 2, 3

for rate in (0.08, 0.12, 0.20):
    print(rate, round((flows / (1 + rate) ** times).sum(), 3))
# 0.08 1.763      positive: worth doing at 8%
# 0.12 -5.738     negative: not at 12%
# 0.2 -18.287     the higher the rate, the lower the NPV

Compounding forward, and continuous rates

Going forward is the mirror image: FV = PV * (1 + r) ** t. If interest is paid m times a year at the quoted rate r, each period earns r / m and there are m * t periods: FV = PV * (1 + r / m) ** (m * t). More frequent payment grows a little more: 100 at 5% becomes 105.00 yearly, 105.12 monthly, 105.13 daily. In the limit of continuous payment the growth factor is exp(r * t) and the discount factor is exp(-r * t), the form used in option pricing because it multiplies nicely over time.

import math

for m in (1, 2, 12, 365):
    print(m, round(100 * (1 + 0.05 / m) ** (m * 1), 4))
# 1 105.0
# 2 105.0625
# 12 105.1162
# 365 105.1267

print(round(100 * math.exp(0.05), 4))            # 105.1271   continuous compounding, the limit
print(round(math.exp(-0.05 * 3), 5))              # 0.86071    the continuous discount factor for 3 years
print(round(100 * (1 + 0.05 / 12) ** (12 * 3), 3))   # 116.147   100 grows for 3 years with monthly interest
# How long to double the money at 5%? Exactly ln 2 / ln 1.05, roughly 72 / 5
print(round(math.log(2) / math.log(1.05), 2), round(72 / 5, 1))     # 14.21 14.4
Always say which rate you mean5% yearly, 5% compounded monthly and 5% continuous are three different rates: they grow 100 to 105.00, 105.12 and 105.13 in a year. Mixing them silently is a classic source of pricing errors. State the compounding convention, keep time in years, and convert with ln(1 + r) or exp(r) - 1 when you move between conventions.
  • PV = cash / (1 + r) ** t: later money is worth less; a higher rate discounts harder.
  • NPV = sum of the discounted flows, the first at time 0: (flows / (1 + r) ** np.arange(n)).sum(); positive means worth doing.
  • FV = PV * (1 + r / m) ** (m * t); continuous: growth exp(r * t), discount exp(-r * t); always state the convention.

Next up: bond prices, discounting a coupon stream and a final principal at a market rate.

Lab · what's graded

  • Bring a future payment to today with present_value25 pts
  • Value a stream of payments with npv25 pts
  • Compound interest forward with future_value25 pts
  • Discount continuously with continuous_discount_factor25 pts
Explorer · lab-66-1
▾ lab-66-1
…
bash · in-browser
learner@quantcraft:~/lab-66-1$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-66-1 goes back to the starter files and the terminal is cleared. Your current solution will be lost — this can't be undone.

Will be reset
  • main.py → starter code
  • Terminal history and test output
  • Unsubmitted changes
Will be kept
  • Best lab score
  • Your XP and streak
  • Lecture progress and notes

Log in to run your code.

Every lecture is free to read. Create an account or log in to run code, run tests and submit this lab.

  • In-browser IDE with a bash terminal — nothing to install
  • Instant grading, XP and your place on the skill
Create an accountLog in
OR
Continue with GitHub