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
Esempio 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
Esempio n. 4
0
    #plt.figure()
    #plt.plot(logMoneynesses, vol, 'ro')
    #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)
    #plt.figure()
    #plt.plot(logMoneynesses, vol, 'ro')
    #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, spot, daycounter, calendar,
                      to_ql_dates(maturity_dates), optiontype, '50etf')
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
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(2.2, 2.8, 0.01)

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y = np.meshgrid(plot_strikes, plot_years)
Esempio n. 6
0
print('strike = ', strike, ', option type : call')
print('=' * 100)
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)
Esempio n. 7
0
# Example
strike = 2700
dS = 0.001
iscall = True
curve = get_curve_treasury_bond(date_ql, daycounter)
yield_ts = util.get_yield_ts(date_ql,curve,maturitydt,daycounter)
dividend_ts = util.get_dividend_ts(date_ql,daycounter)

print('strike = ',strike,', option type : call')
print('='*100)
print("%10s %25s %25s %25s %25s" % ("Spot","delta_total","delta_eff","delta_constant_vol ","diff"))
print('-'*100)

volSurface_call = SviVolSurface(date_ql,paramset_c,daycounter,calendar)
svi_call = SviPricingModel(date_ql,volSurface_call,underlying,daycounter,calendar,util.to_ql_dates(maturity_dates),ql.Option.Call,contractType)

call_delta_total = []
call_delta_cnst = []
call_delta_eff = []
call_diff = []
#index=['data_total','data_const']
result = pd.DataFrame()
for spot in np.arange(2400.0,3200.0,10.0):

    delta = svi_call.get_option(spot,strike,maturitydt,ql.Option.Call).delta()
    # 全Delta
    delta_total = svi_call.calculate_total_delta(spot,strike,maturitydt,ql.Option.Call,spot*0.0001)
    # Effective Delta
    delta_eff = svi_call.calculate_effective_delta(spot,strike,maturitydt,ql.Option.Call, dS)
Esempio n. 8
0
spots = []
while evalDate < endDate:
    try:
        evaluation = Evaluation(evalDate, daycounter, calendar)
        if daily_close <= barrier: break
        put_price = put_data[put_230.Times.index(to_dt_date(evalDate))]
        call_price = call_data[call_265.Times.index(to_dt_date(evalDate))]
        portfolio_price = call_price - put_ratio * put_price
        svidata = svi_dataset.get(to_dt_date(evalDate))
        paramset = calibrered_params_ts.get(to_dt_date(evalDate))
        volSurface = SviVolSurface(evalDate, paramset, daycounter, calendar)
        daily_close = svidata.spot

        maturity_dates = sorted(svidata.dataSet.keys())
        svi = SviPricingModel(volSurface, daily_close, 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))
        # print(black_var_surface.blackVol(ttm,daily_close))
        underlying = ql.SimpleQuote(daily_close)
        # process = evaluation.get_bsmprocess(daycounter, underlying, black_var_surface)

        # vol = estimated_vols.get(to_dt_date(evalDate))
        ttm = daycounter.yearFraction(evalDate, maturitydt)

        vol = black_var_surface.blackVol(ttm, daily_close)
        if not vol > 0.0: vol = estimated_vols.get(to_dt_date(evalDate))
        process = evaluation.get_bsmprocess_cnstvol(daycounter, calendar,
                                                    underlying, vol)