|
From: Ashish B. <ash...@gm...> - 2022-06-20 08:11:50
|
Following is the code that I am using to evaluate the barrier option. Here if I pass the spot which has crossed the barrier for knock-in or knock-out options, I get an error. The down-out is in the code and for down-in, I took the example given in row# 266 of with spot price as 94 from: https://github.com/lballabio/QuantLib/blob/master/test-suite/barrieroption.cpp My python code: ############################################################################ import QuantLib as ql # Setting Barrier option parameters calculation_date = ql.Date(1, 6, 2021) maturity_date = ql.Date(25, 11, 2021) spot_price = 577.0 strike_price = 770.0 volatility = 43.56/100 option_type = ql.Option.Call risk_free_rate = 0.175/100 barrier_price = 400.0 barrier_type = ql.Barrier.DownOut rebate = 0 # no rebate day_count = ql.Actual365Fixed() calendar = ql.TARGET() marketpremium = 18.64 ql.Settings.instance().evaluationDate = calculation_date # Constructing the EU option in QL payoff = ql.PlainVanillaPayoff(option_type, strike_price) eu_exercise = ql.EuropeanExercise(maturity_date) barrier_eu_option = ql.BarrierOption(barrier_type,barrier_price,rebate,payoff, eu_exercise) # The Black-Scholes-Merton process is constructed spot_handle = ql.QuoteHandle( ql.SimpleQuote(spot_price) ) flat_rate_ts = ql.YieldTermStructureHandle( ql.FlatForward(calculation_date, risk_free_rate, day_count) ) flat_vol_ts = ql.BlackVolTermStructureHandle( ql.BlackConstantVol(calculation_date, calendar, volatility, day_count) ) bs_process = ql.BlackScholesProcess(spot_handle, flat_rate_ts, flat_vol_ts) # compute the theoretical price using the AnalyticEuropeanEngine barrier_eu_option.setPricingEngine(ql.FdBlackScholesBarrierEngine(bs_process)) br_eu_price = barrier_eu_option.NPV() print("The theoretical price for EU barrier is %lf" % br_eu_price) ############################################################################ Regards, Ashish On Fri, 17 Jun 2022 at 02:40, Jonathan Sweemer <sw...@gm...> wrote: > Hi Ashish, can you share your code or a link to it? > > 2022년 6월 17일 (금) 03:35, Ashish Bansal <ash...@gm...>님이 작성: > >> Hi, >> >> Any guidance on this error in barriers? >> >> Regards, >> Ashish >> >> On Tue, 14 Jun 2022 at 13:03, Ashish Bansal <ash...@gm...> >> wrote: >> >>> Dear team, >>> >>> I need some guidance on the pricing of the barrier option using >>> the FdBlackScholesBarrierEngine in the event that the barrier is hit: >>> 1. for Down-Out, when I pass the spot less than the barrier, I get >>> RunTimeerror for interpolation range. Should I block the pricing at all in >>> this case? Can't the engine handle it? >>> 2. For Down-in, I am getting the same error whereas the option gets >>> activated and is still live then why is this not priced by the engine? Am >>> I doing something wrong? >>> >>> What is the difference between FdBlackScholesBarrierEngine >>> and AnalyticBarrierEngine? I compared a few results and found a slight >>> difference in values. Any suggestion on which one to use? >>> >>> Any help would be appreciated. >>> >>> Thanks >>> Ashish >>> >> _______________________________________________ >> QuantLib-users mailing list >> Qua...@li... >> https://lists.sourceforge.net/lists/listinfo/quantlib-users >> > |