aboutsummaryrefslogtreecommitdiffstats
path: root/python/option_trades.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/option_trades.py')
-rw-r--r--python/option_trades.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/python/option_trades.py b/python/option_trades.py
index b05c1833..bf622ab6 100644
--- a/python/option_trades.py
+++ b/python/option_trades.py
@@ -79,10 +79,16 @@ def realized_vol(index, series, tenor, date=None, years=None):
raise ValueError("need to provide at least one of date or years")
date = (pd.Timestamp.now() - pd.DateOffset(years=years)).date()
returns = daily_spreads(index, series, tenor)
+ # GARCH(1,1) volatility process with constant mean
am = arch_model(returns)
res = am.fit(update_freq=0, disp='off')
return (res.conditional_volatility * math.sqrt(252), res)
+def lr_var(res):
+ """ computes long run variance of the garch process"""
+ var = res.params.omega/(1 - res.params['alpha[1]'] - res.params['beta[1]'])
+ return math.sqrt(var * 252)
+
def atm_vol_fun(v, ref_is_price=False, moneyness=0.2):
f = interp1d(v.strike.values, v.vol.values, fill_value='extrapolate')
atm_val = v['fwdspread'].iat[0]
@@ -145,11 +151,6 @@ def vol_var(percentile=0.99, index='IG'):
df = df.groupby(df.index.date).last()
return df.pct_change().quantile(percentile)
-def lr_var(res):
- """ computes long run variance of the garch process"""
- var = res.params.omega/(1 - res.params['alpha[1]'] - res.params['beta[1]'])
- return math.sqrt(var) * math.sqrt(252)
-
def index_rolling_returns(date=None, years=3, index="IG", tenor="5yr"):
"""computes on the run returns"""
if date is None: