BLS Gamma
Delta 对标的资产价格变化的敏感度
根据标的资产价格、行权价、无风险利率、到期时间与波动率,使用布莱克-斯科尔斯模型计算期权的 Gamma(Delta 对标的价格的敏感度)。
计算结果
点击「计算」查看输出
code
计算逻辑代码
以下为「ISDA国际通用」BLS Gamma 的 Python 代码示例(基于 QuantLib)。
# 依赖版本:
# python==3.9
# QuantLib==1.43
import math
import traceback
import QuantLib as ql
def qjquant_calu_blsgamma(
price: float,
strike: float,
rate: float,
time: float,
volatility: float,
yield_rate: float = 0.0,
):
try:
# ---------- 参数校验 ----------
if price <= 0 or strike <= 0:
return {"ok": False, "msg": "标的价格与行权价必须大于 0"}
if rate < 0:
return {"ok": False, "msg": "无风险利率不能为负"}
if time <= 0:
return {"ok": False, "msg": "到期时间必须大于 0"}
if volatility <= 0:
return {"ok": False, "msg": "波动率必须大于 0"}
# ---------- 构建 BlackCalculator 所需标量 ----------
# Forward = S * exp((r - q) * T)
forward = price * math.exp((rate - yield_rate) * time)
# 标准差 = σ * sqrt(T)
std_dev = volatility * math.sqrt(time)
# 折现因子 = exp(-r * T)
discount = math.exp(-rate * time)
# ---------- 计算 Gamma ----------
# Gamma 对 Call 和 Put 相同,任选其一即可
call_payoff = ql.PlainVanillaPayoff(ql.Option.Call, strike)
call_calc = ql.BlackCalculator(call_payoff, forward, std_dev, discount)
gamma = call_calc.gamma(price) # gamma(spot) 返回对现货价格的二阶敏感度
return {
"ok": True,
"gamma": round(gamma, 4),
}
except ValueError as ve:
traceback.print_exc()
return {"ok": False, "msg": f"参数错误: {ve}"}
except Exception as e:
traceback.print_exc()
return {"ok": False, "msg": f"未知错误: {e}"}
# ============================================================
# 示例:复制本文件后直接运行
# ============================================================
if __name__ == "__main__":
print("=" * 60)
print("示例 1:标准欧式期权(无股息,平值附近)")
print("=" * 60)
r1 = qjquant_calu_blsgamma(
price=100.0,
strike=100.0,
rate=0.05,
time=1.0,
volatility=0.2,
yield_rate=0.0,
)
print(r1)
print()
print("=" * 60)
print("示例 2:含股息率的欧式期权(半年期限)")
print("=" * 60)
r2 = qjquant_calu_blsgamma(
price=100.0,
strike=95.0,
rate=0.03,
time=0.5,
volatility=0.25,
yield_rate=0.02,
)
print(r2)
print()
print("=" * 60)
print("示例 3:深度实值看涨期权(高波动、长到期)")
print("=" * 60)
r3 = qjquant_calu_blsgamma(
price=120.0,
strike=80.0,
rate=0.04,
time=2.0,
volatility=0.3,
yield_rate=0.01,
)
print(r3)
print()
print("=" * 60)
print("示例 4:深度虚值看跌期权(低波动、短到期)")
print("=" * 60)
r4 = qjquant_calu_blsgamma(
price=100.0,
strike=120.0,
rate=0.02,
time=0.25,
volatility=0.15,
yield_rate=0.0,
)
print(r4)