Ejemplo n.º 1
0
dates = np.array(db_invariants_series.index)

db_invariants_nextstep = pd.read_csv(path + 'db_invariants_nextstep.csv')
# -

# ## [Step 1](https://www.arpm.co/lab/redirect.php?permalink=s_checklist_scenariobased_step03-implementation-step01): Set the flexible probabilities

# +
# time and state conditioning on smoothed and scored VIX returns

# state indicator: VIX compounded return realizations
db_vix['c_vix'] = np.log(db_vix).diff()
# extract data for analysis dates
c_vix = db_vix.c_vix[dates].values
# smoothing
z_smooth = smoothing(c_vix, tau_hl_smooth)
# scoring
z = scoring(z_smooth, tau_hl_score)
# target value
z_star = z[-1]
# prior probabilities
p_prior = exp_decay_fp(t_, tau_hl_prior)
# posterior probabilities
p = conditional_fp(z, z_star, alpha, p_prior)
# effective number of scenarios
ens = effective_num_scenarios(p)

print('Effective number of scenarios is', int(round(ens)))
# -

# ## [Step 2](https://www.arpm.co/lab/redirect.php?permalink=s_checklist_scenariobased_step03-implementation-step02): Estimate the marginal distributions for stocks, S&P 500 and implied volatility
Ejemplo n.º 2
0
# merging datasets
spx_vix = pd.merge(spx, vix, how='inner', on=['date'])
date = spx_vix.date

# ## [Step 1](https://www.arpm.co/lab/redirect.php?permalink=s_smooth_kernel_fp-implementation-step01): Compute the S&P 500 compounded return and the VIX compounded return

epsi = np.diff(np.log(spx_vix.SPX_close))  # S&P 500 index compounded return
v_vix = np.array(spx_vix.VIX_close)  # VIX index value
c = np.diff(np.log(v_vix))  # VIX index compounded return
t_ = len(epsi)

# ## [Step 2](https://www.arpm.co/lab/redirect.php?permalink=s_smooth_kernel_fp-implementation-step02): Compute the risk factor by smoothing and scoring VIX compounded return

tau_hl_smoo = 15
tau_hl_scor = 100
z_smooth = smoothing(c, tau_hl_smoo)  # smoothing
z = scoring(z_smooth, tau_hl_scor)  # scoring

# ## [Step 3](https://www.arpm.co/lab/redirect.php?permalink=s_smooth_kernel_fp-implementation-step03): Compute the smooth kernel probabilities

p_smooth = smooth_kernel_fp(z, z_star, h, gamma=gamma)

# ## [Step 4](https://www.arpm.co/lab/redirect.php?permalink=s_smooth_kernel_fp-implementation-step04): Compute the effective number of scenarios

ens = effective_num_scenarios(p_smooth)

# ## [Step 5](https://www.arpm.co/lab/redirect.php?permalink=s_smooth_kernel_fp-implementation-step05): Compute flexible probabilities histogram

f_eps, x_eps = histogram_sp(epsi, p=p_smooth, k_=10*np.log(t_))

# ## Plots