美文网首页数据科学与Python投资理财财经·投资·理财
如何统计投资品种波动率(python)?

如何统计投资品种波动率(python)?

作者: 阿甘数量化 | 来源:发表于2016-07-09 16:17 被阅读1318次

目前正在网H股ETF,进行了接近一年了还没出清,虽然已盈利,但相对于50ETF来说现在想它还真不是好品种,不考虑强周期、通胀、流动性等因素,仅就网格的最大影响因素波动性来讲,它就比不上50ETF。以前不会统计,现在学了点Python,自己写了小程序计算了下,先上结果:

volatility(510050vs510900).png
  图中蓝色为50ETF,可以看出,过去三年来它的日波动性明显强于H股ETF。
  下面就以50ETF和H股ETF为例,统计这两个投资品种的日波动率,其他品种、其他周期类似处理即可。附上代码:
# -- coding: utf-8 --
"""
Created on Sat Jul 09 12:03:03 2016
@author: forestgumpgg(雪球ID、聚宽ID),欢迎关注,共同讨论量化分析之道
比较上证50ETF(510050)和H股ETF(510900)的日波动率
日波动率=sqrt[(最高值-收盘值)^2 + (最低值- 收盘值) ^2]

"""
import pandas as pd
import matplotlib.pyplot as plt
import tushare as ts
import math

ts.set_token('********') #此次隐去了自己用的token

start_date = '2013-07-01'
end_date = '2016-06-30'

info510050 = ts.get_hist_data('510050', start= start_date, end=end_date)
info510050 = info510050.sort_index(axis = 'index', ascending = True)
info510050['day_volatility'] = (pow(info510050['high'] -info510050['close'] , 2) +
                        pow(info510050['low'] -info510050['close'] , 2) )
for i in range(0,len(info510050.index)):
    info510050['day_volatility'][i] = math.sqrt(info510050['day_volatility'][i])
    
    
info510900 = ts.get_hist_data('510900', start=start_date, end=end_date)
info510900 = info510900.sort_index(axis = 'index', ascending = True)
info510900['day_volatility'] = (pow(info510900['high'] -info510900['close'] , 2) +
                        pow(info510900['low'] -info510900['close'] , 2) )
for i in range(0,len(info510900.index)):
    info510900['day_volatility'][i] = math.sqrt(info510900['day_volatility'][i])    
                        
plt_title = 'volatility(50ETF vs H_ETF)'  
plt_figsize = (16, 9)  #unit is inch                      
plt.figure()
info510050['day_volatility'].plot(figsize = plt_figsize, title = plt_title, grid = True, legend =True)                          
info510900['day_volatility'].plot(figsize = plt_figsize, title = plt_title, grid = True, legend =True) 
plt.legend(['50ETF','H_ETF'])

plt.savefig("volatility(510050vs510900).png")

相关文章

  • 如何统计投资品种波动率(python)?

    目前正在网H股ETF,进行了接近一年了还没出清,虽然已盈利,但相对于50ETF来说现在想它还真不是好品种,不考虑强...

  • 数字货币统计套利

    什么是统计套利? 统计套利是运用数量化的方法构建投资组合,在降低市场波动率的同时,获得投资回报。统计套利从业人...

  • 人生投资的资产动态平衡(方三文)

    长期来说,股票是回报率最高的品种 但它的波动比较大,并不是每个投资者都能承受这样的波动。 债券、抗通胀...

  • 期权的波动率

    与标的资产价格相关的波动率有两种:历史波动率和隐含波动率。 历史波动率是对标的资产过去一段时间的价格行为通过统计的...

  • 如何围绕隐含波动率设计期权交易策略

    波动率简介 首先需要明确波动率是一个统计概念,我们常说的历史波动率是指资产在某一时间段内收益率的年化标准差。波动率...

  • 2023-02-14

    ====== 02-14统计结果(波动率0.0) =====linerlt: 1/246. f(x) = 0.2...

  • 2023-02-17

    ====== 02-17统计结果(波动率0.0) =====linerlt: 1/246. f(x) = 0.1...

  • 2023-02-23

    ====== 02-23统计结果(波动率0.0) =====linerlt: 1/246. f(x) = 0.1...

  • 什么样的货币基金值得买?

    面对市场总多的基金投资品种,我们如何挑选出,哪种基金更安全、收益率更高基金品种呢? 一、挑选货币基金的两大原则 安...

  • 品种太多迷人眼?-真格量化帮您速算多产品历史波动率

    在国内橡胶、玉米、棉花、铜相继加入到期权大家庭后,投资者与研究员愈发觉得脑袋不够用了。这么多品种的波动率,怎么算得...

网友评论

    本文标题:如何统计投资品种波动率(python)?

    本文链接:https://www.haomeiwen.com/subject/hhorjttx.html