Posted by
kmanley on
URL: http://quantlib.414.s1.nabble.com/Question-on-Path-Generation-for-Heston-Processes-tp7043p7044.html
You need to use a multi path generator. This is an example of how I do it from Python, this can be translated directly into C++
from lib.QuantLib import *
def run():
today = Date(15, October, 2008)
riskFreeRate = FlatForward(today, 0.0, ActualActual())
dividendRate = FlatForward(today, 0.0, ActualActual())
discretization = Reflection # PartialTrunction, FullTruncation, Reflection, ExactVariance
hp = HestonProcess(YieldTermStructureHandle(riskFreeRate),
YieldTermStructureHandle(dividendRate),
QuoteHandle(SimpleQuote(570.89)), # s0
.48, # v0
1.2, # kappa
0.25, # theta
0.80, # sigma
-0.64, # rho
discretization)
times = [n/365.0 for n in range(20)]
rsg = GaussianRandomSequenceGenerator(UniformRandomSequenceGenerator(2*(len(times)-1), UniformRandomGenerator()))
mpg = GaussianMultiPathGenerator(hp, TimeGrid(times), rsg)
while True:
sample = mpg.next()
multipath = sample.value()
assetprices = multipath[0]
vols = multipath[1]
for i in range(len(multipath)):
print "time %f: asset=%.2f, vol=%.2f" % (assetprices.time(i), assetprices.value(i), vols.value(i))
raw_input("press any key to generate another multipath")
if __name__ == "__main__":
run()
thusi wrote
Would the following code work, if the process is Heston Process?
rsg_type rsg = PseudoRandom::make_sequence_generator(timeSteps, seconds);
PathGenerator<rsg_type> generator(process, length, timeSteps,
rsg, false);
for (int k=0; k< numOfPaths; k++){
sample_type sample = generator.next();
When I try to use this it generate an exception. I believe the reason is that the Process for PathGenerator is assumed to be StochasticProcess1D