明天的一欧元不等于今天的一欧元
如果你每年能赚 5%,今天的 100 一年后变成 105。所以一年后承诺的 105,今天只值 100。这就是折现:去掉它本可以赚到的利息,把未来的金额换算成现值。对年利率 r 和 t 年,PV = cash / (1 + r) ** t。每一只债券、贷款、年金和养老金都是这样定价的,这使它成为接下来固定收益和期权定价的基础。
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净现值
真实的投资以现金流的形式支付:债券支付票息和最后的本金,项目现在花钱、之后几年才收回。净现值(NPV)把每笔现金流按各自的时间折现再相加。列出现金流,第一笔在时间 0,时间就是 0, 1, 2, ...(np.arange(len(flows))),一次调用就能对整个数组折现。净现值为正,说明投资的收益高于折现率;为负则低于折现率。利率上升时,净现值下降。
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向前复利与连续利率
向前是镜像:FV = PV * (1 + r) ** t。如果按报价利率 r 每年付息 m 次,每期赚 r / m,共有 m * t 期:FV = PV * (1 + r / m) ** (m * t)。付息越频繁,增长略多:5% 的 100 按年是 105.00,按月是 105.12,按日是 105.13。付息连续时,增长因子是 exp(r * t),折现因子是 exp(-r * t),这是期权定价使用的形式,因为它在时间上相乘很方便。
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始终说明你指的是哪种利率年化 5%、按月复利 5% 和连续复利 5% 是三种不同的利率:一年内分别把 100 变成 105.00、105.12 和 105.13。悄悄混用它们是定价错误的经典来源。请说明复利约定,时间用年表示,在不同约定之间转换时使用
ln(1 + r) 或 exp(r) - 1。PV = cash / (1 + r) ** t:越晚收到的钱越不值钱,利率越高折现越狠。- NPV = 折现后现金流之和,第一笔在时间 0:
(flows / (1 + r) ** np.arange(n)).sum();为正则值得做。 FV = PV * (1 + r / m) ** (m * t);连续:增长exp(r * t),折现exp(-r * t);始终说明约定。
下一节:债券价格,用市场利率对票息流和到期本金折现。
实验:评分内容
- 用
present_value把未来的付款折到今天25 分 - 用
npv为一系列现金流估值25 分 - 用
future_value计算复利终值25 分 - 用
continuous_discount_factor连续折现25 分