refraction-ray / xalpha

基金投资管理回测引擎
MIT License
2.04k stars 437 forks source link

volatility 计算疑问 #96

Closed bobbypiggy closed 3 years ago

bobbypiggy commented 3 years ago

xalpha的计算公式源码是: @staticmethod def ratedaily(price, date=yesterdayobj()): partp = price[price["date"] <= date] return list(partp["netvalue"].pct_change())[1:]

@staticmethod def volatility(price, date=yesterdayobj()): df = pd.DataFrame(data={"rate": indicator.ratedaily(price, date)}) *return df.std().rate 15.8144**

def algorithm_volatility(self, date=yesterdayobj()): return indicator.volatility(self.price, date)

【问题】:一般的公式不是应该是如下这样吗? https://techflare.blog/how-to-calculate-historical-volatility-and-sharpe-ratio-in-python/

return = logarithm(current closing price / previous closing price) volatility = std(sum(return)) * sqrt(trading days) 中国交易天数应该数是250天,xalpha的15.8144好像和250/252开根号(15.811388300841897/15.874507866387544)都对不上,是不是15.8114的笔误?

bobbypiggy commented 3 years ago

https://www.joinquant.com/help/api/help#api:%E9%A3%8E%E9%99%A9%E6%8C%87%E6%A0%87

refraction-ray commented 3 years ago

你说的对,似乎应该是 15.8144,估计我手抖打错了。

关于两种波动率计算方案,在每日涨幅$r<<1$的情况下,是一致的,因为 $ln(1+r)= r$.

bobbypiggy commented 3 years ago

好的,源码显式的写sqrt(250)比较好。