def get_vol_data(evalDate,daycounter,calendar,contractType):
    svidata = svi_dataset.get(to_dt_date(evalDate))
    paramset = calibrered_params_ts.get(to_dt_date(evalDate))
    volSurface = SviVolSurface(evalDate, paramset, daycounter, calendar)
    spot = svidata.spot
    maturity_dates = sorted(svidata.dataSet.keys())
    svi = SviPricingModel(volSurface, spot, daycounter, calendar,
                            to_ql_dates(maturity_dates), ql.Option.Call, contractType)
    black_var_surface = svi.black_var_surface()
    const_vol = estimated_vols.get(to_dt_date(evalDate))
    return spot, black_var_surface, const_vol
Ejemplo n.º 2
0
def get_vol_data(evalDate,daycounter,calendar,contractType):
    svidata = svi_dataset.get(to_dt_date(evalDate))
    paramset = calibrered_params_ts.get(to_dt_date(evalDate))
    volSurface = SviVolSurface(evalDate, paramset, daycounter, calendar)
    underlyings = {}
    dataset = svidata.dataSet
    for mdate in svidata.dataSet.keys():
        underlyings.update({mdate:dataset.get(mdate).spot})
    maturity_dates = sorted(svidata.dataSet.keys())
    svi = SviPricingModel(volSurface, underlyings, daycounter, calendar,
                            to_ql_dates(maturity_dates), ql.Option.Call, contractType)
    black_var_surface = svi.black_var_surface()
    const_vol = estimated_vols.get(to_dt_date(evalDate))
    return black_var_surface, const_vol
def get_vol_data_MA(evalDate, daycounter, calendar, contractType):
    black_var_surfaces = []
    startdt = calendar.advance(evalDate, ql.Period(-5, ql.Days))
    while startdt < dt:
        svidata = svi_dataset.get(to_dt_date(evalDate))
        paramset = calibrered_params_ts.get(to_dt_date(evalDate))
        volSurface = SviVolSurface(evalDate, paramset, daycounter, calendar)
        spot = svidata.spot
        maturity_dates = sorted(svidata.dataSet.keys())
        svi = SviPricingModel(volSurface, spot, daycounter, calendar,
                              to_ql_dates(maturity_dates), ql.Option.Call,
                              contractType)
        black_var_surface = svi.black_var_surface()
        black_var_surfaces.append(black_var_surface)
    const_vol = estimated_vols.get(to_dt_date(evalDate))
    spot = svi_dataset.get(to_dt_date(evalDate)).spot
    return spot, black_var_surfaces, const_vol
Ejemplo n.º 4
0
    #plt.plot(x_svi, vol_svi, 'b--')
    #plt.title('vol, ' + str(evalDate) + ', ' + str(mdate))
    #plt.figure()
    #plt.plot(logMoneynesses, totalvariance, 'ro')
    #plt.plot(x_svi, tv_svi2, 'b--')
    #plt.title('tv, ' + str(evalDate) + ', ' + str(mdate))
    #plt.show()

#print(calibrered_params)
maturity_dates = sorted(calibrered_params.keys())
#print(maturity_dates)
calibrered_params_ts.update({evalDate: calibrered_params})
volSurface = SviVolSurface(evalDate, calibrered_params, daycounter, calendar)
svi = SviPricingModel(volSurface, underlyings, daycounter, calendar,
                      to_ql_dates(maturity_dates), ql.Option.Put, 'm')
black_var_surface = svi.black_var_surface()
#local_vol_surface = ql.LocalVolSurface(ql.BlackVolTermStructureHandle(black_var_surface),
#                                       yield_ts,dividend_ts,spot)
dt = black_var_surface.maxDate()
t = daycounter.yearFraction(evalDate, dt)
# Plot
print('plot')
plt.rcParams['font.sans-serif'] = ['STKaiti']
plt.rcParams.update({'font.size': 13})
plot_years = np.arange(0.05, t - 0.05, 0.01)
plot_strikes = np.arange(float(min_k), float(max_k), 10.0)

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y = np.meshgrid(plot_strikes, plot_years)
Ejemplo n.º 5
0
print("%10s %25s %25s %25s %25s %25s" %
      ("Spot", "barrier_delta", "european_delta", "delta_total", "delta_eff",
       "diff"))
print('-' * 100)
barrier = 2.1
#barrier = 2.6
option_call = OptionPlainEuropean(strike, maturitydt, ql.Option.Call)
optionql_call = option_call.option_ql
barrier_option = OptionBarrierEuropean(strike, maturitydt, ql.Option.Call,
                                       barrier, ql.Barrier.DownOut)
barrierql = barrier_option.option_ql
volSurface_call = SviVolSurface(date_ql, paramset_c, daycounter, calendar)
svi_call = SviPricingModel(volSurface_call, underlying, daycounter, calendar,
                           util.to_ql_dates(maturity_dates), ql.Option.Call,
                           contractType)
vol_surface_call = svi_call.black_var_surface()

call_delta_total = []
call_delta_cnst = []
call_delta_eff = []
call_diff = []
call_barrierdelta = []
#index=['data_total','data_const']
result = pd.DataFrame()
underlying_ql = ql.SimpleQuote(0.0)
process = evaluation.get_bsmprocess(daycounter, underlying_ql,
                                    vol_surface_call)
for spot in spot_range:
    underlying_ql.setValue(spot)
    #engine = OptionEngine(process, engineType).engine
    optionql_call.setPricingEngine(