|
From: Ioannis R. <qua...@de...> - 2023-09-10 18:17:47
|
I think, I understand now your confusion regarding the usage of Ito lemma. The mean m = ln(S(0)) + mu*t - 0.5*sigma^2*t is the mean of ln(S(t)) at time t. Formally, m := ||ln(S(t))|| = ln(S(0)) + mu*t - 0.5*sigma^2*t , where ||x|| denotes the mean of the random variable x. But, due to Ito again, the above implies: m' := ||S(t)|| = S(0)*exp(mu*t) which means the mean m' of S(t) does not contain the "Ito term" 0.5*sigma^2*t. When investigating the 68.27% rule, we always look in a normally distributed variable, in this case the ln(S(t)), which is centered around m (not around m'). But when we speak in terms of S(t) - rather than of ln(S(t)) - the distribution of S(t) is centered around m', which indeed does not involve the Ito term. I guess, many practitioners prefer to refer to S(t) rather than to ln(S(t)) and therefore also refer to the 1SD double-side interval around m', giving the impression that the Ito term is not present. But if one needs to calculate the precise min and max values of the 1SD double-side interval in the S(t) space, one should use: min of S(t) = m'*exp(mu*t - 0.5*sigma^2*t - sigma*t¹ᐟ²) max of S(t) = m'*exp(mu*t - 0.5*sigma^2*t + sigma*t¹ᐟ²) The above expressions reintroduce the Ito term. Ioannis On 9/10/2023 7:29 PM, Ioannis Rigopoulos wrote: > > Yes, I mean mu * t - 0.5 * sigma * sigma * t > > Are you sure, you also adjusted the boundaries corresponding to plus > and minus 1 SD? > > I ran an Excel spreadsheet by modifying a spreadsheet I had published > several years ago at > https://blog.deriscope.com/index.php/en/excel-value-at-risk that uses > the GeometricBrownianMotionProcess , albeit with the > PseudoRandom::rsg_type generator. > > At any case, I got convergence to 68.27% as I increased the number of > time steps and keeping the number of simulations fixed to 100,000, > provided I used the correct (Ito-adjusted) means, as below: > > As you see above, the "No Ito-adjusted" boundaries are 74.08 and > 134.99, just like those you use. > > The Ito-adjusted boundaries are 70.82 and 129.05 produced by shifting > the no-adjusted boundaries - in log terms - to the left by 0.5*sigma^2*t. > > The simulation results (percentage of values being within the min and > max boundaries) are below: > > As you see, the Ito-adjusted percentage reaches 68.30% for 100,000 > time steps, which is close to the expected 68.27%. > > The No Ito-adjusted percentage seems instead to converge to a > different value around 67.73% > > On a different topic, I do not understand your statement "/I've never > seen that Sx@-1SD and Sx@+1SD get computed with Ito's lemma applied/". > > What do the Sx@-1SD and Sx@+1SD mean? I suppose m -1SD and m +1SD, > where m is the mean of a normally distributed variable. This means > that one needs to calculate m in order to do the mentioned computation. > > If your starting point is an SDE like dS = S*mu*dt + S*sigma*dw, then > ln(S(t)) at any time t will be normally distributed with mean m = > ln(S(0)) + mu*t - 0.5*sigma^2*t , where the last term is a consequence > of the Ito lemma. > > Do you have any reason to believe that the Ito lemma is somehow not > valid so that m = ln(S(0)) + mu*t? > > Ioannis > > On 9/10/2023 3:00 PM, U.Mutlu wrote: > >> Ioannis Rigopoulos wrote on 09/10/23 13:06: >> > new GeometricBrownianMotionProcess(S, mu - 0.5*sigma^2*t, sigma) >> >> Thank you for your analysis. >> I guess you mean "mu * t - 0.5 * sigma * sigma * t", >> though in our example with t=1 it doesn't make any difference. >> It gives for timeSteps=1 this result: >> >> $ ./Testing_GBM_of_QuantLib.exe 1 >> timeSteps=1 nRuns=1000000 seed=1694350548 S=100.000000 mu=0.000000 >> sigma=0.300000 t=1.000000 : nGenAll=1000000 USE_ITO=1 : >> -1SD=70.822035 +1SD=129.046162 >> cHit=663067/1000000(66.307%) >> >> This is far from the expected value of 68.2689% for timeStep=1. >> So, there must be a bug somewhere. IMO it's our suspect friend Ito :-) >> >> Cf. also the following showing similar results for GBM, >> which then was compared to the standard lognormal calculation: >> https://www.elitetrader.com/et/threads/simulating-stock-prices-using-gbm.375533/page-3#post-5849548 >> >> >> And, honestly, I've never seen that Sx@-1SD and Sx@+1SD get computed >> with Ito's lemma applied. >> >> >> Ioannis Rigopoulos wrote on 09/10/23 13:06: >>> Thank you for testing the BoxMullerGaussianRng code, which - as I >>> wrote - does >>> not seem to be used in other areas of the standard part of QuantLib. >>> >>> Your numerical results below ... >>> >>> indicate that the simulated values for ln(S(t)) produced with >>> timeSteps = 1 >>> are very likely normally distributed with mean (I use your notation) >>> ln(S(0)) >>> + mu*t and standard deviation sigma * sqrt(t) >>> >>> This result _*is consistent*_ with: >>> >>> a) the SDE: dS(t) = S(t)*mu*dt + S(t)*sigma*dw >>> >>> _*and*_ >>> >>> b) the fact that in QuantLib the PathGenerator.next().value returns >>> the result >>> of the SDE expression _*without *_applying the ITO correction >>> associated with >>> the fact that dt is not infinitesimal. >>> >>> The b) is also responsible for the lack of convergence in your >>> output towards >>> the theoretical target of 68.27% >>> >>> You would get the correct convergence if you modified your code by >>> using the >>> expressions below: >>> >>> const double m1SD = S * exp(mu * t - 0.5*sigma^2*t + sigma * >>> sqrt(t) * >>> -1.0); // Sx at -1SD >>> const double p1SD = S * exp(mu * t - 0.5*sigma^2*t + sigma * >>> sqrt(t) * >>> 1.0); // Sx at +1SD >>> >>> new GeometricBrownianMotionProcess(S, mu - 0.5*sigma^2*t, >>> sigma) (as >>> Peter also pointed out) >>> >>> Again, due to b) one can produce the correct simulated values of a GBM >>> diffused quantity (such as a stock price in the GBM model) by using >>> N time >>> steps, with N very large. Using N = 1 (like in your example), the >>> simulated >>> values will still be lognormally distributed (whence your good >>> result with N = >>> 1), but will be centered at a wrong mean and thus will _*fail *_to >>> represent >>> the correct values expected by the GBM SDE. >>> >>> Ioannis >>> >>> On 9/10/2023 11:29 AM, U.Mutlu wrote: >>>> As said in other posting here, after fixing the test program >>>> by skipping the first item (the initial price) in the >>>> generated sample path, BoxMullerGaussianRng now passes the said test. >>>> >>>> The bugfixed test code and the new test results can be found here: >>>> https://www.elitetrader.com/et/threads/simulating-stock-prices-using-gbm.375533/page-4#post-5861666 >>>> >>>> >>>> >>>> That important fact that the generated sample path contains >>>> not timeSteps elements but 1 + timeSteps elements needs >>>> to be documented in the library doc. >>>> For example on this API doc page one normally would expect >>>> to find such an important information, but it's missing: >>>> https://www.quantlib.org/reference/class_quant_lib_1_1_path_generator.html >>>> >>>> >>>> If you or someone else can change/extend the test program by using >>>> the suggested alternative(s) to BoxMullerGaussianRng, I would be happy >>>> to hear about it. Thx. >>>> >>>> >>>> Ioannis Rigopoulos wrote on 09/09/23 16:28: >>>>> If you search within the QuantLib code for BoxMullerGaussianRng, >>>>> you will see >>>>> it is used only in the experimental folder. It is therefore not >>>>> surprising if >>>>> it doesn't produce the expected results. >>>>> >>>>> I use myself the MultiPathGenerator with PseudoRandom::rsg_type, >>>>> which is used >>>>> extensively in other areas of QuantLib. >>>>> >>>>> This type expands to InverseCumulativeRsg< RandomSequenceGenerator< >>>>> MersenneTwisterUniformRng > , InverseCumulativeNormal > and gives >>>>> me good >>>>> results. >>>>> >>>>> Ioannis Rigopoulos, founder of deriscope.com >> > > <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> > Virus-free.www.avast.com > <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> > > > <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> > > > _______________________________________________ > QuantLib-users mailing list > Qua...@li... > https://lists.sourceforge.net/lists/listinfo/quantlib-users -- This email has been checked for viruses by Avast antivirus software. www.avast.com |