Black 隐含波动率

Black 隐含波动率 由期货期权市场价格反推隐含波动率
根据期货价格、行权价、无风险利率、到期时间与欧式期货期权的市场价格,使用布莱克模型反推期货价格的隐含波动率。可选参数:波动率搜索上界 Limit(默认 10,即 1000%)、终止容差 Tolerance、期权类别 Class(1=看涨,0=看跌,默认看涨)。
计算结果
点击「计算」查看输出
code 计算逻辑代码
以下为「ISDA国际通用」Black 隐含波动率的 Python 代码示例(基于 QuantLib)。

# 依赖版本:
# python==3.9
# QuantLib==1.43
import math
import traceback

import QuantLib as ql


def qjquant_calu_blkimpv(
    price: float,
    strike: float,
    rate: float,
    time: float,
    value: float,
    limit: float = 10.0,
    tolerance: float = 1e-6,
    option_class: int = 1,          # 1=看涨, 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 value <= 0:
            return {"ok": False, "msg": "期权市场价格必须大于 0"}
        if limit <= 0:
            return {"ok": False, "msg": "搜索上界 Limit 必须大于 0"}
        if option_class not in (0, 1):
            return {"ok": False, "msg": "期权类别必须为 1(看涨)或 0(看跌)"}

        # ---------- 期权类型映射 ----------
        ql_option_type = ql.Option.Call if option_class == 1 else ql.Option.Put

        # ---------- Black 模型参数 ----------
        forward = price                      # Black 模型 forward 即期货价格
        discount = math.exp(-rate * time)

        # 初始猜测:Brenner-Subrahmanyam 近似(帮助求解器收敛)
        guess_std_dev = (value / forward) * math.sqrt(2 * math.pi / time)

        # ---------- 反解隐含标准差 ----------
        # 使用关键字参数,避免位置传参错位
        implied_std_dev = ql.blackFormulaImpliedStdDev(
            ql_option_type,      # optionType
            strike,              # strike
            forward,             # forward
            value,               # blackPrice
            discount,            # discount
            0.0,                 # displacement(标准 Black 模型为 0)
            guess_std_dev,       # guess
            tolerance,           # accuracy
            100,                 # maxIterations
        )

        implied_vol = implied_std_dev / math.sqrt(time)

        return {"ok": True, "volatility": round(implied_vol, 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_blkimpv(
        price=20.0,
        strike=20.0,
        rate=0.09,
        time=0.3333,
        value=1.1166,
        option_class=1,
    )
    print(r1)

    print()
    print("=" * 60)
    print("示例 2:看跌期货期权隐含波动率")
    print("=" * 60)
    r2 = qjquant_calu_blkimpv(
        price=20.0,
        strike=20.0,
        rate=0.09,
        time=0.3333,
        value=1.1166,
        option_class=0,
    )
    print(r2)

    print()
    print("=" * 60)
    print("示例 3:期货价格高于行权价(看涨实值)")
    print("=" * 60)
    r3 = qjquant_calu_blkimpv(
        price=105.0,
        strike=95.0,
        rate=0.03,
        time=0.5,
        value=12.0,
        option_class=1,
        limit=5.0,
    )
    print(r3)

    print()
    print("=" * 60)
    print("示例 4:短到期、低波动看跌期权")
    print("=" * 60)
    r4 = qjquant_calu_blkimpv(
        price=100.0,
        strike=100.0,
        rate=0.02,
        time=0.25,
        value=5.0,
        option_class=0,
        tolerance=1e-8,
    )
    print(r4)