示例#1
0
def to_ql_option_engine(engine_name=None, process=None, model=None):
    """ Returns a QuantLib.PricingEngine for Options

    :param engine_name: str
        The engine name
    :param process: QuantLib.StochasticProcess
        The QuantLib object with the option Stochastic Process.
    :param model: QuantLib.CalibratedModel
    :return: QuantLib.PricingEngine
    """
    if engine_name.upper() == 'BINOMIAL_VANILLA':
        return ql.BinomialVanillaEngine(process, 'LR', 801)
    elif engine_name.upper() == 'ANALYTIC_HESTON':
        if model is None:
            model = ql.HestonModel(process)
        elif model is not None and process is not None:
            model = model(process)
        return ql.AnalyticHestonEngine(model)
    elif engine_name.upper() == 'ANALYTIC_EUROPEAN':
        return ql.AnalyticEuropeanEngine(process)
    elif engine_name.upper() == 'ANALYTIC_EUROPEAN_DIVIDEND':
        return ql.AnalyticDividendEuropeanEngine(process)
    elif engine_name.upper() == "FINITE_DIFFERENCES":
        return ql.FdBlackScholesVanillaEngine(process)
    elif engine_name.upper() == 'HESTON_FINITE_DIFFERENCES':
        if model is None:
            model = ql.HestonModel(process)
        elif model is not None and process is not None:
            model = model(process)
        return ql.FdHestonVanillaEngine(model)
    elif engine_name.upper() == "BARONE_ADESI_WHALEY":
        return ql.BaroneAdesiWhaleyEngine(process)
    elif engine_name.upper() == "BJERKSUND_STENSLAND":
        return ql.BjerksundStenslandEngine(process)
    elif engine_name.upper() == "ANALYTIC_GJR_GARCH":
        if model is None:
            model = ql.GJRGARCHModel(process)
        elif model is not None and process is not None:
            model = model(process)
        return ql.AnalyticGJRGARCHEngine(model)
    elif engine_name.upper() == 'MC_GJR_GARCH':
        return ql.MCEuropeanGJRGARCHEngine(process=process,
                                           traits='pseudorandom',
                                           timeStepsPerYear=20,
                                           requiredTolerance=0.02)
    else:
        return None
示例#2
0
eu_exercise = ql.EuropeanExercise(maturity_date)
european_option = ql.VanillaOption(payoff, eu_exercise)

spot_handle = ql.QuoteHandle(ql.SimpleQuote(spot_price))
flat_ts = ql.YieldTermStructureHandle(
    ql.FlatForward(calculation_date, risk_free_rate, day_count))
dividend_yield = ql.YieldTermStructureHandle(
    ql.FlatForward(calculation_date, dividend_rate, day_count))
flat_vol_ts = ql.BlackVolTermStructureHandle(
    ql.BlackConstantVol(calculation_date, calendar, volatility, day_count))
bsm_process = ql.BlackScholesMertonProcess(spot_handle, dividend_yield,
                                           spotCurveHandle, flat_vol_ts)

steps = 1000
binomial_engine = ql.AnalyticDividendEuropeanEngine(bsm_process)
european_option.setPricingEngine(binomial_engine)
#print (european_option.NPV()*ratio_up)

#AnalyticDividendEuropeanEngine
#BinomialVanillaEngine
'''
Price the short put option

'''

maturity_date = maturityDate
spot_price = 14.455
strike_price_2 = 12.4467
volatility_2 = 0.37  # the historical vols or implied vols
dividend_rate = .01
示例#3
0
#european_option = ql.DividendVanillaOption(payoff, eu_exercise, div_dates_ql, div_amounts)

spot_handle = ql.QuoteHandle(ql.SimpleQuote(spot_price))

dividend_yield = ql.YieldTermStructureHandle(
    ql.FlatForward(calculation_date, dividend_rate, day_count))

flat_vol_ts = ql.BlackVolTermStructureHandle(
    ql.BlackConstantVol(calculation_date, calendar, volatility, day_count))

bsm_process = ql.BlackScholesMertonProcess(spot_handle, dividend_yield,
                                           spotCurveHandle, flat_vol_ts)
#bs_process = ql.BlackScholesProcess(spot_handle, spotCurveHandle, flat_vol_ts)

steps = 1000
engine = ql.AnalyticDividendEuropeanEngine(bsm_process)
european_option.setPricingEngine(engine)
long_call = european_option.NPV()
'''
Price the short put option

'''

maturity_date = maturityDate
spot_price = spotPrice
strike_price_2 = min_conv_px
volatility_2 = vol_lower  # the historical vols or implied vols
dividend_rate = div_yield
option_type_2 = ql.Option.Put

day_count = ql.Actual360()
 def getPricingEngine(self):
     engine = ql.AnalyticDividendEuropeanEngine(self.process)
     return engine