Serving the Quantitative Finance Community

 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 14th, 2023, 6:56 pm

Friends, I have calculated 2D hermite-series but I have not been able to graph it with change of variable from bivariate normal. Unless we compare graph from our hermite series with 2D Parzen density graaph, we cannot be sure if our analytics are right. It can still take 2-3 days to properly complete the work and I am working on it full time.
I had an antipsychotic injection on Thursday before last Thursday. I have not been able to work well after that and could work only 1-2 hours everyday. But I am somewhat better now and hopefully would get the remaining work done in a few days.
Microwave torture has somewhat deceased but when I try to work and become somewhat productive, they increase their torture and start giving me light pain in left temple. Though many times it is not very high pain but it is still enough to put me off to not be able to work after that. Another new torture technique they have started is that they target EM waves on my teeth and from time to time, I feel sudden pain in many of my teeth.
Anyway, I hope to try to do good research in coming weeks and want to concentrate on my research.
.
Friends, I am sure my 2D Hermite Series is right. I am thinking more about proper plotting of the 2D density from the 2D Hermite Series. If the plotting works, that is good but even if it does not work, I will post the program on this weekend. 
I think a proper implementation of this program to represent a 2D SV density with a 2D hermite series is a requirement before we could do a regression of derivatives payoff on the asset and volatility as in delta and vega while accounting for correlations. 
Though I said in my previous post that we could do a regression of payoffs on delta and vega using Legendre polynomials but regression is forward looking(as opposed to backward looking equations) and rethinking the whole thing, I realize that we would have to do it in hermite polynomial set up in a monte carlo framework.
Though I am sure that there are many insights to be gained from possible solution of backward equations with Legendre polynomials, what we are trying to do in 2D SV set up with hermite polynomials is also truly meaningful and could lead to insightful hedging of the derivatives differently from the previously used approaches. Imagine if we could do it well in a good interest rate model and do a multivariate regression on various interest rates/LIBOR rates, it will be a very very rewarding model in terms of practical applications.
I was losing some enthusiasm for the project but I am again very keen to find a proper solution to the problem of 2D hermite representation of asset in a 2D SV setting in a very good way. 
I will be posting an interim program over the weekend but I will continue my efforts for a proper solution in every way for next week and more. 
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 14th, 2023, 9:29 pm

Friends, I have tried to think more about the problem in my calculation of 2D hermite representation of 2D SV SDEs. I think I have realized the error. I will try to give friends some idea about the calculations.
We need a 2D Parzen numerically calculated density of volatility and asset on an equidistant square grid. Volatility is one dimensional and can easily be mapped on one dimensional standard normal density. However asset lines cannot be independently mapped on an independent standard normal density. Instead every asset line on different volatility grid points have their own CDF and hence a different mapping on standard normal density.
if m is index for volatility and n is index for asset, V can be mapped as  [$]V(Z_m)[$]. But X lines can be mapped only as [$]X(Z_{n,m})[$] with two dimensional indexing (Zs being different for V and X).
I was earlier naively calculating a single mapping of X on Z using average CDF which was very incorrect. This CDF will be different for every X line associated with different volatility points. 
I am sure after accounting for this error, I will get a correct two dimensional Z-series/Hermite Series since basic math is simple. But I still foresee that I will have to make some improvisations for proper 3D graphing.
Though I have been working on the problem for more than one week, I have not been able to think very deeply for longer time on it since mind control agents cause strong pain in my left temple every time I try to work on the problem or think deeply about it. Even now they were trying to do the same and caused huge almost unbearable pain in my left temple but I realized that this pain has something to do with the ears and I washed my ears(especially left ear) very carefully and then put a compressed tissue in my left ear to de-calibrate(change the propeties of) the EM waves going into the ears and I was able to think better.
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 15th, 2023, 7:14 pm

Friends, I have been able to verify that my calculation of 2D Hermite Series representation of 2D SV monte carlo density is correct. I calculated the coefficients of 2D Hermite Series from the 2D Parzen monte carlo density using algorithm similar to what I had used for calculation of coefficients of 1D Hermite Series(with inner product). 
The calculated 2D hermite series is a 2D polynomial in standard normals Zx and Zv. In order to verify that my 2D hermite series coefficients are good, I integrated 2D Series over Zv and also made an appropriate normalization with integral of SV density. And then I got the result as a marginal 1D Hermite series in Zx. When I plotted this analytic 1D Hermite Series density of asset and compared it with numerical 1D Parzen density of the SV asset, both densities were exactly the same on the overlaid graph. So I can confirm that original 2D Hermite density calculations algorithm is perfectly good.
I will post my matlab programs I used to do this over the weekend.
Here is an overlaid graph from one of the examples I ran over my computer. Green is numerical parzen density of asset in SV setting while blue is marginal density of SV asset calculated from 2D hermite series  that is in turn derived from 2D monte carlo density using inner product. These are just initial graphs and I did not use very large number of monte carlo paths since my computer is too slow.

Image


I had the idea of graphing SV asset density after calculation of marginal density to check whether my 2D Hermite series is right. But in next few days I will continue to work on a 2D graph of the SV Asset density as a function of both asset and volatility. I hope that I will have a program ready that grapsh 2D density early next week.

Here are parameters of SV SDEs in appropriate mean reverting SDEs for asset and volatility.

X0=1.0;
alpha1=0;
alpha2=1;
kappaX=0.0;
thetaX=0.0;
a=kappaX*thetaX;
b=-kappaX;
rho=0.15;
sigma1=.4;
gammaV=.5;
gammaX=.65;
%%%%%%%%%%%%%
V0=1.0;
thetaV=1.0;
kappaV=1.50;
mu1=kappaV*thetaV;
mu2=-kappaV;
beta1=0;
beta2=1;
gamma=.85;
sigma0=.75;
%%%%%%%%%%%%

dt=.03125;
Tt=32*4;

T=Tt*dt;
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 15th, 2023, 7:55 pm

Friends, sorry. I tried high negative correlation and the program does not seem to work very well with high negative correlations. I still suspect that my Z-series is right but I will have to be careful with integrating over Zv to get marginal density of asset. Anyway, I am working to fix all the different 1D and 2D graphing and other related issues. 
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 16th, 2023, 8:29 pm

Friends, my program does not work for correlated SV models but I still hope to post it tomorrow for uncorrelated SV models.
I have been thinking of several alternatives for example calculating correlations numerically between various Zs and similar other ideas.
Here I want to tell friends that my first approach to solve 2D SV problem was not through inner product of 2D Hermite polynomials with parzen density. I thought I could do it by matching moments within a 2D Hermite series framework but when I closely approached the problem, I faced many difficulties. Today when I was reviewing various possibilities, and wrote down equations, I realized that analytic matching of moments in a 2D Series framework could be possible and some problems that deterred me earlier could be resolved. 
In order to understand, there are probably 65 or so terms in a 2D hermite series. Each volatility hermite polynomial multiplies with an expression of eight terms that are various hermite polynomials in X. Briefly, I want to take every order of hermite polynomial in volatility Z one by one and match moments of (the combined expression including new orthogonal Z's)sum of  all the Zx hermite polynomials multiplying that particular volatility related hermite. So there would be roughly seven or eight moment matchings in the basic model (in addition to some others) to advance one time step.
I am reasonably sure that this should work well. I want to try it again in next 2-3 days. But only when we get good results that we could know that it actually does work.
There is a benefit to matching moments because in the simulation equation noise generating Z's even in correlated SV models are uncorrelated on the individual variable level so dealing with correlations should be no more difficult if the method works.
Let us see how it goes in next few days.
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 17th, 2023, 9:34 pm

I will give a detailed review with latexed equations tomorrow. In the meanwhile matlab programs to calculate 2D hermite series from 2D SV monte carlo constructed parzen density are given below. I have tried to give comments on the main programs to make it easier for friends who are reasonably familiar with the background to understand the programs. 

Volatility and asset equations are
Vt(0)=V0;
dVt=(mu1*Vt^beta1 + mu2*Vt^beta2)*dt+sigma0 * Vt^gamma * dz1(t)
Xt(0)=X0
dXt=(a*Xt^alpha1+b*Xt^alpha2)*dt+sigma1* Vt^gammaV * Xt^gammaX *dz2(t);

First a graphical comparison of non-correlated-IR like SV equations with mean reversion both in asset and volatility. Programs used to make above graph follow in next post in a few minutes.

Parameters of the density as given in above equations are
X0=.05;
alpha1=0;
alpha2=1;
kappaX=.850;
thetaX=0.0250;
a=kappaX*thetaX;
b=-kappaX;
rho=-0.0;
sigma1=.8;
gammaV=.5;
gammaX=.7;
%%%%%%%%%%%%%
V0=1.0;
thetaV=.250;
kappaV=1.50;
mu1=kappaV*thetaV;
mu2=-kappaV;
beta1=0;
beta2=1;
gamma=.85;
sigma0=.7;
%%%%%%%%%%%%
dt=.03125;
Tt=32*4;
T=Tt*dt;


Here is the graph of the analytic density calculated from the 2D Hermite series of the SV asset by integrating over volatility to calculate the marginal 1D Hermite series of the asset.
There is a very slight mismatch between graphs at peak of the density but this is initial prototype and we will have to work to refine the method to perfection. Playing around with number of paths, grid spacing and related parameters might help in better reconciling both graphs.

Image
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 17th, 2023, 9:43 pm

Here are the matlab functions for method used to construct graphs in previous post.
I will explain tomorrow but quickly
If C are 2D hermite Coeffs as calculated in this program
Hermite Series representation of 2D random variable would be given by
double sum equation below as 

[$]\sum_{n=0}^{n=7} \sum_{m=0}^{m=7} \, C(n+1,m+1) \, He(n,Zx) \, He(m,Zv)[$]

mismatch between hermite indices and indices in C is due to that matlab starts indices from one and not from zero. This is for C as calculated in the current program.

.
function [] = SVMonteCarloDensityWith2DHermitesWilmott()

%Copyright Ahsan Amin. Infiniti derivatives Technologies.
%Please fell free to connect on linkedin: linkedin.com/in/ahsan-amin-0a53334 

%Volatility and asset equations are
%Vt(0)=V0;
%dVt=(mu1*Vt^beta1 + mu2*Vt^beta2)*dt+sigma0 * Vt^gamma * dz1(t)
%Xt(0)=X0
%dXt=(a*Xt^alpha1+b*Xt^alpha2)*dt+sigma1* Vt^gammaV * Xt^gammaX *dz2(t);
%<dz1(t),dz2(t)>=rho *dt

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

X0=.05;
alpha1=0;
alpha2=1;
kappaX=.850;
thetaX=0.0250;
a=kappaX*thetaX;
b=-kappaX;

rho=-0.0;
sigma1=.8;
gammaV=.5;
gammaX=.7;
%%%%%%%%%%%%%
V0=1.0;
thetaV=.250;
kappaV=1.50;
mu1=kappaV*thetaV;
mu2=-kappaV;
beta1=0;
beta2=1;
gamma=.85;
sigma0=.7;
%%%%%%%%%%%%

dt=.03125;
Tt=32*4;

T=Tt*dt;


%%%%%%%%%%%%%%%%%%%%%%%%5

%rng(29079137, 'twister')
rng(15898837, 'twister')
paths=600000;
V(1:paths)=V0;  %Original process monte carlo.
X(1:paths)=X0;
Random1(1:paths)=0;
Random2(1:paths)=0;

for tt=1:Tt
Random1=randn(size(Random1));
Random2=randn(size(Random2));


X(1:paths)=X(1:paths)+ ...
    (a* X(1:paths).^alpha1 + b* X(1:paths).^alpha2)* dt + ...
    sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*Random1(1:paths) * sqrt(dt) + ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*Random2(1:paths)*sqrt(dt) + ...
    (a*alpha1* X(1:paths).^(alpha1-1)+b*alpha2* X(1:paths).^(alpha2-1)).* ...
    (((a* X(1:paths).^alpha1 + b* X(1:paths).^alpha2)* dt^2/2)+ ...
    (sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*Random1(1:paths) *(1-1/sqrt(3)).*dt^1.5+ ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*Random2(1:paths)*(1-1/sqrt(3)).*dt^1.5))+ ...
    .5*(a*alpha1*(alpha1-1)* X(1:paths).^(alpha1-2)+b*alpha2*(alpha2-1).* X(1:paths).^(alpha2-2)).* ...
    ( sigma1^2* V(1:paths).^(2*gammaV).* X(1:paths).^(2*gammaX)) *dt^2/2 + ...
    sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.*gammaX.* X(1:paths).^(gammaX-1).* ...
    ((a* X(1:paths).^alpha1 + b* X(1:paths).^alpha2).*Random1(1:paths) * 1/sqrt(3).* dt^1.5 + ...
    sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*(Random1(1:paths).^2-1) * dt/2 + ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*Random1(1:paths).*Random2(1:paths)*dt/2)+ ...
    .5*sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.*gammaX.*(gammaX-1).* X(1:paths).^(gammaX-2).* ...
    (sigma1^2* V(1:paths).^(2*gammaV).* X(1:paths).^(2*gammaX) .*Random1(1:paths).*1/sqrt(3).*dt^1.5)+ ...
    sqrt(1-rho^2)* sigma1*gammaV.* V(1:paths).^(gammaV-1).* X(1:paths).^(gammaX).* ...
    ((mu1.*V(1:paths).^beta1 + mu2.*V(1:paths).^beta2).*Random1(1:paths) * 1/sqrt(3).* dt^1.5 + ...
    sigma0*V(1:paths).^gamma.*Random1(1:paths).*Random2(1:paths)*dt/2)+ ...
    .5*sqrt(1-rho^2)* sigma1*gammaV.*(gammaV-1).* V(1:paths).^(gammaV-2).* X(1:paths).^(gammaX).* ...
    (sigma0^2*V(1:paths).^(2*gamma).*Random1(1:paths)*1/sqrt(3)*dt^1.5)+ ...
    sqrt(1-rho^2)* sigma1*gammaV.* V(1:paths).^(gammaV-1).*gammaX.* X(1:paths).^(gammaX-1).* ...
    rho.* sigma1.* V(1:paths).^gammaV .*X(1:paths).^gammaX .*sigma0.*V(1:paths).^gamma.*Random1(1:paths)*1/sqrt(3)*dt^1.5+ ...
    rho* sigma1* V(1:paths).^gammaV.*gammaX.* X(1:paths).^(gammaX-1).* ...
    ((a* X(1:paths).^alpha1 + b* X(1:paths).^alpha2).*Random2(1:paths) * 1/sqrt(3).* dt^1.5 + ...
    sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*Random1(1:paths).*Random2(1:paths) * dt/2 + ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*(Random2(1:paths).^2-1)*dt/2)+ ...
    .5*rho* sigma1* V(1:paths).^gammaV.*gammaX.*(gammaX-1).* X(1:paths).^(gammaX-2).* ...
    (sigma1^2* V(1:paths).^(2*gammaV).* X(1:paths).^(2*gammaX) .*Random2(1:paths).*1/sqrt(3).*dt^1.5)+ ...
    rho* sigma1*gammaV.* V(1:paths).^(gammaV-1).* X(1:paths).^(gammaX).* ...
    ((mu1.*V(1:paths).^beta1 + mu2.*V(1:paths).^beta2).*Random2(1:paths) * 1/sqrt(3).* dt^1.5 + ...
    sigma0*V(1:paths).^gamma.*(Random2(1:paths).^2-1)*dt/2)+ ...
    .5*rho* sigma1*gammaV.*(gammaV-1).* V(1:paths).^(gammaV-2).* X(1:paths).^(gammaX).* ...
    sigma0^2.*V(1:paths).^(2*gamma).*Random2(1:paths) * 1/sqrt(3).* dt^1.5+ ...
    rho* sigma1*gammaV.* V(1:paths).^(gammaV-1).*gammaX.* X(1:paths).^(gammaX-1).* ...
    rho.* sigma1.* V(1:paths).^gammaV .*X(1:paths).^gammaX .*sigma0.*V(1:paths).^gamma.*Random2(1:paths)*1/sqrt(3)*dt^1.5;
    

    V(1:paths)=V(1:paths)+ ...
        (mu1.*V(1:paths).^beta1 + mu2.*V(1:paths).^beta2)*dt + ...
        sigma0*V(1:paths).^gamma .*Random2(1:paths)*sqrt(dt) + ...
        (mu1.*beta1*V(1:paths).^(beta1-1) + mu2.*beta2.*V(1:paths).^(beta2-1)).* ...
        ((mu1.*V(1:paths).^beta1 + mu2.*V(1:paths).^beta2)*dt^2/2 + ...
        sigma0*V(1:paths).^gamma .*Random2(1:paths)*(1-1/sqrt(3))*dt^1.5) + ...
        .5*(mu1.*beta1.*(beta1-1).*V(1:paths).^(beta1-2) + mu2.*beta2.*(beta2-1).*V(1:paths).^(beta2-2)).* ...    
        sigma0^2.*V(1:paths).^(2*gamma).*dt^2/2 + ...
        sigma0*gamma*V(1:paths).^(gamma-1) .* ...
        ((mu1.*V(1:paths).^beta1 + mu2.*V(1:paths).^beta2).*Random2(1:paths).*1/sqrt(3)*dt^1.5 + ...
        sigma0.*V(1:paths).^gamma .*(Random2(1:paths).^2-1)*dt/2) + ...
        .5*sigma0*gamma*(gamma-1).*V(1:paths).^(gamma-2) .* ...
        sigma0^2.*V(1:paths).^(2*gamma) .*Random2(1:paths).*1/sqrt(3)*dt^1.5;


end

X=real(X);
X(X<0)=0;
V(V<0)=0;


SVolMeanAnalytic=thetaV+exp(-kappaV*T)*(V0-thetaV)
SVolMean=sum(V(1:paths))/paths
AssetMeanAnalytic=thetaX+exp(-kappaX*T)*(X0-thetaX)
AssetMean=sum(X(1:paths))/paths

str=input("Look at monte carlo Mean of X and V")

NoOfBinsV=200;
NoOfBinsX=200;

[XYProbDensity2D,XYProbMass2D,XProbMass,VProbMass,IndexMaxX,IndexMaxV,Xn,Vm,Zx,Zv]= Find2DDensityAndCDFFromSimulation_Infiniti(X,V,paths,NoOfBinsX,NoOfBinsV);
%Please look at matlab file of above function for etailed explanation of
%all its input and output parameters.

str=input("Look at sizes of variables----1")

surf(Xn,Vm,XYProbDensity2D)

%hold on

MeanX=sum(X(1:paths))/paths
MeanV=sum(V(1:paths))/paths

str=input("Look at 3D graphs")


%Below calculate Coeffs of 2D Hermite products.
%Oxn is order of Zx hermites. ranges from 1 to 8 in indexing or (0 to 7 in reality)
%Ovm is order of Zv hermites. ranges from 1 to 8 in indexing or (0 to 7 in reality)
%HermiteH(Oxn,Zx(nn,mm)) is a small function that caclulates Oxn order hermite at Zx(nn,mm) value
%HermiteH(Ovm,Zv(mm)) caclulates Ovm order hermite at Zy(mm) value
%Below Eq calculates 2D Coeffs with inner product of coordinates of 2D uniform grid with 
%product of X and V hermites.


C(1:8,1:8)=0;

for Oxn=1:8
    for Ovm=1:8
        for nn=1:(NoOfBinsX+1)
            for mm=1:(NoOfBinsV+1)
                C(Oxn,Ovm)=C(Oxn,Ovm)+1/factorial(Oxn-1)/factorial(Ovm-1).*Xn(nn).*Vm(mm).*HermiteH(Oxn-1,Zx(nn,mm)).*HermiteH(Ovm-1,Zv(mm)).*XYProbMass2D(nn,mm);
                
            end
        end
    end
end
        
C

%If C are 2D hermite Coeffs as calculated in above equation
%Hermite Series representation of 2D random variable would be given by
%double sum equation below as 
%Sum_{n=0}^{n=7} Sum_{m=0}^{m=7} C(n+1,m+1) He(n,Zx) He(m,Zy);

str=input("Look at Coefficients of 2D Hermite products")


%Below we calculate 1D Hermite Series for volatility.
%We only need to calculate the mean (zeroth hermite) aH0 of the volatility
%random variable.


aH0=0;
aH(1:7)=0;
for nn=1:IndexMaxV
aH0  =  aH0+Vm(nn).*VProbMass(nn);    
aH(1)=aH(1)+Vm(nn).*Zv(nn).*VProbMass(nn);
aH(2)=aH(2)+.5*Vm(nn).*(Zv(nn).^2-1).*VProbMass(nn);
aH(3)=aH(3)+1/6*Vm(nn).*(Zv(nn).^3-3*Zv(nn)).*VProbMass(nn);
aH(4)=aH(4)+1/24*Vm(nn).*(Zv(nn).^4-6*Zv(nn).^2+3).*VProbMass(nn);
aH(5)=aH(5)+1/120*Vm(nn).*(Zv(nn).^5-10*Zv(nn).^3+15*Zv(nn)).*VProbMass(nn);
aH(6)=aH(6)+1/720*Vm(nn).*(Zv(nn).^6-15*Zv(nn).^4+45*Zv(nn).^2-15).*VProbMass(nn);
aH(7)=aH(7)+1/720/7*Vm(nn).*(Zv(nn).^7-21*Zv(nn).^5+105*Zv(nn).^3-105*Zv(nn)).*VProbMass(nn);
end


%Below we calculate the Hermite series of asset by integrating over the
%volatility to get marginal series of asset. When we integrate over
%volatility, all volatility hermites(alone or as products with X-hermites)
%in the 2D asset series go to zero(they all have mean zero). 
%So basically all volatility terms go to zero and we are left with 
%one dimensional array containing terms from 2D series where 
%volatility hermites in the product had order zero. This order zero is
%represented by volatility index one in the 2d array of coeffs C(n,m);
%So our 1D asset series is from the line C(1:8,1) where volatilit hermites
%are zero. This is very interesting.

bH0=C(1,1);
bH(1:7)=C(2:8,1);

%Above bH0 is asset Hermite series coeff of zeroth order hermite and
%bH(1:7) represent hermites from 1st to 7th order.

bH0=bH0/aH0;
bH=bH/aH0;

%Above, we need to normalize the asset hermite series with expected value
%of volatility since we integrated over the volatility. Just like in
%Conditioning when we integrate over a variable to get marginal density and
%then we have to divide with the integral of the integrated density as
%well. Similalry, Here we have to divide with the mean/expected value of 
%volatility hermite series(which is integral of the volatility hermite series)
%to normalize our asset equation hermite coefficients.

%Below we convert from hermite series to Z-series of the asset for
%plotting.
[b0,b] = ConvertHCoeffsToZCoeffs(bH0,bH,7);

bH0
bH

b0
b

str=input("Look at 1D Coeffs of X")


dNn=.1;%.1/2;   % Normal density subdivisions width. would change with number of subdivisions
Nn=101;%45*4;  % No of normal density subdivisions
NnMid=((1+Nn)/2)*dNn;
Z(1:Nn)=(((1:Nn)*dNn)-NnMid);



XX(1:Nn)=b0;
for nn=1:7
   XX(1:Nn)=XX(1:Nn)+b(nn)*Z(1:Nn).^nn;
end

wnStart=1;
%Below we make calculations of density in original coordinates by doing 
%change of probability derivative with respect to gaussian density.
DfXX(wnStart:Nn)=0;
for nn=wnStart+1:Nn-1
    
    DfXX(nn) = (XX(nn + 1) - XX(nn - 1))/(Z(nn + 1) - Z(nn - 1));
    
    %Change of variable derivative for densities
end
DfXX(Nn)=DfXX(Nn-1);
DfXX(1)=DfXX(2);


pXX(1:Nn)=0;
for nn = wnStart:Nn
    
    pXX(nn) = (normpdf(Z(nn),0, 1))/abs(DfXX(nn));
end



%Below make parzen density of asset in SV equations and also plot the
%analytic density of asset.
 NoOfBins=2400;
 MaxCutOff=100;
  
 [XDensity,IndexOutX,IndexMaxX] = MakeDensityFromSimulation_Infiniti_NEW(X,paths,NoOfBins,MaxCutOff );
 plot(XX(2:Nn-1),pXX(2:Nn-1),'b',IndexOutX(1:IndexMaxX),XDensity(1:IndexMaxX),'g');

title('Asset Density(in SV model) From Analytic Hermite Series Calculated from 2D Hermite Series VS Numerical Parzen Density of Asset');%,sprintf('theta= %f', theta), sprintf('kappa = %f', kappa),sprintf('sigma = %f', sigma0),sprintf('T = %f', T));
 
legend({'Marginal Asset Density from 2D Hermite Series','Parzen Density From Monte Carlo'},'Location','northeast')

str=input('blue line is density of Asset from Hermite Series, green is numerical density from monte carlo.');




end
.
.
.
function [XYProbDensity2D,XYProbMass2D,XProbMass,YProbMass,IndexMaxX,IndexMaxY,Xn,Ym,Zx,Zy] = Find2DDensityAndCDFFromSimulation_Infiniti(X,Y,Paths,NoOfBinsX,NoOfBinsY)

%This function processes joint observations of two stochastic variables X and Y from 
%common monte carlo paths and makes a two dimensional density of X and Y.

%Explanation of Input Parameters
%X and Y are 1D arrays so that nth element of each makes a joint 
%observation of nth monte carlo path X(n) and Y(n) form joint nth observation of two stochastic variables.
%paths ---- total monte carlo paths.
%NoOfBinsX ---- Uniform Grid size in X for density construction. You can alter
%this. But you will have to make sure to alter grid sizes in main program after
%this function has returned results.
%NoOfBinsY ---- Uniform Grid size in Y for density construction. You can alter
%this.

%Explanation of output Parameters
%XYProbDensity2D --- is 2D numerically constructed Parzen density on input
%grid in X and Y.
%XYProbMass2D, ------ is integrated version of 2D parzen density that gives
%two D probability mass on input grid in X and Y.
%XProbMass  ---- is probability mass of 1D marginal density in X on NoOfBinsX Grid.
%YProbMass  ---- is probability mass of 1D marginal density in Y on NoOfBinsY Grid.
%IndexMaxX ----- This is size of grid in X and corresponds to NoOfBinsX and
%is NoOfBinsX+1. Naturally This is also size of array that returns
%X-values on the X-axis of 2D uniform grid.
%IndexMaxY ----- This is size of grid in X and corresponds to NoOfBinsY and
%is  NoOfBinsY+1. Naturally This is also size of array that returns
%Y-values on Y-axis of the 2D uniform grid.
%Xn--- is an array of size IndexMaxX that contains values of X at the
%center of each grid cell on X-axis on 2D uniform grid.
%Ym--- is an array of size IndexMaxY that contains values of Y at the
%center of each grid cell on Y-axis on 2D uniform grid.
%Zx----- this is a 2D array. This returns the value of standard normal associated with 1D Xn grid for every
%Ym grid cell. Given a certain grid cell Ym, we calculate CDF along all 1D X grid
%cells with the same Ym. This standard normal value is derived from inversion of univariate CDF on X-grid
%or X-axis associated with each Y grid cell. Zx(n,m) is a 2D array.
%Zy----- this is the value of standard normal associated with Ym at center
%of each grid cell on Y-axis. This is derived from inversion of univariate CDF on Y-grid
%or Y-axis. This is 1D array. This is used for vol which is independent of
%X.

Xmin=999999;
Xmin1=999999;
Xmin2=999999;
Xmax=0;
Xmax1=0;
Xmax2=0;

Ymin=999999;
Ymin1=999999;
Ymin2=999999;
Ymax=0;
Ymax1=0;
Ymax2=0;
meanX=0;
meanY=0;
for p=1:Paths

meanX=meanX+X(p)/Paths;
meanY=meanY+Y(p)/Paths;
if(Xmin>real(X(p)))
    Xmin2=Xmin1;
    Xmin1=Xmin;
    Xmin=real(X(p));
end
if(Xmax<real(X(p)))
    Xmax2=Xmax1;
    Xmax1=Xmax;
    Xmax=real(X(p));
end

if(Ymin>real(Y(p)))
    Ymin2=Ymin1;
    Ymin1=Ymin;
    Ymin=real(Y(p));
end
if(Ymax<real(Y(p)))
    Ymax2=Ymax1;
    Ymax1=Ymax;
    Ymax=real(Y(p));
end
end


%Xmin
%Xmin1
%Xmin2

%Xmax
%Xmax1
%Xmax2
%str=input('Look at Xmin and Xmax');
%IndexMax=NoOfBins+1;
BinSizeX=(Xmax2-Xmin2)/NoOfBinsX;
BinSizeY=(Ymax2-Ymin2)/NoOfBinsY;
%IndexMax=floor((Xmax-Xmin)/BinSize+.5)+1
IndexMaxX=floor((Xmax2-Xmin2)/BinSizeX+.5)+1
IndexMaxY=floor((Ymax2-Ymin2)/BinSizeY+.5)+1

Xn(1:IndexMaxX)=Xmin2+(0:(IndexMaxX-1))*BinSizeX;
Ym(1:IndexMaxY)=Ymin2+(0:(IndexMaxY-1))*BinSizeY;

XYProbMass2D(1:IndexMaxX,1:IndexMaxY)=0.0;
XYProbDensity2D(1:IndexMaxX,1:IndexMaxY)=0.0;
XProbMass(1:IndexMaxX)=0;
YProbMass(1:IndexMaxY)=0;

for p=1:Paths
indexX=real(floor(real(X(p)-Xmin2)/BinSizeX+.5)+1);
%indexXp=real(X(p)-Xmin2)/BinSizeX+1;


if(real(indexX)<1)
indexX=1;
end
if(real(indexX)>IndexMaxX)
indexX=IndexMaxX;
end


indexY=real(floor(real(Y(p)-Ymin2)/BinSizeY+.5)+1);
%indexYp=real(Y(p)-Ymin2)/BinSizeY;

if(real(indexY)<1)
indexY=1;
end
if(real(indexY)>IndexMaxY)
indexY=IndexMaxY;
end



%XDensity(index)=XDensity(index)+1.0/Paths/BinSize;
XProbMass(indexX)=XProbMass(indexX)+1.0/Paths;
YProbMass(indexY)=YProbMass(indexY)+1.0/Paths;
XYProbMass2D(indexX,indexY)=XYProbMass2D(indexX,indexY)+1.0/Paths;
XYProbDensity2D(indexX,indexY)=XYProbDensity2D(indexX,indexY)+1.0/Paths/BinSizeX/BinSizeY;


end

%BinSizeX
%BinSizeY

%str=input("Look at BinSizes");

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
%Below calculate Zx by inversion of 1D X-CDF associated with each volatility grid cell
%so that resulting array is 2D.
XProbSum(1:IndexMaxX,1:IndexMaxY)=0;
XCDF(1:IndexMaxX,1:IndexMaxY)=0;
Zx(1:IndexMaxX,1:IndexMaxY)=0;

for mm=1:IndexMaxY
    XProbSum(1,mm)=XYProbMass2D(1,mm)*.5;
    if(YProbMass(mm)>0)
        XCDF(1,mm)=XProbSum(1,mm)./YProbMass(mm);
        
    else
        XCDF(1,mm)=0;
    end
    if((XCDF(1,mm)>0) && (XCDF(1,mm)<1))
        Zx(1,mm)=norminv(XCDF(1,mm));
    elseif (XCDF(1,mm)<.0000001)
        Zx(1,mm)=-8;
    elseif (XCDF(1,mm)>.9999999)
        Zx(1,mm)=8;
    end
    for nn=2:IndexMaxX
        XProbSum(nn,mm)=XProbSum(nn-1,mm)+XYProbMass2D(nn-1,mm)*.5+XYProbMass2D(nn,mm)*.5;
        if(YProbMass(mm)>0)
            XCDF(nn,mm)=XProbSum(nn,mm)./YProbMass(mm);
        else
            XCDF(nn,mm)=0;
        end
        if((XCDF(nn,mm)>0) && (XCDF(nn,mm)<1))
            Zx(nn,mm)=norminv(XCDF(nn,mm));
        elseif (XCDF(nn,mm)<.0000001)
            Zx(nn,mm)=-8;
        elseif (XCDF(nn,mm)>.9999999)
            Zx(nn,mm)=8;
        end
    end
end
    
    

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



YCDF(1:IndexMaxY)=0;
Zy(1:IndexMaxY)=0;
YCDF(1)=YProbMass(1)*.5;
Zy(1)=norminv(YCDF(1));
for nn=2:IndexMaxY
    YCDF(nn)=YCDF(nn-1)+YProbMass(nn-1)*.5+YProbMass(nn)*.5;
    Zy(nn)=norminv(YCDF(nn));
end

end
.
.
function [a0,a] = ConvertHCoeffsToZCoeffs(aH0,aH,SeriesOrder)


if(SeriesOrder==3)
a0=aH0-aH(2);
a(1)=aH(1)-3*aH(3);
a(2)=aH(2);
a(3)=aH(3);
end

if(SeriesOrder==4)
a0=aH0-aH(2)+3*aH(4);
a(1)=aH(1)-3*aH(3);
a(2)=aH(2)-6*aH(4);
a(3)=aH(3);
a(4)=aH(4);
end

if(SeriesOrder==5)
a0=aH0-aH(2)+3*aH(4);
a(1)=aH(1)-3*aH(3)+15*aH(5);
a(2)=aH(2)-6*aH(4);
a(3)=aH(3)-10*aH(5);
a(4)=aH(4);
a(5)=aH(5);
end

if(SeriesOrder==5)
a0=aH0-aH(2)+3*aH(4);
a(1)=aH(1)-3*aH(3)+15*aH(5);
a(2)=aH(2)-6*aH(4);
a(3)=aH(3)-10*aH(5);
a(4)=aH(4);
a(5)=aH(5);
end
% if(SeriesOrder==5)
% a0=aH0-aH(2)-3*aH(4);
% a(1)=aH(1)-3*aH(3)-15*aH(5);
% a(2)=aH(2)-6*aH(4);
% a(3)=aH(3)-10*aH(5);
% a(4)=aH(4);
% a(5)=aH(5);
% end
if(SeriesOrder==6)
a0=aH0-aH(2)+3*aH(4)-15*aH(6);
a(1)=aH(1)-3*aH(3)+15*aH(5);
a(2)=aH(2)-6*aH(4)+45*aH(6);
a(3)=aH(3)-10*aH(5);
a(4)=aH(4)-15*aH(6);
a(5)=aH(5);
a(6)=aH(6);
end

if(SeriesOrder==7)
a0=aH0-aH(2)+3*aH(4)-15*aH(6);
a(1)=aH(1)-3*aH(3)+15*aH(5)-105*aH(7);
a(2)=aH(2)-6*aH(4)+45*aH(6);
a(3)=aH(3)-10*aH(5)+105*aH(7);
a(4)=aH(4)-15*aH(6);
a(5)=aH(5)-21*aH(7);
a(6)=aH(6);
a(7)=aH(7);
end


end

.
.
.
function [ValHermite] = HermiteH(n,Z)

if(n==0)
    ValHermite=1;
elseif(n==1)
    ValHermite=Z;
elseif(n==2)
    ValHermite=Z.^2-1;
elseif(n==3)
    ValHermite=Z.^3-3*Z;
elseif(n==4)
    ValHermite=Z.^4-6*Z.^2+3;
elseif(n==5)
    ValHermite=Z.^5-10*Z.^3+15*Z;
elseif(n==6)
    ValHermite=Z.^6-15*Z.^4+45*Z.^2-15; 
elseif(n==7)
    ValHermite=Z.^7-21*Z.^5+105*Z.^3-105*Z;     
end

end

.
.
.
function [XDensity,IndexOut,IndexMax] = MakeDensityFromSimulation_Infiniti_NEW(X,Paths,NoOfBins,MaxCutOff )
%Processes monte carlo paths to return a series Xdensity as a function of IndexOut. IndexMax is the maximum value of index.
% 


Xmin=10000;
Xmax=0;
for p=1:Paths
if(X(p)>MaxCutOff)
X(p)=MaxCutOff;
end
%if(X(p)<0)
%X(p)=0;
%end
if(Xmin>real(X(p)))
Xmin=real(X(p));
end
if(Xmax<real(X(p)))
Xmax=real(X(p));
end
end

%IndexMax=NoOfBins+1;
BinSize=(Xmax-Xmin)/NoOfBins;
%IndexMax=floor((Xmax-Xmin)/BinSize+.5)+1
IndexMax=floor((Xmax-Xmin)/BinSize+.5)+1

XDensity(1:IndexMax)=0.0;

for p=1:Paths
index=real(floor(real(X(p)-Xmin)/BinSize+.5)+1);
if(real(index)<1)
index=1;
end
if(real(index)>IndexMax)
index=IndexMax;
end

XDensity(index)=XDensity(index)+1.0/Paths/BinSize;

end

IndexOut(1:IndexMax)=Xmin+(0:(IndexMax-1))*BinSize;

end
.
.
.
Here is what you see when you run this program.
>> SVMonteCarloDensityWith2DHermitesWilmott
SVolMeanAnalytic =
   0.251859064132500
SVolMean =
   0.251863758906108
AssetMeanAnalytic =
   0.025834331749008
AssetMean =
   0.025815497695354
Look at monte carlo Mean of X and V
str =
     []
IndexMaxX =
   201
IndexMaxY =
   201
Look at sizes of variables----1
str =
     []
MeanX =
   0.025815497695354
MeanV =
   0.251863758906108
Look at 3D graphs
str =
     []
C =
  Columns 1 through 7
   0.006497337445425   0.003232035701479   0.000888200210853   0.000167060492319   0.000013447963356  -0.000003787882163  -0.000002707045488
   0.006103640762728   0.003760791234298   0.001271542675321   0.000248614492577  -0.000005783011101  -0.000025053419495  -0.000010537958465
   0.002688558089542   0.001844247294565   0.000667340562761   0.000105391238830  -0.000031310243646  -0.000026033438760  -0.000008058781951
   0.000737006426825   0.000471817212194   0.000127309107535  -0.000019251106172  -0.000030786964423  -0.000010776359191  -0.000000647624144
   0.000103340578135   0.000026870335121  -0.000033946738528  -0.000035927962856  -0.000015053148333  -0.000001187308493   0.000001715435407
  -0.000011263272013  -0.000031027161428  -0.000030381876777  -0.000015049249060  -0.000003237889580   0.000000864867892   0.000000820707402
  -0.000011059378227  -0.000013770321674  -0.000008316453218  -0.000001613632758   0.000000769374831   0.000000585206186   0.000000098112089
  -0.000004350446341  -0.000003026159833  -0.000000158888808   0.000001224264466   0.000000821549110   0.000000187375651  -0.000000044194121
  Column 8
  -0.000001088579833
  -0.000002348046073
  -0.000000907288553
   0.000000863981233
   0.000000851930877
   0.000000214439577
  -0.000000047398723
  -0.000000041876454
Look at Coefficients of 2D Hermite products
str =
     []
bH0 =
   0.025796952988447
bH =
   0.024233824260633   0.010674619753890   0.002926201741049   0.000410302228929  -0.000044719564136  -0.000043910026624  -0.000017272961528
b0 =
   0.017011890320703
b =
   0.016598086535875   0.006236855182237   0.001559736421978   0.001068952628289   0.000318012627951  -0.000043910026624  -0.000017272961528
Look at 1D Coeffs of X
str =
     []
IndexMax =
        2401
blue line is density of Asset from Hermite Series, green is numerical density from monte carlo.
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 18th, 2023, 11:02 am

Friends sorry that this is not the post for explanation of the previous program but a short post to describe the torture. I would like to make the explanation post now but I slept around 4:00 am and woke up at 8:45 am. I am short of sleep and need to sleep now after writing this post. Explanatory post with latex may take too longer.
Friends, for past ten days I have become target of torture again and again. They have even further increased torture for past 2-3 days. Every day they give me almost unbearable pain in left temple and other places on face and head for at least 6-7 hours. This becomes very very painful.
Sometimes they would give pain in temple and then at other times pain in teeth or ears. And at even other times they cause pain in the eyes. 
Now they are systematically using torture as a policy. I am sure this is very well thought out strategy by most of the people who always wanted to retard me. 
Again this is very difficult to pass a day when they continue to torture for 6-7 hours. For example they also continue to torture when I drop my mother for her class on my car and also in the evening when I go out in the city on the motorcycle.
Though I continue to wash my face and head and continue to wet my face and head repeatedly after short periods to decrease torture, it is still very difficult to do any work when there is extreme torture.
This noon and after that I went to a nearby park to brainstorm about the analytic evolution of 2D correlated density with addition of moments and they continue to torture me in the park but it was still far better than what I had to face in our house. The purpose of going to park was also because I expected that there would be a relatively better environment there.
Sometimes they decrease torture abruptly only to restart it with severity after an hour or two again.
I Want to request friends to please ask people in government to make sure that torture on me stops. I am committed to research work but it would be far nicer if I could do my research in a relatively more pleasant environment and I could possibly become more productive.
I have been able to work reasonably well in past few days despite the torture but it would be difficult to continue for a longer  time with 6-7 hours of intense torture everyday.
Mind control guys continue to tell me that they want me to do research for specific person in academia or industry who would control what to do with my research and they do not want me to make my research public and they assure that I would be paid decently for my research. While I really want my research to remain perfectly accessible for everyone who is interested.
I would be posting details of yesterday's program tonight. I also want to mention that I am very hopeful that we would be able to solve for 2D correlated SV problem with addition/matching of moments. Today when I was in the park, I wrote equations for it and I hope we would be able to solve the problem. But of course, we could be sure only when we have done it. Tonight I will also try to write basic equations for solution of 2D SV problem with analytic matching/addition of moments.
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 18th, 2023, 4:55 pm

Friends, I just came back to my house from going outside in the city. They continued torture on me when I was driving my bike and I had constant pain in my left temple. But that is nothing new and I have told friends several times about it. But what has made me become seriously worried is when I returned home I noticed that I was slightly losing balance for very little periods of time. I also was very disoriented and I noticed that I am also slightly forgetting/losing context of things I am doing or talking about. I was a bit more worried due to these new problems and decided to write this post to ask good American people for help before it is too late for me and there is some possible permanent damage to my brain.
I will be explaining the previous technical post in a few hours later tonight.
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 18th, 2023, 6:43 pm

Sorry friends, I am not feeling well and going to sleep. I will write explanation of technical post during the day tomorrow. Sorry about this delay.
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 19th, 2023, 7:41 am

Friends, Explaining the ideas behind the previous program.
I have previously suggested that we can represent a bivariate random variable V as a double summation in hermite polynomials as

[$]V(Z_x,Z_y) \, =\, \sum\limits_{n=0}^N \, \sum\limits_{m=0}^M \, C(n,m) \, H_n(Z_x) \, H_m(Z_y) [$]

please note that a perfectly equivalent representation(analogous to Z-series in 1D) would be 

[$]V(Z_x,Z_y) \, =\, \sum\limits_{n=0}^N \, \sum\limits_{m=0}^M \, D(n,m) \, {Z_x}^n \, {Z_y}^m [$]

where C(n,m) and D(n,m) can be converted into each other.

If [$]Z_x[$] and [$]Z_y[$] are independent of each other, we can take inner product of the bivariate variable with 2D Hermite polynomials of order n1 and m1

[$] \,  \int\limits_{Z_x=-\infty}^{\infty}  \int\limits_{Z_y=-\infty}^{\infty} V(Z_x,Z_v) \, H_{n1}(Z_x) \, H_{m1}(Z_y)\, p(Z_x,Z_y) \, dZ_x \, dZ_y[$]

We know from start that our postulated representation of [$]V(Z_x,Z_y)[$] is 
[$]V(Z_x,Z_y) \, =\, \sum\limits_{n=0}^N \, \sum\limits_{m=0}^M \, C(n,m) \, H_n(Z_x) \, H_m(Z_y) [$]

Substituting it in our previous Eq, we get

[$]\,  \int\limits_{Z_x=-\infty}^{\infty}  \int\limits_{Z_y=-\infty}^{\infty} \Big[\, \sum\limits_{n=0}^N \, \sum\limits_{m=0}^M \, C(n,m) \, H_{n}(Z_x) \, H_{m}(Z_y) \Big] \, H_{n1}(Z_x) \, H_{m1}(Z_y)\, p(Z_x,Z_y) \, dZ_x \, dZ_y[$]

Since most terms are orthogonal to each other and there is only one term where n1=n and m1=m that has a non-zero inner product. So we get from previous term

[$]\,  \int\limits_{Z_x=-\infty}^{\infty}  \int\limits_{Z_y=-\infty}^{\infty} \Big[\, \, C(n1,m1) \, H_{n1}(Z_x) \, H_{m1}(Z_y) \Big] \, H_{n1}(Z_x) \, H_{m1}(Z_y)\, p(Z_x,Z_y) \, dZ_x \, dZ_y[$]
[$]= \, n1! \, m1! \, C(n1,m1) [$]

which means by taking factorials in denominator of other side of the equation that 

[$] C(n1,m1) \, = \, \, \frac{1}{\, n1! \, m1! \,} \int\limits_{Z_x=-\infty}^{\infty}  \int\limits_{Z_y=-\infty}^{\infty} V(Z_x,Z_v) \, H_{n1}(Z_x) \, H_{m1}(Z_y)\, p(Z_x,Z_y) \, dZ_x \, dZ_y [$]

We can replace integrations with summations, on a uniform 2D grid where asset index k ranges from 0 to K and vol index  ranges from 0 to L, for a numerical procedure as

[$] C(n1,m1) \, = \, \, \frac{1}{\, n1! \, m1! \,} \sum\limits_{k=0}^{K}  \sum\limits_{l=0}^{L} V(Z_x(k,l),Z_v(k,l)) \, H_{n1}(Z_x(k,l)) \, H_{m1}(Z_y(k,l))\, p(k,l) \, dZ_x(k,l) \, dZ_y(k,l) [$]
since [$]Z_y[$] is independent of the asset and does not depend on its index, we can simplify as

[$] C(n1,m1) \, = \, \, \frac{1}{\, n1! \, m1! \,} \sum\limits_{k=0}^{K}  \sum\limits_{l=0}^{L} V(Z_x(k,l),Z_v(l)) \, H_{n1}(Z_x(k,l)) \, H_{m1}(Z_y(l))\, p(k,l) \, dZ_x(k,l) \, dZ_y(l) [$]

In our numerical procedure I used integrated probability mass in each grid cell so we represent integrated probability mass as integral over a single 2D cell, I am not writing integral sign since it is integral over a single cell.

[$]P(k,l)=\, p(k,l) \, dZ_x(k,l) \, dZ_y(l) [$]

to modify the previous equation as

[$] C(n1,m1) \, = \, \, \frac{1}{\, n1! \, m1! \,} \sum\limits_{k=0}^{K}  \sum\limits_{l=0}^{L} V(Z_x(k,l),Z_v(l)) \, H_{n1}(Z_x(k,l)) \, H_{m1}(Z_y(l))\, P(k,l) \, [$]
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 19th, 2023, 8:51 am

Here I explain the very simple way to convert 2D hermite expression of bivariate density into 1D density of asset.
Our 2D representation of bivariate random variable is given as

[$]V(Z_x,Z_y) \, =\, \sum\limits_{n=0}^N \, \sum\limits_{m=0}^M \, C(n,m) \, H_n(Z_x) \, H_m(Z_y) [$]

I suppose we can, due to conditioality, get one dimensional hermite series of asset by integrating 2D hermite series of bivariate random variable over volatility and then dividing by the single dimensional integral of volatility (here Y)as .

[$]\sum\limits_{n=0}^N  \, b(n) \, H_n(Z_x) \,=\, \frac{\int\limits_{Z_y=-\infty}^{\infty} \,V(Z_x,Z_y) \, dZ_y \,}{\int\limits_{-\infty}^{\infty} Y(Z_y) \, dZ_y}\, [$]

We integrate the above expression over volatility as 

[$]\int\limits_{Z_y=-\infty}^{\infty} \,V(Z_x,Z_y) \, dZ_y \,=\int\limits_{Z_y=-\infty}^{\infty} \,\, \sum\limits_{n=0}^N \, \sum\limits_{m=0}^M \, C(n,m) \, H_n(Z_x) \, H_m(Z_y) dZ_y[$]

When we integrate over volatility, all volatility hermite polynomials greater than zero have a zero expectation so we get only non-zero term with zeroth hermite in volatility.

[$]\int\limits_{-\infty}^{\infty} \,V(Z_x,Z_y) \, dZ_y \,=\,\, \sum\limits_{n=0}^N  \, C(n,0) \, H_n(Z_x) H_0(Z_y)[$]

if b(n) are coefficients of independent asset series, Because of conditionality we know

[$]\sum\limits_{n=0}^N  \, b(n) \, H_n(Z_x) \,=\, \frac{\int\limits_{Z_y=-\infty}^{\infty} \,V(Z_x,Z_y) \, dZ_y \,}{\int\limits_{-\infty}^{\infty} Y(Z_y) \, dZ_y}\, =\, \frac{\,\, \sum\limits_{n=0}^N  \, C(n,0) \, H_n(Z_x) H_0(Z_y)}{ H_0(Z_y)\,}[$]

this is because [$]\int\limits_{Z_y=-\infty}^{\infty}  Y(Z_y) dZ_y\, = \, H_0(Z_y)\, = \, \mu(y)[$]

where [$]\mu(y)[$] is mean of volatility

So in order to get a hermite series in asset we have to divide the original  expression with mean as

So we can get coefficients of 1D hermite asset series [$]b(n)=\frac{C(n,0)}{\mu(y)}[$]

where resulting hermite series for asset is given as [$]X=\sum\limits_{n=0}^{N} b(n) H_n(Z)[$]
 
Last edited by Amin on September 19th, 2023, 9:05 am, edited 2 times in total.
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 19th, 2023, 8:54 am

Yesterday, I had some good ideas about analytic solution of 2D correlated SV models with matching/summation of moments. I also want to start working on that so that I could complete all the work on that before next injection. I will post my basic equations for that in latex later tonight. I am very hopeful that method would work well. I will be posting the equations for review by friends later tonight.
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 19th, 2023, 10:23 am

Please note the last equation of post 1961.

[$] C(n1,m1) \, = \, \, \frac{1}{\, n1! \, m1! \,} \sum\limits_{k=0}^{K}  \sum\limits_{l=0}^{L} V(Z_x(k,l),Z_v(l)) \, H_{n1}(Z_x(k,l)) \, H_{m1}(Z_y(l))\, P(k,l) \, [$]

For a bivariate random variable without correlations  V(Z_x(k,l),Z_y(l)) can be written as a product of values of univariate variables on (k,l) grid cell as

[$]V(Z_x(k,l),Z_v(l)) \, = \, X(k) \, Y(l) [$]

So we can write the first equation as

[$] C(n1,m1) \, = \, \, \frac{1}{\, n1! \, m1! \,} \sum\limits_{k=0}^{K}  \sum\limits_{l=0}^{L} X(k) \, Y(l) \, H_{n1}(Z_x(k,l)) \, H_{m1}(Z_y(l))\, P(k,l) \, [$]


Also from equation below we see that X and Y even though correlated/non-correlated, they are not independent in our case. 
[$]V(Z_x(k,l),Z_v(l)) \, = \, X(k) \, Y(l) [$]

If they were independent, their Z-series would be product of two 1 dimensional Z-series which is not the case in our problem.

Explaining these posts was informative for me as well. Now I am thinking that we could retrieve X after integrating V(2D bivariate random variable) over volatility(here Y) and dividing by the mean of volatility since Y(volatility) is independent of X. I am not sure if we could retrieve Y(volatility) after integrating V (two d bivariate variable) over X and dividing by mean of X since X(asset) is not independent of Y(volatility). But I need to think more about it.   
I also think I have more clarity about plotting 2D graphs after writing these posts.
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal
 
User avatar
Amin
Topic Author
Posts: 2309
Joined: July 14th, 2002, 3:00 am

Re: Breakthrough in the theory of stochastic differential equations and their simulation

September 19th, 2023, 11:28 am

Friends, here I want to describe my strategy for solution of 2D SV asset equation with matching/summation of moments.
First please know that in the explanation Capital letters with parameters Zx and Zy are expansions of the form below each with a different set of coefficients C.

[$]A(Z_x,Z_y) \, =\, \sum\limits_{n=0}^N \, \sum\limits_{m=0}^M \, C(n,m) \, H_n(Z_x) \, H_m(Z_y) [$]

When we have a initial value solution in above form and we substitute it in a correlated asset equation and also substitute volatility in the asset Sv equation, we get a 2D solution of the bivariate random variable in the form

[$]A(Z_x,Z_y) \, + \, B(Z_x,Zy) \, \bar{Z_y} \, + \, C(Z_x,Z_y)\, ({\bar{Z_y}}^2-1) + \, D(Z_x,Zy) \, \bar{Z_x} \, + \, E(Z_x,Z_y)\, ({\bar{Z_x}}^2-1) + \, F(Z_x,Zy) \, \bar{Z_x} \, \bar{Z_y} \,[$]

here [$]Z_x[$] and  [$]Z_y[$] are standard normals from initial value and [$]\bar{Z_x}[$] and [$]\bar{Z_y}[$] are standard normals from noise in the SDE. We want to write a single expression that is only in form of just two standard normals instead of four e have in above evolution equation.

We could write the above SV SDE evolution equation as

[$]=\Big[A(Z_x,Z_y) \, + \, B(Z_x,Zy) \, \bar{Z_y} \, + \, C(Z_x,Z_y)\, ({\bar{Z_y}}^2-1) \Big] \, \\
+\Big[ \, D(Z_x,Zy) \, + \, F(Z_x,Zy) \,\, \bar{Z_y} \Big] \,\bar{Z_x} \, \\
+ \, E(Z_x,Z_y)\, ({\bar{Z_x}}^2-1) \,[$]

We first solve by summation of moments of all volatility terms(with [$]Z_y[$] and [$]\bar{Z_y}[$] to get a single [$]\tilde{Z_y}[$]) that are associated with each orthogonal X-hermite. First we tackle first equation in big brackets 
[$]\Big[A(Z_x,Z_y) \, + \, B(Z_x,Zy) \, \bar{Z_y} \, + \, C(Z_x,Z_y)\, ({\bar{Z_y}}^2-1) \Big] \,[$] and equate it to 
[$]G(Z_x,\tilde{Z_y})[$]

similarly for 
[$]\Big[ \, D(Z_x,Zy) \, + \, F(Z_x,Zy) \,\, \bar{Z_y} \Big][$] and equate it to 
[$]H(Z_x,\tilde{Z_y})[$]

and then write the problem as
[$]=G(Z_x,\tilde{Z_y}) \, +H(Z_x,\tilde{Z_y})\,\bar{Z_x} \,+ \, E(Z_x,Z_y)\, ({\bar{Z_x}}^2-1) \,[$]

and then convert the above into one term as A(\tilde{Z_x},\tilde{Z_y}) by adding all asset terms(with [$]Z_x[$] and [$]\bar{Z_x}[$] to get a single [$]\tilde{Z_x}[$]) that are associated with each orthogonal Y-hermite.
My only worry is that  terms with [$]\tilde{Z_y}[$] that appears in G and H above and  [$]Z_y[$] that appears in E might have some incompatibility or hidden correlation (that can throw off some cross moments but I strongly doubt it) with each other but I will have to check. I am very sure all other terms are compatible since they are derived from same initial value Z_y standard normal  and same noise \bar{Z_y} standard normal and they should be compatible in all cross moments (of the true expression) in the form of a single resulting variable.
I solve first for two volatility standard normals to get one in the expression and it is done first since Y (volatility) is independent of X while any changes due to Y are accounted in X that is solved later.
I will start working on this tonight.
Today was a better day since they gave me only relatively light pain and it was not very intense and I could work well. I hope this thing lasts in coming days.
You think life is a secret, Life is only love of flying, It has seen many ups and downs, But it likes travel more than the destination. Allama Iqbal