strike = svidata.spot
        barrier = strike*(1+pct)
        endDate = calendar.advance(maturitydt,ql.Period(-1,ql.Days))
        ################Barrier Option Info#####################
        #print('barrier/strike',barrier/strike)

        optionBarrierEuropean = OptionBarrierEuropean(strike,maturitydt,optionType,barrier,barrierType)
        barrier_option = optionBarrierEuropean.option_ql
        hist_spots = []
        #########################################################
        # construct vol surface on last day's close prices.
        evaluation = Evaluation(begDate, daycounter, calendar)
        daily_close, black_var_surface, const_vol = get_vol_data(begDate,daycounter,calendar,contractType)
        #print('init spot : ',daily_close)
        underlying = ql.SimpleQuote(daily_close)
        process_svi_h = evaluation.get_bsmprocess(daycounter, underlying, black_var_surface)
        process_bs_h = evaluation.get_bsmprocess_cnstvol(daycounter, calendar, underlying, const_vol)

        price_bs, delta_bs = exotic_util.calculate_barrier_price(evaluation, optionBarrierEuropean, hist_spots,
                                                                 process_bs_h, engineType)
        try:
            price_svi, delta_svi = exotic_util.calculate_barrier_price(evaluation, optionBarrierEuropean, hist_spots,
                                                                       process_svi_h, engineType)
        except:
            continue
        init_svi = price_svi
        init_bs = price_bs
        init_spot = daily_close
        tradingcost_svi = abs(delta_svi)*daily_close*fee
        tradingcost_bs = abs(delta_bs)*daily_close*fee
        cash_svi = price_svi - delta_svi*daily_close - tradingcost_svi
Пример #2
0
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(
        ql.BinomialVanillaEngine(process, 'crr', 801))
    barrierql.setPricingEngine(ql.BinomialBarrierEngine(process, 'crr', 801))
    delta = optionql_call.delta()
    barrierdelta = barrierql.delta()
    # 全Delta
    delta_total = svi_call.calculate_total_delta(evaluation, option_call,
                                                 engineType, spot,
                                                 spot * 0.0001)
    # Effective Delta
    delta_eff = svi_call.calculate_effective_delta(evaluation, option_call,
                                                   engineType, spot, dS)