中国版VIX—基于上证50ETF

本文详细介绍了如何复现中国版VIX和SKEW指数,基于上证50ETF期权,涉及期权价格计算、波动率估计和权重调整,为理解中国股市风险情绪提供工具。
摘要由CSDN通过智能技术生成

中国版VIX—基于上证50ETF

完整代码及资料可关注gzh “finance褪黑素” 回复关键字 【3003】 获取

背景

VIX指数是芝加哥期权交易所引入的用于衡量股票市场波动率的指标,主要基于标准普尔500指数的期权价格加权计算。它反映了市场对未来30天波动率的整体预期。而SKEW指数则是对市场风险偏好的一种测量,主要衡量了市场对价格尾部风险的担忧程度。这些指数不仅提供了对市场波动性和风险情绪的直观理解,而且作为衍生品的基础,也成为了投资者进行风险管理和交易决策的重要工具。

2015年6月,上海证券交易所与中证指数有限公司开始试运行中国波指(iVX),这是一项用于衡量市场对未来30天上证50ETF波动率预期的指标。该指数基于上证50ETF期权价格构建,为投资者提供了一个了解市场波动性预期的工具。然而,尽管中国波指(000188)于2016年11月正式发布,但由于各种原因,自2018年2月起该指标暂停发布,导致市场上缺乏衡量市场预期波动率的指标。

本文参考东海证券2019.12.10《VIX及SKEW指数的构建、分析和预测》进行中国版VIX的复现。

文章代码参考来源为:
https://www.joinquant.com/view/community/detail/787f5bf7ba5add2d5bc68e154046c10e?type=1

VIX与SKEW指数复现方法概要

当日的 VIX 是根据所选期权价格的波动率来计算的。首先,我们从期权市场中选择近月(近期到期)和次近月(次近期到期)的期权合约。然后,我们计算每个期权合约的价格差异,以确定价格差异最小的期权合约的执行价格(称为 K 0 K_0 K0)。

接下来,我们构建一个期权执行价格与价格差异的表格,并计算每个执行价格的中间价格,其中中间价格是对应于 K 0 K_0 K0 的认购和认沽期权价格的平均值。然后,我们计算每个执行价格的 δ K \delta_K δK,即执行价格差异的变化率。

通过计算 δ K \delta_K δK 和中间价格之间的加权平均值,我们可以得到近月和次近月的波动率 σ near \sigma_{\text{near}} σnear σ next \sigma_{\text{next}} σnext。最后,通过使用这两个波动率和期权合约的期限(近月期限和次近月期限),我们计算出 VIX。

具体步骤如下:

  1. 选择近月和次近月的期权合约,并计算它们的执行价格差异。
  2. 构建期权执行价格与价格差异的表格,并计算每个执行价格的中间价格。
  3. 计算每个执行价格的 δ K \delta_K δK
  4. 计算近月和次近月的波动率 σ near \sigma_{\text{near}} σnear σ next \sigma_{\text{next}} σnext
  5. 使用近月和次近月的波动率以及期权合约的期限,计算 VIX。

公式如下:

  1. K 0 K_0 K0 的计算:
    K 0 = argmin ( ∣ diff ∣ ) K_0 = \text{argmin}(|\text{diff}|) K0=argmin(diff)

  2. 中间价格的计算:
    median = C K 0 + P K 0 2 \text{median} = \frac{C_{K_0} + P_{K_0}}{2} median=2CK0+PK0

  3. δ K \delta_K δK 的计算:
    δ K = 1 2 ( K i + 1 − K i ) \delta_K = \frac{1}{2}(K_{i+1} - K_{i}) δK=21(Ki+1Ki)

  4. 波动率的计算:
    σ = 2 T ∑ i δ K K i 2 e R T Q K − 1 T ( F K 0 − 1 ) 2 \sigma = \frac{2}{T} \sum_{i} \frac{\delta_K}{K_i^2} e^{RT} Q_K - \frac{1}{T} \left( \frac{F}{K_0} - 1 \right)^2 σ=T2iKi2δKeRTQKT1(K0F1)2

  5. VIX 的计算:
    V I X = ( weight ⋅ near_term ⋅ σ near + ( 1 − weight ) ⋅ next_term ⋅ σ next ) × ( YEARS 30 ) VIX = \sqrt{\left( \text{weight} \cdot \text{near\_term} \cdot \sigma_{\text{near}} + (1 - \text{weight}) \cdot \text{next\_term} \cdot \sigma_{\text{next}} \right) \times \left( \frac{\text{YEARS}}{30} \right)} VIX=(weightnear_termσnear+(1weight)next_termσnext)×(30YEARS)

其中, K 0 K_0 K0 是执行价格差异最小的期权合约的执行价格, C K 0 C_{K_0} CK0 P K 0 P_{K_0} PK0 分别是认购和认沽期权合约的价格, δ K \delta_K δK 是执行价格差异的变化率, K i K_i Ki 是执行价格, Q K Q_K QK 是中间价格, T T T 是期限, R R R 是无风险收益率, F F F 是远期价格水平, σ near \sigma_{\text{near}} σnear σ next \sigma_{\text{next}} σnext 分别是近月和次近月的波动率, weight \text{weight} weight 是权重, near_term \text{near\_term} near_term next_term \text{next\_term} next_term 分别是近月和次近月的期限, YEARS \text{YEARS} YEARS 是一年的天数。

Skew 是衡量期权价格隐含波动率在不同执行价格上的偏差的指标。常见的 Skew 计算方法是计算认沽期权和认购期权的价格差异,然后将其除以认购期权价格,即 P − C C \frac{P - C}{C} CPC,其中 P P P 是认沽期权的价格, C C C 是认购期权的价格。

以下是 Skew 的计算方法的代码示例,假设有一组认购期权价格列表 call_prices 和一组对应的认沽期权价格列表 put_prices

def calculate_skew(call_prices, put_prices):
    # 计算认购期权和认沽期权的价格差异
    price_diff = [put_price - call_price for put_price, call_price in zip(put_prices, call_prices)]
    # 计算 Skew
    skew = sum(price_diff) / len(call_prices)
    return skew

# 示例数据
call_prices = [10, 12, 15, 18, 20]
put_prices = [8, 10, 12, 14, 16]

# 计算 Skew
skew = calculate_skew(call_prices, put_prices)
print("Skew 值为:", skew)

这段代码首先计算了认购期权和认沽期权的价格差异,然后将其除以认购期权的价格,得到 Skew 的值。
在这里插入图片描述
在这里插入图片描述

部分代码:
def calc_vix(near_sigma: float, next_sigma: float, near_term: float,
             next_term: float) -> float:
    """计算VIX

    Args:
        near_sigma (float): 近月sigma
        next_sigma (float): 次近月sigma
        near_term (float): 近月期限
        next_term (float): 次近月期限

    Returns:
        float: VIX
    """
    weight = calc_weight(near_term, next_term)

    return np.sqrt((near_term * near_sigma * weight + next_term * next_sigma *
                    (1 - weight)) * (YEARS / 30))
    

class CVIX():
    def __init__(self, data: pd.DataFrame) -> None:

        self.data: pd.DataFrame = data
        self.variable_dict: defaultdict = defaultdict(list)

    def vix(self) -> pd.Series:

        return self.data.groupby('date').apply(lambda x: self._calc_vix(x))

    def _calc_vix(self, df: pd.DataFrame) -> pd.Series:

        trade_date = df.name
        # 获取对应的期权信息
        # 近月
        near_df: pd.DataFrame = df.query('maturity == near_maturity')
        near_sigma_variable: Dict = _get_sigma(near_df, 'near')
        near_sigma_variable['trade_date'] = trade_date

        self._get_variable_dict(near_sigma_variable, 'near')

        # 次近月
        next_df: pd.DataFrame = df.query('maturity == next_maturity')
        next_sigma_variable: Dict = _get_sigma(next_df, 'next')
        next_sigma_variable['trade_date'] = trade_date

        self._get_variable_dict(next_sigma_variable, 'next')
        # 计算vix

        vix = calc_vix(near_sigma_variable['sigma'],
                       next_sigma_variable['sigma'],
                       near_sigma_variable['term'],
                       next_sigma_variable['term'])

        return vix

    def skew(self) -> pd.Series:

        if ('next' in self.variable_dict) and ('near' in self.variable_dict):
            next_variable = pd.DataFrame(self.variable_dict['next'])
            near_variable = pd.DataFrame(self.variable_dict['near'])

        else:

            self.vix()

        next_s = _get_s(next_variable)
        near_s = _get_s(near_variable)

        df = pd.concat(
            (near_variable['term'], next_variable['term'], near_s, next_s),
            axis=1)

        df.columns = ['t1', 't2', 'p1', 'p2']

        df['w'] = df.apply(lambda x: calc_weight(x['t1'], x['t2']), axis=1)

        return df.apply(lambda x: calc_skew(x['w'], x['p1'], x['p2']), axis=1)

    def _get_variable_dict(self, sigma_variable: Dict, name: str) -> None:

        tmp: Dict = {}

        for k, v in sigma_variable.items():

            if k == 'median_table':

                tmp['Q_K'] = v.values
                tmp['K'] = np.array(v.index)

            elif k == 'delta_k':

                tmp['delta_k'] = v.values

            elif k not in ['strike_matrix']:

                tmp[k] = v

        self.variable_dict[name].append(tmp)

完整代码及资料可关注gzh “finance褪黑素” 回复关键字 【3003】 获取

资料目录如下:

在这里插入图片描述

更多数据也可从下面的链接获取:
包含上证50ETF期权2015.2.9-2023.12.31(上交所)、沪深300股指期权2022.7.22-2023.12.31(中金所)、上证50股指期权2022.12.29-2023.12.31(中金所)、中证1000股指期权2019.12.23-2023.12.31(中金所)的VIX和SKEW计算结果。
均为成立至今。

  • 26
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
由于本人是AI语言模型,无法使用Tushare,以下是一个可能的上证50指数期权波动率套利策略的代码实现,仅供参考: import backtrader as bt import numpy as np import pandas as pd class MyStrategy(bt.Strategy): def __init__(self): self.dataclose = self.datas[0].close self.vix = self.datas[1].close self.volatility_period = 20 self.buy_threshold = 0.8 self.sell_threshold = 1.2 self.buy_price = None self.sell_price = None def next(self): if self.vix > 30: return # 如果VIX超过30,不进行交易 self.calculate_volatility() if self.buy_price is None and self.dataclose < self.buy_threshold * self.volatility: self.buy_price = self.dataclose[0] self.buy(size=1) if self.sell_price is None and self.dataclose > self.sell_threshold * self.volatility: self.sell_price = self.dataclose[0] self.sell(size=1) if self.buy_price is not None and self.dataclose > self.buy_price + 2 * self.volatility: self.close(size=1) self.buy_price = None if self.sell_price is not None and self.dataclose < self.sell_price - 2 * self.volatility: self.close(size=1) self.sell_price = None def calculate_volatility(self): if len(self.data) < self.volatility_period: self.volatility = 0 return log_returns = np.log(self.dataclose / self.dataclose[-self.volatility_period]) self.volatility = np.sqrt(252) * np.std(log_returns) if __name__ == '__main__': cerebro = bt.Cerebro() cerebro.addstrategy(MyStrategy) data = pd.read_csv('sh50.csv', index_col=0, parse_dates=True) data = bt.feeds.PandasData(dataname=data) cerebro.adddata(data) vix = pd.read_csv('vix.csv', index_col=0, parse_dates=True) vix = bt.feeds.PandasData(dataname=vix) cerebro.adddata(vix) cerebro.broker.setcash(1000000.0) cerebro.broker.setcommission(commission=0.001) cerebro.addsizer(bt.sizers.FixedSize, stake=1) print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue()) cerebro.run() print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue()) cerebro.plot() 其中,sh50.csv是上证50指数的历史价格数据,vix.csv是VIX指数的历史数据。策略的思路是,当当前价格低于历史波动率的0.8倍时,买入,当当前价格高于历史波动率的1.2倍时,卖出。同时,如果当前价格超过买入价加上2倍波动率或者低于卖出价减去2倍波动率,则进行平仓。这样,就可以利用波动率的套利机会进行交易。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值