|
From: Jack G <jac...@gm...> - 2020-11-27 09:47:53
|
Luigi, Thanks for the pointer. It seems as though the only multi-path generator that is currently exposed via SWIG is for pseudorandoms only ( https://github.com/lballabio/QuantLib-SWIG/blob/master/SWIG/montecarlo.i). I have the feeling that I should be adding the following to expose a multi-path generator for low discrepancy numbers, but for some reason this is upsetting my SWIG build (the error I get is "gcc: fatal error: Killed signal terminated program cc1plus" which I usually see when I add something subtly bad)... am I thinking on the right lines here? *%{* *typedef QuantLib::MultiPathGenerator<GaussianLowDiscrepancySequenceGenerator>* * GaussianMultiPathSobolGenerator;* *%}* *class GaussianMultiPathSobolGenerator {* * public:* * %extend {* * GaussianMultiPathSobolGenerator(* * const ext::shared_ptr<StochasticProcess>& process,* * const std::vector<Time>& times,* * const GaussianLowDiscrepancySequenceGenerator& generator,* * bool brownianBridge = false) {* * return new GaussianMultiPathSobolGenerator(process,* * QuantLib::TimeGrid(* * times.begin(),* * times.end()),* * generator,* * brownianBridge);* * }* * }* * Sample<MultiPath> next() const;* * Sample<MultiPath> antithetic() const;* *};* Best, Jack On Fri, Nov 27, 2020 at 4:35 PM Luigi Ballabio <lui...@gm...> wrote: > Hello Jack, > the Heston process is two-dimensional (it models both underlying and > vol) so you'll need to use a multi-path generator. The error you're > getting is the generator trying to cast the process to a one-dimensional > one and failing. > > Luigi > > > On Fri, Nov 27, 2020 at 4:13 AM Jack G <jac...@gm...> wrote: > >> Dear QL Users, >> >> I'm getting a slightly cryptic error when I try to manually generate >> paths for Heston using LD numbers in Python. >> >> It works fine for BS: >> >> *import QuantLib as ql* >> >> *initialValue = ql.QuoteHandle(ql.SimpleQuote(100))* >> *sigma = 0.2* >> >> *today = ql.Date().todaysDate()* >> *riskFreeTS = ql.YieldTermStructureHandle(ql.FlatForward(today, 0.0, >> ql.Actual365Fixed()))* >> *dividendTS = ql.YieldTermStructureHandle(ql.FlatForward(today, 0.0, >> ql.Actual365Fixed()))* >> *volTS = ql.BlackVolTermStructureHandle(ql.BlackConstantVol(today, >> ql.NullCalendar(), sigma, ql.Actual365Fixed()))* >> *process = ql.BlackScholesProcess(initialValue, riskFreeTS, volTS)* >> >> *times = ql.TimeGrid(1, 12)* >> >> *rng = ql.UniformLowDiscrepancySequenceGenerator(12)* >> *seq = ql.GaussianLowDiscrepancySequenceGenerator(rng)* >> *path_gen = ql.GaussianSobolPathGenerator(process, times, seq, False)* >> >> *x = path_gen.next()* >> >> >> However, when I try the same with Heston, I get the following error: " >> RuntimeError: Boost assertion failed: px != 0" >> >> *v0 = 0.09 kappa = 0.8 theta = 0.09 rho = 0.4 sigma = 0.1 process = >> ql.HestonProcess(riskFreeTS, dividendTS, initialValue, v0, kappa, theta, >> sigma, rho) times = ql.TimeGrid(1, 12) rng = >> ql.UniformLowDiscrepancySequenceGenerator(12) seq = >> ql.GaussianLowDiscrepancySequenceGenerator(rng) path_gen = >> ql.GaussianSobolPathGenerator(process, times, seq, False) x = >> path_gen.next()* >> >> >> My working hypothesis is that the rng needs to be dimension 24 instead of >> 12 because of the second vol process that needs to be simulated, but when I >> change the dimension to 24 I get the following error: "RuntimeError: >> sequence generator dimensionality (24) != timeSteps (12)" >> >> I've looked through the QuantLib-SWIG code but not got too far... any >> pointers about how I might deal with this? Or have I done something stupid >> somewhere? >> >> Thanks, >> Jack >> >> >> _______________________________________________ >> QuantLib-users mailing list >> Qua...@li... >> https://lists.sourceforge.net/lists/listinfo/quantlib-users >> > |