My goal is to price American basket put options using the Least squares Monte Carlo, or Longstaff-Schwartz algorithm.
I currently have the one-dimensional case working with the Python file below (I am using the SWIG package), but I would like to change the number of basis functions used by the AmericanBasketEngine to make sure the price is accurate. How do I do this?
Looking at the C++ source, I found the
polynomOrder keyword argument with default value
2 of the class
AmericanBasketPathPricer. However, I do not know how this class is connected to the
MCAmericanBasketEngine, which does not have such a keyword argument. (I never programmed in either
C++, so I am quite lost in the source.)
Maybe is the polynomial order determined automatically, based on the
requiredTolerance? That would be ideal, but I couldn't find a description of what the
MCAmericanBasketEngine does exactly anywhere.
from QuantLib import * d=1 #To be increased... todaysDate = Date(15,May,1998) Settings.instance().evaluationDate = todaysDate settlementDate = Date(17,May,1998) riskFreeRate = FlatForward(settlementDate, 0.05, Actual365Fixed()) payoff = PlainVanillaPayoff(Option.Put, 100.0) underlying1 = SimpleQuote(100.0) volatility1 = BlackConstantVol(todaysDate, TARGET(), 0.30, Actual365Fixed()) dividendYield1 = FlatForward(settlementDate, 0.00, Actual365Fixed()) process1 = BlackScholesMertonProcess(QuoteHandle(underlying1), YieldTermStructureHandle(dividendYield1), YieldTermStructureHandle(riskFreeRate), BlackVolTermStructureHandle(volatility1)) procs = StochasticProcessVector() procs.push_back(process1) matrix = Matrix(1,1) matrix = 1.0 process = StochasticProcessArray(procs, matrix) american_exercise = AmericanExercise(Date(17,May,1998),Date(17,May,1999)) basketoption = BasketOption(AverageBasketPayoff(payoff,d),american_exercise) basketoption.setPricingEngine( MCAmericanBasketEngine( process, 'pseudorandom', polynomOrder = 2,#keyword does not exist timeStepsPerYear = 100, requiredTolerance = 0.01, #seed = 42)) ) ) print(basketoption.NPV())