n_ = len(delta_moneyness)

implied_vol = db_impliedvol.loc[(
    db_impliedvol['date'].isin(dates)), :].iloc[:, 2:].values

implvol_delta_moneyness_3d = np.zeros((t_, k_, n_))
for k in range(k_):
    implvol_delta_moneyness_3d[:, k, :] = \
        np.r_[np.array(implied_vol[:, k::k_])]

# constant and flat yield curve
y_tau = y * np.ones((t_, k_))

# convert from delta-moneyness to m-moneyness
implvol_m_moneyness, m_moneyness = \
    implvol_delta2m_moneyness(implvol_delta_moneyness_3d, tau_implvol,
                              delta_moneyness, y_tau, tau_implvol, l_)
# -

# ## [Step 2](https://www.arpm.co/lab/redirect.php?permalink=s_implied_volatility_surface-implementation-step02): Save database

# +
implvol2d = implvol_m_moneyness.reshape((t_, k_ * l_))
out = pd.DataFrame(
    {
        'm=' + str(m_moneyness[0]) + ' tau=' + str(tau_implvol[0]):
        implvol2d[:, 0]
    },
    index=dates)
for l in range(1, l_):
    df2 = pd.DataFrame(
        {
r_bar_call = chi(r_sandp)  # prediction
u = r_call - r_bar_call  # residuals

# ## [Step 4](https://www.arpm.co/lab/redirect.php?permalink=s_call_mean_regression-implementation-step04): Compute payoff at t_end and current value of the call option as a function of the underlying S&P500

# +
i_ = 50
# grid of the underlying values
v_sandp_grid = np.linspace(v_sandp_thor.min(), v_sandp_thor.max(), i_)
# time to expiry (in years)
tau = (t_end - t_now) / 252
# compute induced m-moneyness
m_sandp = np.log(v_sandp_grid / k_strk) / np.sqrt(tau)

# transition from delta-moneyness to m-moneyness parametrization
sigma_tnow_m_tau, m_grid = implvol_delta2m_moneyness(
    np.array([sigma_delta_tnow.T]), tau_grid, delta_grid, y, tau, 13)
# interpolate impied volatility surface
sigma = interpolate.interp2d(
    m_grid, tau_grid,
    sigma_tnow_m_tau.reshape(tau_grid.shape[0], m_grid.shape[0]))
sigma_tnow_m_sandp_tau = sigma(m_sandp, tau)

#current Black-Scholes values of call option as the function of the underlying
v_call_bsm_tnow_kstrk_tend = bsm_function(v_sandp_grid, y,
                                          sigma_tnow_m_sandp_tau, m_sandp, tau)
# payoff of call option as the function of the underlying values
v_call_tend_kstrk_tend = np.maximum(v_sandp_grid - k_strk, 0)
# returns
r_call_bsm_tnow = v_call_bsm_tnow_kstrk_tend / v_call_tnow_kstrk_tend - 1
r_call_tend = v_call_tend_kstrk_tend / v_call_tnow_kstrk_tend - 1
# -
Beispiel #3
0
# value of the S&P 500 index
v_tnow[d_] = db_impliedvol.loc[t_now, 'underlying']
v_tinit[d_] = db_impliedvol.loc[t_init, 'underlying']
v_tnow_names[d_] = 'sp_index'

# update counter
d_ = d_ + 1
# -

# ## [Step 3](https://www.arpm.co/lab/redirect.php?permalink=s_checklist_scenariobased_step01-implementation-step03): Call and put options on the S&P 500 Index

# +
# from delta-moneyness to m-moneyness parametrization
implvol_m_moneyness_3d, m_moneyness = \
    implvol_delta2m_moneyness(implvol_delta_moneyness_3d, tau_implvol,
                              delta_moneyness, y*np.ones((t_, k_)),
                              tau_implvol, l_)

# calculate log implied volatility
log_implvol_m_moneyness_2d = \
    np.log(np.reshape(implvol_m_moneyness_3d,
                      (t_, k_*(l_)), 'F'))

# value of the underlying
s_tnow = v_tnow[d_stocks]
s_tinit = v_tinit[d_stocks]

# time to expiry (in years)
tau_option_tnow = np.busday_count(t_now, tend_option) / 252
tau_option_tinit = np.busday_count(t_init, tend_option) / 252