diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/beta_trade.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/python/beta_trade.py b/python/beta_trade.py index 24a30ea6..34058090 100644 --- a/python/beta_trade.py +++ b/python/beta_trade.py @@ -11,3 +11,25 @@ beta = model.beta.x am = arch_model(returns.ig.dropna()) res = am.fit() + +# three ways of computing the volatility +# 20 days simple moving average +vol_sma = returns.hy.rolling(20).std() * math.sqrt(252) +vol_ewma = returns.hy.ewm(span=20).std() * math.sqrt(252) +# GARCH(1,1) +# we scale returns by 10 to help with the fitting +scale = 10 +am = arch_model(scale * returns.hy.dropna()) +res = am.fit() +vol_garch = res.conditional_volatility * math.sqrt(252)/scale +vol = pd.concat([vol_sma, vol_ewma, vol_garch], axis=1) + +## let's get the betas +beta_ewma = (returns. + ewm(span=20). + cov(). + apply(lambda df:df.loc['ig', 'hy']/df.loc['ig', 'ig'], + ('minor', 'major'))) + +feather.write_dataframe(beta_ewma.reset_index(), + "/home/share/CorpCDOs/data/beta.fth") |
