Beispiel #1
0

# Returns versus risk factors
strategy_name = 'equity_vs_vol'
df = pd.DataFrame()
return_windows = [1, 5, 10, 21, 63]

df['returns'] = underlying_price / underlying_price.shift(t1) - 1
df['pnl'] = pd.to_numeric(sm.outputs[strategy_name]['combined_pnl_net']
                          ['optim_weight']).rolling(t1).sum()
df = df[np.isfinite(df).all(axis=1)]
plt.scatter(y=df['pnl'], x=df['returns'])


etl.add_equities_from_list(tickers=['IEI'], exchange_codes=['US'])
ids = db.get_equity_ids(equity_tickers=['IEI'])
etl.ingest_historical_equity_prices(ids=ids)

'''
--------------------------------------------------------------------------------
Bayesian time-varying expected returns
--------------------------------------------------------------------------------
'''

r = sm.outputs['vix_curve']['combined_pnl_net']['optim_weight']
r = r[np.isfinite(pd.to_numeric(r))]

psi_bar = 0.0
rho = 0.998
sig2_eps = r.var()
sig2_eta = sig2_eps / 252.0 / 2.0
Beispiel #2
0
                    data_dict[t1][t2].loc[ind, 'pnl_pct'].mean()
            counter += 1
mean_pnl_grid = mean_pnl_grid.sort_values(['tenor', 'return_period'])\
                .set_index(['return', 'tenor', 'return_period'])

mean_pnl_grid.unstack(level='return').to_excel('qfl\data\sp_convexity.xlsx')



'''
--------------------------------------------------------------------------------
Plotting volatility
--------------------------------------------------------------------------------
'''

ids = db.get_equity_ids(equity_tickers=md.get_etf_vol_universe())
etl.ingest_historical_equity_prices(ids=ids, start_date=dt.datetime(1990, 1, 1))

xlf = md.get_equity_prices(tickers=['XLB'], start_date = dt.datetime(2010, 1, 1))
xlf = xlf.reset_index(level='ticker', drop=True)
xlf['returns'] = xlf['adj_close'] / xlf['adj_close'].shift(1)
xlf['rv_63'] = xlf['returns'].rolling(window=63).std() * np.sqrt(252)

plt.plot(xlf['adj_close'])



'''
--------------------------------------------------------------------------------
Process to clean implied volatility
Process to create skew and curve by moneyness