Hi, i tried to adapt \test-suite\hestonmodel.cpp to print out path values of the process. Specifically, within one of the test sections of hestonmodel, i inserted a snippet of code from \test-suite\pathgenerator.cpp to print out path values. The key elements then looks as follows: boost::shared_ptr<HestonProcess> process(new HestonProcess( riskFreeTS, dividendTS, s0, 0.3, 1.16, 0.2, 0.8, 0.8)); .... typedef PseudoRandom::rsg_type rsg_type; typedef MultiPathGenerator<rsg_type>::sample_type sample_type; BigNatural seed = 42; Time length = 10; Size timeSteps = 12; Size assets = process->size(); rsg_type rsg = PseudoRandom::make_sequence_generator(timeSteps*assets, seed); MultiPathGenerator<rsg_type> generator(process, TimeGrid(length, timeSteps), rsg, false); Size i; for (i=0; i<100; i++){ sample_type sample = generator.next(); wtfil << " i= " << i << " value[0]= "<< sample.value[0].back() << " value[1]= "<< sample.value[1].back() << std::endl; } // end i loop This produces [first 11 values]: i= 0 value[0]= 8.38959 value[1]= -0.527286 i= 1 value[0]= 7.17443 value[1]= -0.0744848 i= 2 value[0]= 31.5997 value[1]= 0.669117 i= 3 value[0]= 3.29738 value[1]= 0.0869779 i= 4 value[0]= 7.42287 value[1]= 0.220784 i= 5 value[0]= 1.56449 value[1]= -0.0911644 i= 6 value[0]= 4.15224 value[1]= -0.0711199 i= 7 value[0]= 14.0519 value[1]= -0.16052 i= 8 value[0]= 7.14489 value[1]= 0.216222 i= 9 value[0]= 9.32183 value[1]= 0.155854 i= 10 value[0]= 3.46721 value[1]= -0.333396 I thought value[0] and value[1] would be the the asset value and the variance, respectively [or their changes] at each time step i. But value[0] seems to jump a lot (e.g., from sstep 1 to step 2] and value[1] is often negative. Am I doing something wrong, or do these values represent something else? How would I recover the stock value and variance at each time step? [I tried different parameter sets----some fixed the negative variance issue, but value[0] still bounces around a lot.] thanks -------------------------------------------- P.C. Venkatesh Office of Prudential Supervision & Risk Analysis Division of Trading and Markets, SEC Station Place, 100 F Street, N.E., Washington, D.C. 20549 e-mail: [hidden email] vox: 202 551 5549 fax: 202 772-9273 . ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hi
generator.next() generates a complete new path. Therefore please change the for - loop towards for (k=0; k<100; k++){ sample_type sample = generator.next(); for (int i=0; i < 12; ++i) wtfil << " i= " << i << " value[0]= "<< sample.value[0][i] << " value[1]= "<< sample.value[1][i] << std::endl; } // end i loop Your suggestion is right, value[0] is the asset path and value[1] is the variance. By default the Heston process is using an special kind of the Euler discretization, the so called FullTruncation scheme. Therefore the variance might become negative but heuristics have shown that these discretization scheme produces less errors than e.g. the reflexion scheme. If you don't like it use the ExactVariance discretization scheme. boost::shared_ptr<HestonProcess> process(new HestonProcess( riskFreeTS, dividendTS, s0, 0.3, 1.16, 0.2,0.8,0.8,HestonProcess::ExactVariance))); It's slower but the variance will stay positive (or zero if the Feller constraint is violated). Just one additional remark, your vol of vol and your instantaneous variance are quite high and it seems that you are using only 12 timesteps to simulate 10 years. This will lead to large discretization errors even with the ExactVariance scheme. Please use much more time steps. hope that helps Klaus On Tuesday 18 March 2008 21:47:45 Venkatesh, P.C. wrote: > Hi, i tried to adapt \test-suite\hestonmodel.cpp to print out path > values of the process. Specifically, within one of the test sections of > hestonmodel, i inserted a snippet of code from > \test-suite\pathgenerator.cpp to print out path values. The key > elements then looks as follows: > > boost::shared_ptr<HestonProcess> process(new HestonProcess( > riskFreeTS, dividendTS, s0, 0.3, 1.16, 0.2, 0.8, > 0.8)); > .... > typedef PseudoRandom::rsg_type rsg_type; > typedef MultiPathGenerator<rsg_type>::sample_type sample_type; > > BigNatural seed = 42; Time length = 10; Size timeSteps = 12; > Size assets = process->size(); > rsg_type rsg = > PseudoRandom::make_sequence_generator(timeSteps*assets, > seed); > MultiPathGenerator<rsg_type> generator(process, > TimeGrid(length, timeSteps), > rsg, false); > > Size i; > for (i=0; i<100; i++){ > sample_type sample = generator.next(); > wtfil << " i= " << i << " value[0]= "<< sample.value[0].back() << > " value[1]= "<< sample.value[1].back() << std::endl; > } // end i loop > > This produces [first 11 values]: > > i= 0 value[0]= 8.38959 value[1]= -0.527286 > i= 1 value[0]= 7.17443 value[1]= -0.0744848 > i= 2 value[0]= 31.5997 value[1]= 0.669117 > i= 3 value[0]= 3.29738 value[1]= 0.0869779 > i= 4 value[0]= 7.42287 value[1]= 0.220784 > i= 5 value[0]= 1.56449 value[1]= -0.0911644 > i= 6 value[0]= 4.15224 value[1]= -0.0711199 > i= 7 value[0]= 14.0519 value[1]= -0.16052 > i= 8 value[0]= 7.14489 value[1]= 0.216222 > i= 9 value[0]= 9.32183 value[1]= 0.155854 > i= 10 value[0]= 3.46721 value[1]= -0.333396 > > I thought value[0] and value[1] would be the the asset value and the > variance, respectively [or their changes] at each time step i. But > value[0] seems to jump a lot (e.g., from sstep 1 to step 2] and value[1] > is often negative. Am I doing something wrong, or do these values > represent something else? How would I recover the stock value and > variance at each time step? [I tried different parameter sets----some > fixed the negative variance issue, but value[0] still bounces around a > lot.] > > thanks > -------------------------------------------- > P.C. Venkatesh > Office of Prudential Supervision & Risk Analysis > Division of Trading and Markets, SEC > Station Place, 100 F Street, N.E., Washington, D.C. 20549 > > e-mail: [hidden email] > vox: 202 551 5549 > fax: 202 772-9273 . > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > QuantLib-users mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-users -- Klaus Spanderen Ludwig Erhard Str. 12 48734 Reken (Germany) EMail: [hidden email] (remove NOSPAM from the address) ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |