aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/option_trades.py25
1 files changed, 10 insertions, 15 deletions
diff --git a/python/option_trades.py b/python/option_trades.py
index bf622ab6..c3f9cb77 100644
--- a/python/option_trades.py
+++ b/python/option_trades.py
@@ -85,8 +85,16 @@ def realized_vol(index, series, tenor, date=None, years=None):
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]'])
+ """ computes long run variance of the garch process
+
+ .. math::
+
+ \sigma^2=\frac{\omega}{1-\sum_{i=1}^p \alpha_i + \sum_{i=1}^q \beta_i}
+
+ """
+ names = res.model.volatility.parameter_names()
+ ## names[0] is omega, rest is alpha[1],..., alpha[p], beta[1],...,beta[q]
+ var = res.params[names[0]]/(1 - res.params[names[1:]])
return math.sqrt(var * 252)
def atm_vol_fun(v, ref_is_price=False, moneyness=0.2):
@@ -188,19 +196,6 @@ def get_index_ref(index, series, date, expiry, conn):
conn.commit()
return ref, fwdspread
-def get_strike(index, series, date, expiry, conn):
- with conn.cursor() as c:
- c.execute("SELECT strike from index_quotes " \
- "WHERE index=%s and series=%s and quotedate::date=%s "\
- "AND expiry=%s ORDER BY quotedate desc",
- (index, series, date, expiry))
- try:
- stri
- except TypeError:
- ref, fwdspread = None, None
- conn.commit()
- return ref, fwdspread
-
def get_option_pnl(strike, expiry, index, series, start_date, engine):
for s in [strike, strike+2.5, strike-2.5, strike+5]:
df = pd.read_sql_query("SELECT quotedate, (pay_bid+pay_offer)/2 AS pay_mid, " \