Serving the Quantitative Finance Community

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

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

May 9th, 2021, 2:17 pm

Friends, I was doing research on ODE like formulas for constant CDF lines of the SDE densities. I realized that only transition SDE is probably not enough to calculate the constant CDF lines and I wanted to explore ways to find a complete density for small steps that takes into account the previous density. I was able to find a simple series formula that could update the entire density for short steps using convolution. It would not work for long steps since I am only using first hermite though I really think that it could be possible to extend this series formula to two hermite polynomials in volatility with a bit of hack( I will share that if that works in my experiments since I still cannot be sure.). Here is the derivation of the new formula.

 We are in Bessel/Lamperti format and we are taking a constant  volatility [$]\sigma[$]. I write the SDE as

[$]dy(t)= \mu(y) dt + \sigma dz(t)[$]

In general when we expand the SDE using Taylor, we get multiple terms in drift that can have several powers of t and similarly for volatility so I write the above equation in discrete form and use symbols  [$]\mu[$] and [$]\sigma[$]  to represent sum of all the terms and I have absorbed t or dt in the same symbol representation since it will help keep focus on the main derivation so I write the discrete form of SDE as

[$]y_2=y_1+ \mu(y_1,t)  + \sigma(t) Z [$]
Here [$]y_2[$] denotes the SDE variable at time [$]t_2[$] and [$]y_1[$] is the starting density variable of SDE at time [$]t_1[$].

We can write the evolution equation for the density at next step using convolution as

[$]p(y_2) =\int_{-\infty}^{\infty} f(y_1) g(\frac{(y_2-y_1- \mu(y_1,t))}{ \sigma(t) }) dy_1[$]

here [$]f(y_1)[$] is the original density at time [$]t_1[$] and [$]g(.)[$] is a normal density.
We write the above integral equation with normal density explicitly as

[$]p(y_2) =\int_{-\infty}^{\infty} f(y_1)  \frac{1}{\sigma \sqrt{2 \pi}} \exp(-.5 \big [\frac{(y_2-y_1- \mu(y_1,t))}{ \sigma(t) } \big ]^2 ) dy_1[$]

Expanding the terms inside the normal exponential, we get

[$]p(y_2) =\int_{-\infty}^{\infty} f(y_1)  \frac{1}{\sigma \sqrt{2 \pi}} \exp(-.5 \big [\frac{( {y_2}^2- 2 y_2(y_1+\mu(y_1,t))+ {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) dy_1[$]

and further re-arrangement of terms gives

[$]p(y_2) =\frac{1}{\sigma \sqrt{2 \pi}}   \exp(-.5 \big [\frac{ {y_2}^2}{ {\sigma(t)}^2 } \big ]) \int_{-\infty}^{\infty} f(y_1)  \exp(-.5 \big [\frac{(- 2 y_2(y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 } \big ]) \exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) dy_1[$]

We can expand the integral as expectation of a series evaluated with respect to density  [$]f(y_1)[$]. Below whenever I write expectation symbol E, it means that expectation is taken over the density [$]f(y_1)[$], so we can write the above integral as an expansion as

[$]p(y_2) =\frac{1}{\sigma(t) \sqrt{2 \pi}}   \exp(-.5 \big [\frac{ {y_2}^2}{ {\sigma(t)}^2 } \big ]) E \Big [\exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] )\Big ] *(1 + y_2 E \big [(\frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 }) \big ] [$]
[$]+ \frac{ {y_2}^2}{2}  E \big [(\frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 }) \big ]^2 + \frac{ {y_2}^3}{6}  E \big [(\frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 }) \big ]^3 + . . .) [$]

please notice that I have taken [$]\frac{1}{\sigma(t) \sqrt{2 \pi}}[$]  out of integral since even if we have expanded [$]\sigma(t)[$] to higher order terms in t, its dependence on [$]y_1[$] is totally negligible in Bessel coordinates unless we are extremely close to zero.
So this way we can easily expand the resulting density of SDE to next steps but we will have to keep time steps reasonable. I have not shown this to keep exposition simple, but the powers of time terms would also explicitly appear in the expansion and can be easily differentiated to work with the ODEs etc. We may have to take a lot of terms in the expansion depending upon what the parameters are but it should not be difficult at all.
So eventually we get an expansion for the density of  [$]y_2[$]  in the form

[$]p(y_2) =C_0  \exp(-.5 \big [\frac{ {y_2}^2}{ {\sigma(t)}^2 } \big ])  *(1 +C_1 y_2  +C_2 \frac{ {y_2}^2}{2}  + C_3 \frac{ {y_2}^3}{6} + . . .) [$]
 where all the constants [$]C_0[$],[$]C_1[$],[$]C_2[$] and further are evaluated as expectations over the original density of [$]y_1[$] at starting time.
Friends, I made some small mistakes in the previous post. I had not taken detailed notes and finessed some equations writing them on the forum. I would have corrected earlier but a fortnightly antipsychotic injection was due and I had to run to take the injection. Anyway here are the corrections which I am sure would have already been obvious to most friends but still I will write them.

I take up from the following equation.
[$]p(y_2) =\frac{1}{\sigma \sqrt{2 \pi}}   \exp(-.5 \big [\frac{ {y_2}^2}{ {\sigma(t)}^2 } \big ]) \int_{-\infty}^{\infty} f(y_1)  \exp(-.5 \big [\frac{(- 2 y_2(y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 } \big ]) \exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) dy_1[$]

We expand the first exponential under integral sign and write as

[$]p(y_2) =  \exp(-.5 \big [\frac{ {y_2}^2}{ {\sigma(t)}^2 } \big ]) \int_{-\infty}^{\infty} f(y_1) \frac{1}{\sigma \sqrt{2 \pi}}  \Big[ 1+ y_2   \big [ -.5  \frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 } \big ] [$]
[$]+  \frac{ {y_2}^2}{2}   {\big [ -.5  \frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 } \big ]}^2 +  \frac{ {y_2}^3}{6}   {\big [ -.5  \frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 } \big ]}^3 + . . .  \Big] \exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) dy_1[$] 

So we get an expansion in the form of series where
[$]p(y_2) =  \exp(-.5 \big [\frac{ {y_2}^2}{ {\sigma(t)}^2 } \big ])  *(C_0 +C_1 y_2  +C_2 \frac{ {y_2}^2}{2}  + C_3 \frac{ {y_2}^3}{6} + . . .) [$]

and 
[$]C_0=\int_{-\infty}^{\infty} f(y_1) \frac{1}{\sigma \sqrt{2 \pi}}\exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) dy_1[$]
[$]=E \Big[\frac{1}{\sigma \sqrt{2 \pi}}\exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) \Big] [$]
and
[$]C_1=\int_{-\infty}^{\infty} f(y_1) \frac{1}{\sigma \sqrt{2 \pi}} \big [ -.5  \frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 } \big ] \exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) dy_1[$]
[$]=E \Big[ \frac{1}{\sigma \sqrt{2 \pi}} \big [ -.5  \frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 } \big ] \exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) \Big] [$]
[$]C_2=\int_{-\infty}^{\infty} f(y_1) \frac{1}{\sigma \sqrt{2 \pi}} {\big [ -.5  \frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 } \big ]}^2 \exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) dy_1[$]
[$]=E \Big[ \frac{1}{\sigma \sqrt{2 \pi}} {\big [ -.5  \frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 } \big ]}^2 \exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) \Big] [$]
[$]C_3=\int_{-\infty}^{\infty} f(y_1) \frac{1}{\sigma \sqrt{2 \pi}} {\big [ -.5  \frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 } \big ]}^3 \exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) dy_1[$]
[$]=E \Big[ \frac{1}{\sigma \sqrt{2 \pi}} {\big [ -.5  \frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 } \big ]}^3 \exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) \Big] [$]
and nth coefficient is 
[$]C_n=\int_{-\infty}^{\infty} f(y_1) \frac{1}{\sigma \sqrt{2 \pi}} {\big [ -.5  \frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 } \big ]}^n \exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) dy_1[$]
[$]=E \Big[ \frac{1}{\sigma \sqrt{2 \pi}} {\big [ -.5  \frac{(- 2 (y_1+\mu(y_1,t)) }{ {\sigma(t)}^2 } \big ]}^n \exp(-.5 \big [\frac{( {(\mu(y_1,t)+{y_1})}^2 ) }{ {\sigma(t)}^2 } \big ] ) \Big] [$]
All these coefficients are expectations over the probability density [$]f(y_1)[$]. If our grid is refined enough, we can easily replace these integrations with summations over the density [$]f(y_1)[$] on the grid. Multiplying Terms in various coefficients are either the same or powers of each other which can easily be calculated once and summed or even integrated if you like in the same one pass over the density.

So we get an expansion in the form of series where
[$]p(y_2) =  \exp(-.5 \big [\frac{ {y_2}^2}{ {\sigma(t)}^2 } \big ])  *(C_0 +C_1 y_2  +C_2 \frac{ {y_2}^2}{2}  + C_3 \frac{ {y_2}^3}{6} + . . .) [$]

I have already taken the antipsychotic injection shot in my arm and I will lose most facility of thought in a day or so only to come back after 7-10 days if I continue to struggle.
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 10th, 2021, 6:42 am

Friends, I have previously mentioned that getting good water everyday remains a difficult thing but it is becoming increasingly difficult everyday. I had told friends that water in all residential areas of the city close to where I live has been drugged but I could still get good water since I got water from areas far away from Johar town. But it is becoming extremely difficult to get good water even from many remote areas of the city. Today I was able to get decent water after trying several times from different remote areas of the city and even then water I got was lightly drugged and I strongly suspect that they are adding mind control drugs to underground water deposits in a lot of adjacent and remote parts of the cities. Water I got today was lightly drugged which means that they had drugged underground water deposits in some other nearby part of the city close to where I got water and its effect spilled over to the place from where I got water. 
I want to request good Americans to please protest against widespread drugging of water supply and underground water deposits with mind control chemicals throughout Lahore city. Crook generals in Pakistan army are getting the realization that I have been able to create some awareness about mind control in our societies and they are very afraid that tens of millions of dollars each crook makes would end if people across the world raise their voice against mind control and American agencies decide to decrease mind control and then hefty bribes would not be given to crooks in Pakistan army. I am very very afraid that American mind control agencies want to detain me again in a week or two and if good Americans do not raise their voice against evil of mind control, a lot of mind control victims like me would face a bleak future. I want to beg all good humans to please protest against mind control in your country and in other countries across the world and do whatever you can to end this ill from every human society.
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 10th, 2021, 9:14 am

I think I have been able to outline a way to add second hermite polynomial in my proposed solution I posted yesterday. It is not very difficult and if things go well I would be posting a new program that will advance the SDE density(in bessel coordinates) using this new algorithm in another 3-4 days or even earlier.
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 10th, 2021, 3:09 pm

I was feeling sick due to bad water(that I called decent water in my previous post) and again in the evening I went to remote parts of the city across the river to get good water and I got some water that was not from a public water supply but was pulled from earth using a pump at that place but water was still lightly drugged meaning mind control agencies are actively drugging underground water deposits all across the city. 
It seems that crooks in American army and mind control  are unable to pay a heed to civilized calls by good American people and others to end their animal cruel practices and remain bent on mischief. If crooks in American army and mind control remain adamant on continuing evil practices, the only solution seems that some brave investigative journalists expose them by running a comprehensive story on mind control practices by American army. It seems that doing a civilized dialogue with hardened crooks in mind control gives them a strong sense of weakness of good people and makes the crooks even more adamant to continue their evil practices.  Reminds me of  Abu-Gharib. Very similarly, Crooks in defense had no conception that they were doing any wrong thing when there was a culture of openly urinating on human captives. It was an open thing in army and most crooks thought it was indeed a very right thing to do( and I am sure some of those crooks still believe that it was a right thing they did even after being reprimanded by the broader American society). It was not until brave people at CNN did a daring story against animal practices by crooks that evil practices stopped. Though American army crooks retard intelligent people of all color and creed, these ultra right wing army crooks love to retard blacks and muslims with great relish. Blacks are only 8-10% of US population but make a very large proportion of victims in united states since many ultra right wing crooks in US army would rather die than let those intelligent blacks succeed in American society in a big way.
I want to request CNN, New York Times, Washington Post and large reputed European media outlets to run a comprehensive story on mind control torture, retarding and victimization of intelligent people of US and other nations by crooks in US army on behest of some powerful people in United States and due to rightwing extremist biases of these crooks. If you would like to do investigative research about animal practices of US army, one great resource would be mainland European embassies in Muslim countries who keep a detailed account of mind control persecution of intelligent muslims in these countries by crooks in US army. Many of the staff in mainland European embassies are very good human beings who abhor such practices and would love to cooperate with good journalists in exposing the evil animal practices of US army crooks. Only the accounts of people at mainland European embassies in muslim countries thorough animal practices of American army's mind control wing would be enough to drop a great bombshell in the media and general public all across the world. I want to warn all the good people who try to have a civilized dialogue with crooks in American army to end their evil practices that their being nice with crooks is a very misguided approach. Since good people do not have the power to forcefully end the evil practices of US army crooks, only way to end the evil practices of US army crooks is by exposing them openly in US public and all across the world. 
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 11th, 2021, 8:54 am

Friends, I was able to get good water today. I tried water from public supply in another remote area and it was also drugged but then I drove into a different neighborhood where I have not been going for a long time and I was able to buy very good 5 Litre Nestle water bottles. I earlier mentioned that 5 Liter Nestle bottled water is very good in the market but Pak army crooks went into several markets and drugged the Nestle 5 Liter water bottles and it was becoming difficult to get that water good in many areas of the city so I turned to water from public supply and underground water pulled with pumps in remote areas. I am sure 5 Liter Nestle water bottles are still good in several areas and now Pak Army crooks will go into different markets to drug that Nestle water. I want good Pakistanis and foreign embassies in Pakistan to watch out carefully how army crooks drug 5 Liter Nestle water bottles in different parts of Lahore city.
Good thing is that I am working again carefully on writing my program and if all things go well, it will be ready in another day or two and I will post it on the forum. I am working full time on the program I mentioned.
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 16th, 2021, 8:10 am

Friends, I earlier thought that it would be rather easy to include the effect of second hermite polynomial but it turned out that my intuition about it was not correct and I had to think of all sort of ways how to expand the equations. I even tried to think of a series inside the exponential and tried to tackle it. But later I was able to find a rather simpler expression(though still not extremely simple) that is also very accurate. Here are the details. 
If the Stochastic differential equation is written in discrete form as
[$]y_2 = y_1 + \mu + \sigma_1 Z + \sigma_2 (Z^2-1) [$]
The transition normal that appears in transition exponential is given with second hermite polynomial as
[$]Z_t(y_2,y_1)=\frac{(y_2 - y_1 - \mu + \sigma_2)}{.5 (\sigma_1 + \sqrt{{\sigma_1}^2 -4 \sigma_2 (y_2 - y_1 - \mu + \sigma_2) })}[$]

It turns out that we can faithfully expand the above expression in terms of two terms as

[$] Z_t(y_2,y_1)=\frac{(y_2 - y_1 - \mu + \sigma_2)}{ \sigma_1}- C_1 \frac{{(y_2 - y_1 - \mu + \sigma_2)}^2 \sigma_2}{\sigma_1}[$]


Where I found [$]C_1[$] by equating the true transition normal at a certain one value of [$]y_2[$] with the equation below and it holds extremely closely to five or six digits(The whole second term is a small but still significant number) for all values of [$]y_2[$] when originating from a certain [$]y_1[$] (or also other values of [$]y_1[$])

So our transition normal we have to expand now becomes
[$]\exp \Big[-.5 \big[\frac{(y_2 - y_1 - \mu + \sigma_2)}{ \sigma_1}- C_1 \frac{{(y_2 - y_1 - \mu + \sigma_2)}^2 \sigma_2}{\sigma_1} \big]^2 \Big] *\Big[\frac{1}{ \sigma_1}- C_1 \frac{{(y_2 - y_1 - \mu + \sigma_2)} \sigma_2}{\sigma_1} \Big]/\sqrt{2 \pi}[$]

We have to find expectation of above exponential with respect to probability density of [$]y_1[$]
The above expression can be handled in several ways with a bit of tact and I will be doing that in next several days. Sorry to friends for the already delay. I had antipsychotic injection and that was showing effect and I could not work properly but I hope to have a working program ready in a few days.
Though [$]C_1[$] is time dependent on time step size, I am sure its dependence on time can be explicitly found and stated in equations if needed.
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 16th, 2021, 8:32 am

As a start, I hope to have an expression for the resulting density in terms of [$]y_2[$] only with a given time step. Once that is done in a good manner, I will make a more advanced version that will have explicit dependence on time step as well so friends could try different time step sizes. I also  think that it should be possible to find CDF (Cumulative distribution function) of the resulting density analytically by finding CDF at zero and integrating from there so we would be able to find associated value of Z everywhere if needed.
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 21st, 2021, 4:54 am

Friends, I am dividing my time on solution of stochastic integrals project and convolution series solution of SDEs. I was having some difficulty in tackling the series and would be trying to handle that in next few days. In stochastic integrals project I made some headway in calculation of variance of multiple nested stochastic integrals with time in them so things look better. In a few days I will be coming back with more code and analytics about solution to both the projects.
In the meantime I want to share an old file with friends. As I earlier mentioned for friends that after simulation of SDEs we will move to bayesian filtering and inference with SDEs. So I am sharing a very old file that describes how to do algorithmic trading based on bayesian filtering. What we have in the old file is a lognormal stochastic differential equation for asset with a drift(trend) and volatility in it. Both drift and volatility are slowly moving parameters with their own SDEs and the density of drift/trend and volatility is continuously updated after a very small discrete period of time. If the drift variable is more significant than volatility, we can say that market is trending in a particular direction and if drift is very small compared to volatility, we would say that market is mean-reverting. model can be used on various time scales and in a typical market on a short time scale, the drift(trend variable) will be changing directions every few minutes and if used for trading  on this scale, our trade life would be a few minutes at most. Sometimes even on this time scale drift will remain far less significant than volatility variable and we could be making mean-reverting trades even on this time scale. 
Similar model can be used for pairs trading and other relative value where a substantial dynamic drift in relative value would show that pairs are diverging or converging.
It is not just in finance, in most physical and many social sciences there are many time series that dynamically change and can be modelled like this and our bayesian filtering exercise will be very helpful there as well. 
The paper is only for review, what we want to do would be different as SDEs for drift and volatility would change and timescales for change for both drift and volatility variables will be different. As a start, we will take volatility locally constant(but evolving slowly with time as we will see) and only drift would be totally dynamically changing. So we will be dealing with a lot of very interesting stuff in the future. 
Here is the file that I wrote on algorithmic trading using bayesian methods more than ten years ago.


Though there is very little financial information in the writeup file and it is purely technical, we will make up for that now by applying the bayesian methods on real S&P 500 data and I will be explaining everything in detail. The writeup is only for reference and most things would change though spirit of the idea would remain the same.
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 21st, 2021, 3:27 pm

In the previous post I mentioned that I have made headway in calculation of variances in stochastic dt-integrals. I am making this post to explain that. But please let me put things in context.
Let us suppose we have an SDE of the form
[$]dx(t) = \mu(x) dt + \sigma(x) dz(t)[$]
and we want to calculate integrals of the kind  [$]\int {x(t)}^{\alpha} dt [$]
To calculate these integrals we know the formula
[$]\int_{t_1}^{t_2} {x(t)}^{\alpha} dt = \int_{t_1}^{t_2} d[ t {x(t)}^{\alpha}]- \int_{t_1}^{t_2} t d[{x(t)}^{\alpha}][$]
and we have to know how to expand the second integral correctly which is 
[$]\int_{t_1}^{t_2} t \, d[{x(t)}^{\alpha}] [$]
[$] =\int_{t_1}^{t_2} t \, \alpha \, {x(t)}^{\alpha-1} \mu(x) dt [$]
[$]+ \int_{t_1}^{t_2} t \, \alpha \, {x(t)}^{\alpha-1} \sigma(x) dz(t)[$]
[$] +\int_{t_1}^{t_2} .5 t \, \alpha \, (\alpha-1) \, {x(t)}^{\alpha-2} {\sigma(x)}^2 dt[$]
The above equation follows from Ito change of variable formula but generally it would not be accurate enough for simulations so we expand it further like we have done  for monte carlo simulations of SDEs. Expanding inside the integrals we get a more suitable equation for correct simulation as

[$]\int_{t_1}^{t_2} t \, d[{x(t)}^{\alpha}] [$]
[$] =\int_{t_1}^{t_2} t \, \alpha \, {x(t_1)}^{\alpha-1} \mu(x(t_1)) dt + \int_{t_1}^{t_2} t  \, \int_{t_1}^t \frac{d[\alpha \, {x(s)}^{\alpha-1} \mu(x(s))]}{dx} \mu(x(s)) ds \,   dt[$]
[$] + \int_{t_1}^{t_2} t \,  \int_{t_1}^t \frac{d[\alpha \,{x(s)}^{\alpha-1} \mu(x(s))]}{dx} \sigma(x(s)) dz(s) \, dt+ \int_{t_1}^{t_2} t \, \int_{t_1}^t \frac{d^2[\alpha \,{x(s)}^{\alpha-1} \mu(x(s))]}{dx^2} {\sigma(x(s))}^2 ds \, dt[$]
[$]+ \int_{t_1}^{t_2} t \, \alpha \, {x(t_1)}^{\alpha-1} \sigma(x(t_1)) dz(t)+ \int_{t_1}^{t_2} t  \, \int_{t_1}^t \frac{d[\alpha \, {x(s)}^{\alpha-1} \sigma(x(s))]}{dx} \mu(x(s)) ds \,   dz(t)[$]
[$] + \int_{t_1}^{t_2} t \,  \int_{t_1}^t \frac{d[\alpha \,{x(s)}^{\alpha-1} \sigma(x(s))]}{dx} \sigma(x(s)) dz(s) \, dz(t)+ \int_{t_1}^{t_2} t \, \int_{t_1}^t \frac{d^2[\alpha \,{x(s)}^{\alpha-1} \sigma(x(s))]}{dx^2} {\sigma(x(s))}^2 ds \, dz(t)[$]
[$] +\int_{t_1}^{t_2} .5 t \, \alpha \, (\alpha-1) \, {x(t_1)}^{\alpha-2} {\sigma(x(t_1))}^2 dt+ \int_{t_1}^{t_2} t  \, \int_{t_1}^t .5 \frac{d[\alpha \, (\alpha-1) \, {x(s)}^{\alpha-2} {\sigma(x(s))}^2]}{dx} \mu(x(s)) ds \,   dt[$]
[$] + \int_{t_1}^{t_2} t \,  \int_{t_1}^t .5 \frac{d[\alpha \, (\alpha-1) \, {x(s)}^{\alpha-2} {\sigma(x(s))}^2]}{dx} \sigma(x(s)) dz(s) \, dt+ \int_{t_1}^{t_2} t \, \int_{t_1}^t .5 \frac{d^2[\alpha \, (\alpha-1) \, {x(s)}^{\alpha-2} {\sigma(x(s))}^2]}{dx^2} {\sigma(x(s))}^2 ds \, dt[$]
In many cases we will like to expand the integrals further but it becomes tedious so I end at double integrals. Finally just like we did in single integrals, in double integrals we replace [$]x(s)[$] like terms by their initial values at [$] t_1[$] as [$]x(t_1)[$] and since we have taken the x-dependent terms inside the integrals as constant at initial value, we can take them outside of the integrals to write the above equation as

[$]\int_{t_1}^{t_2} t \, d[{x(t)}^{\alpha}] [$]
[$] =( \alpha \, {x(t_1)}^{\alpha-1} \mu(x(t_1))) \int_{t_1}^{t_2} t \, dt + (\frac{d[\alpha \, {x(t_1)}^{\alpha-1} \mu(x(t_1))]}{dx} \mu(x(t_1)) \int_{t_1}^{t_2} t  \, \int_{t_1}^t  ds \,   dt[$]
[$] + (\frac{d[\alpha \,{x(t_1)}^{\alpha-1} \mu(x(t_1))]}{dx} \sigma(x(t_1)) \int_{t_1}^{t_2} t \,  \int_{t_1}^t  dz(s) \, dt+ (\frac{d^2[\alpha \,{x(t_1)}^{\alpha-1} \mu(x(t_1))]}{dx^2} {\sigma(x(t_1))}^2) \int_{t_1}^{t_2} t \, \int_{t_1}^t  ds \, dt[$]
[$]+(\alpha \, {x(t_1)}^{\alpha-1} \sigma(x(t_1))) \int_{t_1}^{t_2} t \,  dz(t)+ (\frac{d[\alpha \, {x(t_1)}^{\alpha-1} \sigma(x(t_1))]}{dx} \mu(x(t_1))) \int_{t_1}^{t_2} t  \, \int_{t_1}^t  ds \,   dz(t)[$]
[$] +(\frac{d[\alpha \,{x(t_1)}^{\alpha-1} \sigma(x(t_1))]}{dx} \sigma(x(t_1))) \int_{t_1}^{t_2} t \,  \int_{t_1}^t  dz(s) \, dz(t)+(\frac{d^2[\alpha \,{x(t_1)}^{\alpha-1} \sigma(x(t_1))]}{dx^2} {\sigma(x(t_1))}^2) \int_{t_1}^{t_2} t \, \int_{t_1}^t  ds \, dz(t)[$]
[$] +(.5 \, \alpha \, (\alpha-1) \, {x(t_1)}^{\alpha-2} {\sigma(x(t_1)))}^2)\int_{t_1}^{t_2}  t \,  dt+(.5 \, \frac{d[\alpha \, (\alpha-1) \, {x(t_1)}^{\alpha-2} {\sigma(x(t_1))}^2]}{dx} \mu(x(t_1))) \int_{t_1}^{t_2} t  \, \int_{t_1}^t  ds \,   dt[$]
[$] +(.5 \, \frac{d[\alpha \, (\alpha-1) \, {x(t_1)}^{\alpha-2} {\sigma(x(t_1))}^2]}{dx} \sigma(x(t_1))) \int_{t_1}^{t_2} t \,  \int_{t_1}^t  dz(s) \, dt+ (.5 \, \frac{d^2[\alpha \, (\alpha-1) \, {x(s)}^{\alpha-2} {\sigma(x(t_1))}^2]}{dx^2} {\sigma(x(t_1))}^2)\int_{t_1}^{t_2} t \, \int_{t_1}^t  ds \, dt[$]

So we are basically left with how to solve the integrals of the type(leaving the obvious to solve integrals) [$] \int_{t_1}^{t_2} t \, \int_{t_1}^t  ds \, dz(t)[$], [$]\int_{t_1}^{t_2} t \,  \int_{t_1}^t  dz(s) \, dt[$] and if we go to higher order, we need to solve other integrals like [$] \int_{t_1}^{t_2} t \, \int_{t_1}^t \, \int_{t_1}^s dz(v) \, ds \, dz(t)[$],  [$] \int_{t_1}^{t_2} t \, \int_{t_1}^t \, \int_{t_1}^s dv \, dz(s) \, dz(t)[$],  [$] \int_{t_1}^{t_2} t \, \int_{t_1}^t \, \int_{t_1}^s dz(v) \, dz(s) \, dt[$]. After putting these integrlas in context, in next post I describe how to solve these integrals.
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 21st, 2021, 5:13 pm

In the previous post I mentioned that I have made headway in calculation of variances in stochastic dt-integrals. I am making this post to explain that. But please let me put things in context.
Let us suppose we have an SDE of the form
[$]dx(t) = \mu(x) dt + \sigma(x) dz(t)[$]
and we want to calculate integrals of the kind  [$]\int {x(t)}^{\alpha} dt [$]
To calculate these integrals we know the formula
[$]\int_{t_1}^{t_2} {x(t)}^{\alpha} dt = \int_{t_1}^{t_2} d[ t {x(t)}^{\alpha}]- \int_{t_1}^{t_2} t d[{x(t)}^{\alpha}][$]
and we have to know how to expand the second integral correctly which is 
[$]\int_{t_1}^{t_2} t \, d[{x(t)}^{\alpha}] [$]
[$] =\int_{t_1}^{t_2} t \, \alpha \, {x(t)}^{\alpha-1} \mu(x) dt [$]
[$]+ \int_{t_1}^{t_2} t \, \alpha \, {x(t)}^{\alpha-1} \sigma(x) dz(t)[$]
[$] +\int_{t_1}^{t_2} .5 t \, \alpha \, (\alpha-1) \, {x(t)}^{\alpha-2} {\sigma(x)}^2 dt[$]
The above equation follows from Ito change of variable formula but generally it would not be accurate enough for simulations so we expand it further like we have done  for monte carlo simulations of SDEs. Expanding inside the integrals we get a more suitable equation for correct simulation as

[$]\int_{t_1}^{t_2} t \, d[{x(t)}^{\alpha}] [$]
[$] =\int_{t_1}^{t_2} t \, \alpha \, {x(t_1)}^{\alpha-1} \mu(x(t_1)) dt + \int_{t_1}^{t_2} t  \, \int_{t_1}^t \frac{d[\alpha \, {x(s)}^{\alpha-1} \mu(x(s))]}{dx} \mu(x(s)) ds \,   dt[$]
[$] + \int_{t_1}^{t_2} t \,  \int_{t_1}^t \frac{d[\alpha \,{x(s)}^{\alpha-1} \mu(x(s))]}{dx} \sigma(x(s)) dz(s) \, dt+ \int_{t_1}^{t_2} t \, \int_{t_1}^t \frac{d^2[\alpha \,{x(s)}^{\alpha-1} \mu(x(s))]}{dx^2} {\sigma(x(s))}^2 ds \, dt[$]
[$]+ \int_{t_1}^{t_2} t \, \alpha \, {x(t_1)}^{\alpha-1} \sigma(x(t_1)) dz(t)+ \int_{t_1}^{t_2} t  \, \int_{t_1}^t \frac{d[\alpha \, {x(s)}^{\alpha-1} \sigma(x(s))]}{dx} \mu(x(s)) ds \,   dz(t)[$]
[$] + \int_{t_1}^{t_2} t \,  \int_{t_1}^t \frac{d[\alpha \,{x(s)}^{\alpha-1} \sigma(x(s))]}{dx} \sigma(x(s)) dz(s) \, dz(t)+ \int_{t_1}^{t_2} t \, \int_{t_1}^t \frac{d^2[\alpha \,{x(s)}^{\alpha-1} \sigma(x(s))]}{dx^2} {\sigma(x(s))}^2 ds \, dz(t)[$]
[$] +\int_{t_1}^{t_2} .5 t \, \alpha \, (\alpha-1) \, {x(t_1)}^{\alpha-2} {\sigma(x(t_1))}^2 dt+ \int_{t_1}^{t_2} t  \, \int_{t_1}^t .5 \frac{d[\alpha \, (\alpha-1) \, {x(s)}^{\alpha-2} {\sigma(x(s))}^2]}{dx} \mu(x(s)) ds \,   dt[$]
[$] + \int_{t_1}^{t_2} t \,  \int_{t_1}^t .5 \frac{d[\alpha \, (\alpha-1) \, {x(s)}^{\alpha-2} {\sigma(x(s))}^2]}{dx} \sigma(x(s)) dz(s) \, dt+ \int_{t_1}^{t_2} t \, \int_{t_1}^t .5 \frac{d^2[\alpha \, (\alpha-1) \, {x(s)}^{\alpha-2} {\sigma(x(s))}^2]}{dx^2} {\sigma(x(s))}^2 ds \, dt[$]
In many cases we will like to expand the integrals further but it becomes tedious so I end at double integrals. Finally just like we did in single integrals, in double integrals we replace [$]x(s)[$] like terms by their initial values at [$] t_1[$] as [$]x(t_1)[$] and since we have taken the x-dependent terms inside the integrals as constant at initial value, we can take them outside of the integrals to write the above equation as

[$]\int_{t_1}^{t_2} t \, d[{x(t)}^{\alpha}] [$]
[$] =( \alpha \, {x(t_1)}^{\alpha-1} \mu(x(t_1))) \int_{t_1}^{t_2} t \, dt + (\frac{d[\alpha \, {x(t_1)}^{\alpha-1} \mu(x(t_1))]}{dx} \mu(x(t_1)) \int_{t_1}^{t_2} t  \, \int_{t_1}^t  ds \,   dt[$]
[$] + (\frac{d[\alpha \,{x(t_1)}^{\alpha-1} \mu(x(t_1))]}{dx} \sigma(x(t_1)) \int_{t_1}^{t_2} t \,  \int_{t_1}^t  dz(s) \, dt+ (\frac{d^2[\alpha \,{x(t_1)}^{\alpha-1} \mu(x(t_1))]}{dx^2} {\sigma(x(t_1))}^2) \int_{t_1}^{t_2} t \, \int_{t_1}^t  ds \, dt[$]
[$]+(\alpha \, {x(t_1)}^{\alpha-1} \sigma(x(t_1))) \int_{t_1}^{t_2} t \,  dz(t)+ (\frac{d[\alpha \, {x(t_1)}^{\alpha-1} \sigma(x(t_1))]}{dx} \mu(x(t_1))) \int_{t_1}^{t_2} t  \, \int_{t_1}^t  ds \,   dz(t)[$]
[$] +(\frac{d[\alpha \,{x(t_1)}^{\alpha-1} \sigma(x(t_1))]}{dx} \sigma(x(t_1))) \int_{t_1}^{t_2} t \,  \int_{t_1}^t  dz(s) \, dz(t)+(\frac{d^2[\alpha \,{x(t_1)}^{\alpha-1} \sigma(x(t_1))]}{dx^2} {\sigma(x(t_1))}^2) \int_{t_1}^{t_2} t \, \int_{t_1}^t  ds \, dz(t)[$]
[$] +(.5 \, \alpha \, (\alpha-1) \, {x(t_1)}^{\alpha-2} {\sigma(x(t_1)))}^2)\int_{t_1}^{t_2}  t \,  dt+(.5 \, \frac{d[\alpha \, (\alpha-1) \, {x(t_1)}^{\alpha-2} {\sigma(x(t_1))}^2]}{dx} \mu(x(t_1))) \int_{t_1}^{t_2} t  \, \int_{t_1}^t  ds \,   dt[$]
[$] +(.5 \, \frac{d[\alpha \, (\alpha-1) \, {x(t_1)}^{\alpha-2} {\sigma(x(t_1))}^2]}{dx} \sigma(x(t_1))) \int_{t_1}^{t_2} t \,  \int_{t_1}^t  dz(s) \, dt+ (.5 \, \frac{d^2[\alpha \, (\alpha-1) \, {x(s)}^{\alpha-2} {\sigma(x(t_1))}^2]}{dx^2} {\sigma(x(t_1))}^2)\int_{t_1}^{t_2} t \, \int_{t_1}^t  ds \, dt[$]

So we are basically left with how to solve the integrals of the type(leaving the obvious to solve integrals) [$] \int_{t_1}^{t_2} t \, \int_{t_1}^t  ds \, dz(t)[$], [$]\int_{t_1}^{t_2} t \,  \int_{t_1}^t  dz(s) \, dt[$] and if we go to higher order, we need to solve other integrals like [$] \int_{t_1}^{t_2} t \, \int_{t_1}^t \, \int_{t_1}^s dz(v) \, ds \, dz(t)[$],  [$] \int_{t_1}^{t_2} t \, \int_{t_1}^t \, \int_{t_1}^s dv \, dz(s) \, dz(t)[$],  [$] \int_{t_1}^{t_2} t \, \int_{t_1}^t \, \int_{t_1}^s dz(v) \, dz(s) \, dt[$]. After putting these integrlas in context, in next post I describe how to solve these integrals.
I continued to try how to solve for variance of the above integrals when they start in forward time and not from zero. multiple Integrals ending with dt were not easy but finally it turned out that all integrals were very simple. I will start with simplest integrals

[$]Variance \Big[\int_{t_1}^{t_2} t \, dz(t) \Big]= \frac{{t_2}^3}{3}-\frac{{t_1}^3}{3}[$]

We notice that we can write the integral [$]\int_{t_1}^{t_2} t \, dz(t)[$] as [$]\int_{0}^{t_2-t_1} (t_1+t) \, dz(t)[$]
When we apply Ito Isometry on the second integral we find that its variance indeed matches the variance of the first integral.
[$]Variance \Big[\int_{0}^{t_2-t_1} (t_1+t) \, dz(t) \Big]=\int_{0}^{t_2-t_1} {(t_1+t)}^2 \, dt= \frac{{t_2}^3}{3}-\frac{{t_1}^3}{3}[$]

We use the same simple strategy to solve all nested integrals with t in it and limits equal to [$]t_1[$] and [$]t_2[$]. We replace t with [$]t_1+t[$] and put the starting limit of integrals to zero and final limit to [$]t_2-t_1[$] and we easily get all the results.

[$]Variance[\int_{t_1}^{t_2} t \, \int_{t_1}^{t} ds dz(t)][$]
[$]=Variance[\int_{0}^{t_2-t_1} (t_1+t) \, \int_{0}^{t} ds dz(t)][$]
[$]=\int_0^{t_2-t_1} {(t_1+t)}^2 t^2 dt=(1/30) ( t_2-t_1)^3 ({t_1}^2 + 3 \, t_1 \, t_2 + 6 \, {t_2}^2)[$]
which is the right variance

Now we come to integral
[$]\int_{t_1}^{t_2} t \, \int_{t_1}^{t} dz(s) dt[$]
[$]=\int_{0}^{t_2-t_1} (t_1+t) \, \int_{0}^{t} dz(s) dt[$]
[$]=\int_{0}^{t_2-t_1} (t_1+t) \,  z(t) dt[$]
[$]=\int_{0}^{t_2-t_1} d[\frac{(t_1+t)^2 \, z(t)}{2}] - \int_0^{t_2-t_1} \, \frac{(t_1+t)^2}{2} \, dz(t)[$]
Please note that initial value on first complete integral goes to zero and We solve the second part with Ito-isometry to get a representation of the above integral as
[$](\frac{{t_2}^2 \, \sqrt{t_2-t_1}}{2} - \sqrt{\frac{{t_2}^5-{t_1}^5}{20}} ) \,  Z[$]  where Z is a standard normal

Similarly we solve third order integrals. I give some of them here as
[$]\int_{t_1}^{t_2} t \, \int_{t_1}^{t} \int_{t_1}^{s} dv dz(s) dz(t)[$]
[$]=\int_{0}^{t_2-t_1} (t_1+t) \, \int_{0}^{t} \int_{0}^{s} dv dz(s) dz(t)[$]
[$]=\int_{0}^{t_2-t_1} (t_1+t) \,  \frac{t \, z(t)}{\sqrt{3}} dz(t)[$]
going to variance now
[$]=\int_{0}^{t_2-t_1} {(t_1+t)}^2 \frac{t^3}{3} dt[$]
[$]=(1/180) \, {(t_2-t_1)}^4 \, (10 {t_2}^2 + 4 t_1 t_2 + {t_1}^2) [$]
above integral is variance
and 
[$]\int_{t_1}^{t_2} t \, \int_{t_1}^{t} \int_{t_1}^{s} dz(v) ds dz(t)[$]
[$]=\int_{0}^{t_2-t_1} (t_1+t) \, \int_{0}^{t} \int_{0}^{s} dz(v) ds dz(t)[$]
[$]=\int_{0}^{t_2-t_1} (t_1+t) \, (1-1/\sqrt{3}) \, t \, z(t)   dz(t)[$]
going to variance now
[$]=\int_{0}^{t_2-t_1} {(t_1+t)}^2 \,{(1-1/\sqrt{3})}^2 \, t^3 \, dt[$]
[$]=(1/60) \, {(1-1/\sqrt{3})}^2 {(t_2-t_1)}^4 \, (10 {t_2}^2 + 4 t_1 t_2 + {t_1}^2) [$]
Above integral is variance. Please note that for both of the above integrals, we will multiply the square root of their variances with  second hermite polynomial and there will be an additional division by square root of two which is variance of second hermite polynomial with standard normal.
Now the integral
[$]\int_{t_1}^{t_2} t \, \int_{t_1}^{t} \int_{t_1}^{s} dz(v) dz(s) dt[$]
[$]=\int_{0}^{t_2-t_1} (t_1+t) \, \int_{0}^{t} \int_{0}^{s} dz(v) dz(s) dt[$]
[$]=\int_{0}^{t_2-t_1} d[\frac{{(t_1+t)}^2}{2} \, H_2(z(t))] -\int_{0}^{t_2-t_1} \, {(t_1+t)}^2 \, z(t) \, dz(t)[$]
[$]=\frac{{t_2}^2}{2} \, H_2(z(t_2-t_1)) - \sqrt{\frac{{t_1}^6}{30}-\frac{t_1{t_2}^5}{5}+\frac{{t_2}^6}{6}} \, H_2(Z)/\sqrt{2}[$]

in the above equation [$]H_2(z(t_2-t_1))[$] is second hermite polynomial with a z that has variance [$]t_2-t_1[$] and H_2(Z) is second hermite polynomial with standard normal. 
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 23rd, 2021, 4:04 pm

Friends, I had been thinking about the filtering model for statistical trading. I had a lot of interesting ideas and I want to share them with friends. 
First of all the model we want to develop could be used in for vanilla trading on a sub-minute scale to a few minutes scale(or much more as we will later see.) The model could also be used in an excellent fashion in pairs and relative value trading(in scalar and vector form for a group of several pairs simultaneously with covariances involved). 
1. We will start with a simple linear model, gain intuition, learn stylized facts a and then see if we need to extend it  to non-linear filtering models. Here I describe the model with SDEs(or an equivalent form in discrete state space version). First we take volatility constant and suppose that drift has its own dynamics dictated by another SDE. 
2. Since we are dealing with a level of minutes at maximum, we will not consider the asset dynamics as lognormal and just consider its noise as normal scaled by volatility. Our discrete time  spacing can range from five seconds to twenty seconds for vanilla trading. At this level, considering a lognormal SDE would be a bad choice.
3. since we are working/trading on a level of few minutes at max, units of time will not be years but rather possibly in minutes or hours.
4. In order to decrease noise due to bid-ask crossing, we will work with mid-prices.
5. drift cannot continue to increase so it must be slowly mean-reverting. 

Here is the SDE of financial asset or pair ratio
[$]X(t+1)=X(t) \,+ \mu(t) \, dt + \sigma \, dz(t)[$]
while [$]\mu(t)[$] has its SDE given as
[$]\mu(t+1)=\mu(t) \, - \theta  \, \mu(t) \, dt+ \sigma_{mu} dw(t)[$]

Keeping the SDE for drift the same, We can write the SDE for financial asset in returns form for the asset as
[$]dX(t)=\, \mu(t) \, dt + \sigma \, dz(t)[$]

If the model(SDEs and parameters) is well-specified, its variance with drift will be smaller than its variance without drift and if model is poorly specified, its variance will be larger as compared to without drift variance.
We notice that asset price is fully observable while drift is a hidden variable and the two SDEs are exactly in Gaussian Kalman filter form. I write the two SDEs again
[$]dX(t)= \, \mu(t) \, dt + \sigma \, dz(t)[$]
while [$]\mu(t)[$] has its SDE given as
[$]\mu(t+1)=\mu(t) \, - \theta  \, \mu(t) \, dt+ \sigma_{mu} dw(t)[$]

So we can use the huge literature and machinery developed for Kalman filter to solve this problem.
Returns of financial are highly notorious to defy attempts at finding structure but I am sure the above simple model would work successfully in a large number of cases in reality. With properly optimized parameters, The above model would continue to tell us when the drift is significantly different from zero and help us in trading decisions.
As I stated in my previous post, with a properly optimized model,  if the level of drift constantly stays insignificant and far smaller than volatility, we can say that we are in a mean-reverting regime and we need to trade accordingly. On the other hand, when the drift continues to remain in significant range, we can make directional trades according to short-term trend dictated by direction of drift.
Since we are in a Kalman filter mode, we can make our model very interesting by making it large dimensional and by adding covariances across different financial assets  and their drifts and the model will still remain robust and tractable.
I will be coming with worked out programs and more equations in a few days.
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 24th, 2021, 9:16 pm

Friends, I had been thinking about the filtering model for statistical trading. I had a lot of interesting ideas and I want to share them with friends. 
First of all the model we want to develop could be used in for vanilla trading on a sub-minute scale to a few minutes scale(or much more as we will later see.) The model could also be used in an excellent fashion in pairs and relative value trading(in scalar and vector form for a group of several pairs simultaneously with covariances involved). 
1. We will start with a simple linear model, gain intuition, learn stylized facts a and then see if we need to extend it  to non-linear filtering models. Here I describe the model with SDEs(or an equivalent form in discrete state space version). First we take volatility constant and suppose that drift has its own dynamics dictated by another SDE. 
2. Since we are dealing with a level of minutes at maximum, we will not consider the asset dynamics as lognormal and just consider its noise as normal scaled by volatility. Our discrete time  spacing can range from five seconds to twenty seconds for vanilla trading. At this level, considering a lognormal SDE would be a bad choice.
3. since we are working/trading on a level of few minutes at max, units of time will not be years but rather possibly in minutes or hours.
4. In order to decrease noise due to bid-ask crossing, we will work with mid-prices.
5. drift cannot continue to increase so it must be slowly mean-reverting. 

Here is the SDE of financial asset or pair ratio
[$]X(t+1)=X(t) \,+ \mu(t) \, dt + \sigma \, dz(t)[$]
while [$]\mu(t)[$] has its SDE given as
[$]\mu(t+1)=\mu(t) \, - \theta  \, \mu(t) \, dt+ \sigma_{mu} dw(t)[$]

Keeping the SDE for drift the same, We can write the SDE for financial asset in returns form for the asset as
[$]dX(t)=\, \mu(t) \, dt + \sigma \, dz(t)[$]

If the model(SDEs and parameters) is well-specified, its variance with drift will be smaller than its variance without drift and if model is poorly specified, its variance will be larger as compared to without drift variance.
We notice that asset price is fully observable while drift is a hidden variable and the two SDEs are exactly in Gaussian Kalman filter form. I write the two SDEs again
[$]dX(t)= \, \mu(t) \, dt + \sigma \, dz(t)[$]
while [$]\mu(t)[$] has its SDE given as
[$]\mu(t+1)=\mu(t) \, - \theta  \, \mu(t) \, dt+ \sigma_{mu} dw(t)[$]

So we can use the huge literature and machinery developed for Kalman filter to solve this problem.
Returns of financial are highly notorious to defy attempts at finding structure but I am sure the above simple model would work successfully in a large number of cases in reality. With properly optimized parameters, The above model would continue to tell us when the drift is significantly different from zero and help us in trading decisions.
As I stated in my previous post, with a properly optimized model,  if the level of drift constantly stays insignificant and far smaller than volatility, we can say that we are in a mean-reverting regime and we need to trade accordingly. On the other hand, when the drift continues to remain in significant range, we can make directional trades according to short-term trend dictated by direction of drift.
Since we are in a Kalman filter mode, we can make our model very interesting by making it large dimensional and by adding covariances across different financial assets  and their drifts and the model will still remain robust and tractable.
I will be coming with worked out programs and more equations in a few days.
..
.

I thought more about the model I presented yesterday and I want to add some more ideas to that so I decided to write this post. Here is my motivation for making new changes.
1. local volatility continues to change remarkably during any trading day and we have to find a way to capture this change.
2. I wrongly stated yesterday that a low drift and relatively high volatility would imply mean-reversion. High volatility itself has nothing to do with mean reversion. But we know that there are times of high mean reversion in most financial asset price series. 
Therefore I decided to add a mean-reversion term to asset price dynamics where mean-reversion speed would be a slowly changing parameter that will  have its own hidden SDE. When stochastic slowly varying mean-reversion parameter would increase, it would decrease the effect of mean and the volatility even if they are both high enough. Now we will have two hidden processes, a time varying mean and a time varying mean-reversion speed  in our kalman filter and both these processes would have their own SDE dynamics. We have to add new framework while keeping the model as a tractable linear multivariate Kalman filter. 

We notice that asset price is fully observable while drift and mean-reversion are hidden variables and now we have three SDEs and we write them here. 
SDE we observe is given as
[$]X(t+1)=X(t)+ \, \mu(t) \, dt - \kappa(t) \, (X(t+1)-X(t)) \, dt+\sigma \, dz(t)[$]
In the above equation, I have given mean-reversion around [$]X(t-1)[$] with hidden mean-reversion speed [$]\kappa(t)[$]
or equivalently
[$]dX(t)=\, \mu(t) \, dt - \kappa(t) \, dX(t) \, dt+\sigma \, dz(t)[$]
I have not solved the above SDE since that would result in kappa appearing in exponentials and that would make the model non-tractable in state space form. We could possibly remain content with first order mean-reversion effect to keep the filter fast, simple and tractable besides time intervals would be reasonably small.

The above equation would be written in Kalman form as

[$]dX(t)=\, \mu(t) \, dt - \kappa(t) \, dX(t) \, dt+\sigma \, dz(t)[$]

while [$]\mu(t)[$] has its SDE given as
[$]\mu(t+1)=\mu(t) \, - \theta  \, \mu(t) \, dt+ \sigma_{\mu} \, dw(t)[$]

and simple  mean reversion sde could be written as
[$]\kappa(t+1)= \,  \kappa(t)+ \, \sigma_{\kappa} \, dv(t)[$]

The above three equations are in an exact linear Kalman filter form and therefore we can easily find the changing means, covariances and densities associated with hidden variables [$]\mu(t)[$] and [$]\kappa(t)[$].
Relative significance of [$]\mu(t)[$] and [$]\kappa(t)[$] especially in a multivariate framework would greatly help us in deciding what type of market regime(mean-reverting or trending) we are in and relative strength of market regime would help us decide what kind of trade has to be done to statistically make money in the market.
I have given mean-reversion around [$]X(t-1)[$] but you might want to change it to some weighted sum of previous few values of X(t). If a multivariate version with good specification of covariances could be properly calibrated, it will make a powerful filter that can be very helpful in automated algorithmic trading.
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 25th, 2021, 7:11 am

Friends, I had been thinking about the filtering model for statistical trading. I had a lot of interesting ideas and I want to share them with friends. 
First of all the model we want to develop could be used in for vanilla trading on a sub-minute scale to a few minutes scale(or much more as we will later see.) The model could also be used in an excellent fashion in pairs and relative value trading(in scalar and vector form for a group of several pairs simultaneously with covariances involved). 
1. We will start with a simple linear model, gain intuition, learn stylized facts a and then see if we need to extend it  to non-linear filtering models. Here I describe the model with SDEs(or an equivalent form in discrete state space version). First we take volatility constant and suppose that drift has its own dynamics dictated by another SDE. 
2. Since we are dealing with a level of minutes at maximum, we will not consider the asset dynamics as lognormal and just consider its noise as normal scaled by volatility. Our discrete time  spacing can range from five seconds to twenty seconds for vanilla trading. At this level, considering a lognormal SDE would be a bad choice.
3. since we are working/trading on a level of few minutes at max, units of time will not be years but rather possibly in minutes or hours.
4. In order to decrease noise due to bid-ask crossing, we will work with mid-prices.
5. drift cannot continue to increase so it must be slowly mean-reverting. 

Here is the SDE of financial asset or pair ratio
[$]X(t+1)=X(t) \,+ \mu(t) \, dt + \sigma \, dz(t)[$]
while [$]\mu(t)[$] has its SDE given as
[$]\mu(t+1)=\mu(t) \, - \theta  \, \mu(t) \, dt+ \sigma_{mu} dw(t)[$]

Keeping the SDE for drift the same, We can write the SDE for financial asset in returns form for the asset as
[$]dX(t)=\, \mu(t) \, dt + \sigma \, dz(t)[$]

If the model(SDEs and parameters) is well-specified, its variance with drift will be smaller than its variance without drift and if model is poorly specified, its variance will be larger as compared to without drift variance.
We notice that asset price is fully observable while drift is a hidden variable and the two SDEs are exactly in Gaussian Kalman filter form. I write the two SDEs again
[$]dX(t)= \, \mu(t) \, dt + \sigma \, dz(t)[$]
while [$]\mu(t)[$] has its SDE given as
[$]\mu(t+1)=\mu(t) \, - \theta  \, \mu(t) \, dt+ \sigma_{mu} dw(t)[$]

So we can use the huge literature and machinery developed for Kalman filter to solve this problem.
Returns of financial are highly notorious to defy attempts at finding structure but I am sure the above simple model would work successfully in a large number of cases in reality. With properly optimized parameters, The above model would continue to tell us when the drift is significantly different from zero and help us in trading decisions.
As I stated in my previous post, with a properly optimized model,  if the level of drift constantly stays insignificant and far smaller than volatility, we can say that we are in a mean-reverting regime and we need to trade accordingly. On the other hand, when the drift continues to remain in significant range, we can make directional trades according to short-term trend dictated by direction of drift.
Since we are in a Kalman filter mode, we can make our model very interesting by making it large dimensional and by adding covariances across different financial assets  and their drifts and the model will still remain robust and tractable.
I will be coming with worked out programs and more equations in a few days.
..
.

I thought more about the model I presented yesterday and I want to add some more ideas to that so I decided to write this post. Here is my motivation for making new changes.
1. local volatility continues to change remarkably during any trading day and we have to find a way to capture this change.
2. I wrongly stated yesterday that a low drift and relatively high volatility would imply mean-reversion. High volatility itself has nothing to do with mean reversion. But we know that there are times of high mean reversion in most financial asset price series. 
Therefore I decided to add a mean-reversion term to asset price dynamics where mean-reversion speed would be a slowly changing parameter that will  have its own hidden SDE. When stochastic slowly varying mean-reversion parameter would increase, it would decrease the effect of mean and the volatility even if they are both high enough. Now we will have two hidden processes, a time varying mean and a time varying mean-reversion speed  in our kalman filter and both these processes would have their own SDE dynamics. We have to add new framework while keeping the model as a tractable linear multivariate Kalman filter. 

We notice that asset price is fully observable while drift and mean-reversion are hidden variables and now we have three SDEs and we write them here. 
SDE we observe is given as
[$]X(t+1)=X(t)+ \, \mu(t) \, dt - \kappa(t) \, (X(t+1)-X(t)) \, dt+\sigma \, dz(t)[$]
In the above equation, I have given mean-reversion around [$]X(t-1)[$] with hidden mean-reversion speed [$]\kappa(t)[$]
or equivalently
[$]dX(t)=\, \mu(t) \, dt - \kappa(t) \, dX(t) \, dt+\sigma \, dz(t)[$]
I have not solved the above SDE since that would result in kappa appearing in exponentials and that would make the model non-tractable in state space form. We could possibly remain content with first order mean-reversion effect to keep the filter fast, simple and tractable besides time intervals would be reasonably small.

The above equation would be written in Kalman form as

[$]dX(t)=\, \mu(t) \, dt - \kappa(t) \, dX(t) \, dt+\sigma \, dz(t)[$]

while [$]\mu(t)[$] has its SDE given as
[$]\mu(t+1)=\mu(t) \, - \theta  \, \mu(t) \, dt+ \sigma_{\mu} \, dw(t)[$]

and simple  mean reversion sde could be written as
[$]\kappa(t+1)= \,  \kappa(t)+ \, \sigma_{\kappa} \, dv(t)[$]

The above three equations are in an exact linear Kalman filter form and therefore we can easily find the changing means, covariances and densities associated with hidden variables [$]\mu(t)[$] and [$]\kappa(t)[$].
Relative significance of [$]\mu(t)[$] and [$]\kappa(t)[$] especially in a multivariate framework would greatly help us in deciding what type of market regime(mean-reverting or trending) we are in and relative strength of market regime would help us decide what kind of trade has to be done to statistically make money in the market.
I have given mean-reversion around [$]X(t-1)[$] but you might want to change it to some weighted sum of previous few values of X(t). If a multivariate version with good specification of covariances could be properly calibrated, it will make a powerful filter that can be very helpful in automated algorithmic trading.
..
.

For pairs trading and many fixed income relative value trades, it would be more interesting to have simple mean-reversion type models where mean reversion is a slowly changing stochastic parameter and find it using Kalman filtering. In that case our simple SDEs for Kalman filtering would be usually simpler since we would not need the stochastic mean as a hidden variable(though sometimes you would still need both a stochastic mean and stochastic mean-reversion)

[$]dX(t)=\, \kappa(t) \, (\theta \, - \,X(t) \, dt+\sigma \, dz(t)[$]

and simple  mean reversion sde could be written as
[$]\kappa(t+1)= \,  \kappa(t)+ \, \sigma_{\kappa} \, dv(t)[$]

We suppose that theta is approximately known and we have done some research about it though a robust model may not greatly depend on mean reversion target and stochastic kappa would adjust for minor changes in it. So in pairs trading and relative value trades, when kappa is significantly positive, we will know that our pair is converging towards the specified mean reversion target and when kappa is significantly negative, we will know that our pair is diverging away from the mean reversion target. And we would be able to finesse our strategies according to prevailing mean-reversion speed, kappa.
In large fixed income relative value portfolios, we could easily do a  high dimensional kalman filter of rates with proper specification of covariances and appropriate calibration  and that would greatly help in understanding how rates are changing and we could calculate sensitivities of portfolio with respect to stochastic mean reversion and use that information for trading decision making and risk management. It would also be very useful information in interest options, swaptions and exotic interest derivatives risk management.
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 26th, 2021, 9:11 am

Friends, I had an antipsychotic injection yesterday and next week will be difficult. Antipsychotic injections are a big problem and I remain mentally stunted for a week after I get the injections. But I can still continue to work with them especially a week after I get the injection. But bad people who are embarrassed by my doing good work and  bent on retarding me somehow now bitterly want to end the injections and put me on daily antipsychotic medication so, every few days, they can add different mind control chemicals in the medicine tailored to particular neurotransmitters I have in my mind to control my changing neurotransmitters and successfully stop me from doing any productive work. 
I want to request American friends who helped me so many times in the past by forcing mind control agencies to be better to please protest to mind control agencies against putting me on antipsychotics forcefully despite that everybody knows that I am perfectly mentally healthy. Please ask the mind control agencies to refrain from putting me on daily oral medication (that would surely be contaminated on a regular basis to add mind control chemicals in it so that work of mind control agencies becomes easy and simple.) Though injections are difficult and hard for me, daily oral medication will be extremely tough and far more difficult if they would add mind control chemicals to that on a regular basis. I am in Lahore and my psychiatrist is in Islamabad and we would have a whatsapp meeting in a few days. I want to request good people and foreign embassies in Pakistan to please record my conversation with the psychiatrist and you would surely know that he would unduly insist on ending injections and putting me on daily medication despite that I remain very nice and perfectly amicable with my family and others(as I always was even when not on medications) and keep taking food from home to debunk the accusations that I am psychologically afraid of taking food at home. Friends would know that doctor would bitterly insist on daily medication as instructed to him by crooks in army.
I again want to request good Americans to please forcefully protest to American government against my persecution and I also want to request embassies of good European countries to protest to civilian Pakistani government(that just want wants to please army crooks to remain in power) against my inhuman persecution in Pakistan.
 
User avatar
Amin
Topic Author
Posts: 2760
Joined: July 14th, 2002, 3:00 am

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

May 27th, 2021, 9:28 am

Friends, I had been thinking about the filtering model for statistical trading. I had a lot of interesting ideas and I want to share them with friends. 
First of all the model we want to develop could be used in for vanilla trading on a sub-minute scale to a few minutes scale(or much more as we will later see.) The model could also be used in an excellent fashion in pairs and relative value trading(in scalar and vector form for a group of several pairs simultaneously with covariances involved). 
1. We will start with a simple linear model, gain intuition, learn stylized facts a and then see if we need to extend it  to non-linear filtering models. Here I describe the model with SDEs(or an equivalent form in discrete state space version). First we take volatility constant and suppose that drift has its own dynamics dictated by another SDE. 
2. Since we are dealing with a level of minutes at maximum, we will not consider the asset dynamics as lognormal and just consider its noise as normal scaled by volatility. Our discrete time  spacing can range from five seconds to twenty seconds for vanilla trading. At this level, considering a lognormal SDE would be a bad choice.
3. since we are working/trading on a level of few minutes at max, units of time will not be years but rather possibly in minutes or hours.
4. In order to decrease noise due to bid-ask crossing, we will work with mid-prices.
5. drift cannot continue to increase so it must be slowly mean-reverting. 

Here is the SDE of financial asset or pair ratio
[$]X(t+1)=X(t) \,+ \mu(t) \, dt + \sigma \, dz(t)[$]
while [$]\mu(t)[$] has its SDE given as
[$]\mu(t+1)=\mu(t) \, - \theta  \, \mu(t) \, dt+ \sigma_{mu} dw(t)[$]

Keeping the SDE for drift the same, We can write the SDE for financial asset in returns form for the asset as
[$]dX(t)=\, \mu(t) \, dt + \sigma \, dz(t)[$]

If the model(SDEs and parameters) is well-specified, its variance with drift will be smaller than its variance without drift and if model is poorly specified, its variance will be larger as compared to without drift variance.
We notice that asset price is fully observable while drift is a hidden variable and the two SDEs are exactly in Gaussian Kalman filter form. I write the two SDEs again
[$]dX(t)= \, \mu(t) \, dt + \sigma \, dz(t)[$]
while [$]\mu(t)[$] has its SDE given as
[$]\mu(t+1)=\mu(t) \, - \theta  \, \mu(t) \, dt+ \sigma_{mu} dw(t)[$]

So we can use the huge literature and machinery developed for Kalman filter to solve this problem.
Returns of financial are highly notorious to defy attempts at finding structure but I am sure the above simple model would work successfully in a large number of cases in reality. With properly optimized parameters, The above model would continue to tell us when the drift is significantly different from zero and help us in trading decisions.
As I stated in my previous post, with a properly optimized model,  if the level of drift constantly stays insignificant and far smaller than volatility, we can say that we are in a mean-reverting regime and we need to trade accordingly. On the other hand, when the drift continues to remain in significant range, we can make directional trades according to short-term trend dictated by direction of drift.
Since we are in a Kalman filter mode, we can make our model very interesting by making it large dimensional and by adding covariances across different financial assets  and their drifts and the model will still remain robust and tractable.
I will be coming with worked out programs and more equations in a few days.
In the above post, I have hinted at high dimension Kalman filter with a hidden vector process of drift but even if we make the drift stochastic, volatility would still not be constant and would continue to remain stochastic and I was thinking of simpler ways to factor in the effect of changing volatility.
In the equation below upper case bold letters represent matrices, lower case bold letters represent vectors and non-bold lower case represent scalars. Writing the observation equation for the financial asset, we have
[$]\textbf{dx(t)} \, = \, \boldsymbol{\mu(t)} \, dt \, +  \eta \, \boldsymbol{R \, z_1(t)} \, +  \,  \boldsymbol{\Sigma \, z_2(t)} [$]
In hte above equation scalar [$]\eta[$] is a single dimensional hidden variable with its own hidden state space dynamics and total noise variance that enters the observation equation now becomes  [$]{\eta}^2 \boldsymbol{RR' \,+\, \Sigma {\Sigma}' }[$]. The matrices [$]\boldsymbol{R}[$]  and  [$]\boldsymbol{\Sigma}[$] are kept constant and have been pre-calculated in the optimization phase. So we have a constant variance and there is a time changing variance that is scaled by a single hidden parameter  [$]\eta[$]  that has its own dynamics.
So we can write the filtering equations as
[$]\textbf{dx(t)} \, = \, \boldsymbol{\mu(t)} \, dt \, +  \eta \, \boldsymbol{R \, z_1(t)} \, +  \,  \boldsymbol{\Sigma \, z_2(t)} [$]

[$]\boldsymbol{\mu(t+1)}=\boldsymbol{\mu(t)} \, - \boldsymbol{\Theta  \, \mu(t) }\, dt+ \boldsymbol{\sigma_{mu} \, w(t)}[$]

and scalar [$]\eta[$] process follows its own simple dynamics as

[$]\eta(t+1)=\eta(t) \, - \theta  \, \eta(t) \, dt+ \sigma_{eta} v(t)[$]

due to [$]\eta[$] this filter will not be a kalman filter and will require some hack to solve this intelligently somehow. This may not be extremely difficult since we kept it as a single dimensional variable in a large vector-matrix system.

We could try other recipes for variance by choosing  [$]eta[$]  as the scalar magnitude of largest stochastic eigenvalue with a system of the sort like
[$]\textbf{dx(t)} \, = \, \boldsymbol{\mu(t)} \, dt \, +  \eta_1 \, \boldsymbol{r_1} \, z_1(t) \,+  \eta_2 \, \boldsymbol{r_2} \, z_2(t) \, +  \,  \boldsymbol{\Sigma \, z_3(t)} [$]