Serving the Quantitative Finance Community

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

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

January 22nd, 2023, 6:44 am

Sorry Doubled.

Friends, in a previous post I told friends how staff at a lady psychiatrist's hospital started beating me and abused me. During past twenty three years, there have been many many instances of my obvious abuse by different psychiatrists. I will describe some of those instances in this post.
When I came from United States and till fifteen years after that, my father would proudly ask me that I could see any psychiatrist I wish. This was because Pakistan army was managing my persecution and they would force psychiatrists to declare me schizophrenic and my father was told that every psychiatrist would be forced to cooperate. However, by chance in 2016, I came  across a psychiatrist who was far better. I never told him that I was under mind control but whenever he interviewed me, he always said after the interview that I was perfectly sane and mentally healthy. When my family would force him to increase the dosage of antipsychotics, the doctor first told me that I should not live with my family and make a comprehensive plan to support myself and become independent (such a plan could never work since Pakistan army was threatening people in Pakistan to not give me any business and CIA was making sure that every contact I would reach for work in Europe (and Singapore/ Japan /Australia) would be approached by CIA telling them that I was a very bad guy and they must not do business with me. I had not told the doctor any such thing that intelligence agencies were after me.)  When I told the good doctor how previous psychiatrists had abused me, he would tell me that this used to be a very widespread practice in America hundred years ago to wrong mentally healthy humans by using corrupt psychiatrists as instruments to detain them and strip them of their sanity. The good doctor I am talking about was American national with Pakistan background who had practiced psychiatry in America for over twenty years and had returned to Pakistan. That good doctor kept me on very low antipsychotics (1 mg resperidone per day) and that too on extreme insistence of my family. It was only during that time of treatment by that doctor that I got my first break in research and I solved the problem of high order monte carlo simulations (and analytic series solution of ODEs)  and posted that solution on this thread. Ok, when my family was fed with the doctor, they detained me with another doctor. They detained me again two years ago when I requested my family that I wanted to see the same doctor of my choice again( I have been detained every year for past six or seven years by different doctors), they detained me through a different doctor. So my family now stubbornly refuses to allow me to see a professional qualified American psychiatrist of my own choice and detains me every time I try to approach him.
Now back to my obvious abuse by two other psychiatrists. I was detained by this doctor who was running a mental health facility and was not a psychiatrist himself. At that time I did not use to walk very much and my blood pressure used to be somewhat high. Since other antipsychotics had failed to retard me, doctor suggested I take aripperizole injections. These injections affect the heart and also elevate blood pressure but doctor who wanted to retard me had no regard for my health while pretending to cure me. In initial days of my detention, staff at the hospital when checked my blood pressure told me high enough blood pressure in line with what I used to have but after I complained about aripperizole and its effect on blood pressure the staff started doctoring blood pressure and started telling me that my blood pressure was very good or even low. This is a post I wrote on another thread in this forum about it. How to safeguard my research - Page 32 - wilmott.com
.

Amin:

Since I wrote about high blood pressure and mentioned high blood pressure before the hospital staff, they have started to doctor blood pressure. Now, everyday they tell me that my blood pressure is 120/80 or 110/70. While they always told me that my blood pressure was 130/90 or 140/100 prior to injections. I have never had so good blood pressure for years that they have started to tell me now. Friends would recall a previous post when I could not sleep at night and had to take a sleeping pill. When the dispenser came to me at night(The hospital has no MBBS who stays here at night in Ramadan. Dr. AS used to stay here on some nights earlier but has been totally absent in Ramadan). When the dispenser checked my blood pressure, he told me that it upper blood pressure is 110. I did not believe him at all. He asked me to check on my own and put the stethoscope head assembly in my ears. I could easily tell that upper blood pressure was more than 140 and lower was more than 100. The staff has already started to doctor blood pressure. My parents are going to Saudi Arabia for two weeks in a few days. Now Dr. AS has the plan to hold me in detention while my parents are abroad. I had a complete settlement with Dr. N and we(I and the doctor N) both agreed that I would be visiting him every fifteen days and all modalities were agreed. I do think as a patient it is my right to choose the psychiatrist and Dr. AS( who is incharge of facility Pav.) has no right to change the doctor after I have selected a psychiatrist and we both agree on terms of any treatment. Dr. AS has imposed another psychiatrist Dr. M who has not even seen me and has already started giving me injections and increased medicine without looking at my present condition. Dr. N had explicitly stated that I would be free to leave if it were his facility. Most major reason for detaining me now is that Dr.AS wants to continue to detain me while my parents are leaving for abroad for more than two weeks
.
Later after a few days, I was given a second aripperizole injection and released from detention. An injection was due every fifteen days. My parents were in Saudi Arabia and I was living with my sister. She insisted after fifteen days that I get a new aripperizole injection. I complained about too much side effects and other serious problems but my sister insisted that I must get the injection. She talked to another doctor and the doctor told her that if his blood pressure and pulse are fine, just give him the injection. I asked my sister that my blood pressure must be checked before I get the new injection. We went to a small hospital close to her house and when my blood pressure was checked my lower blood pressure was 110. The hospital staff recommended that I stay at the hospital in their care until my blood pressure decreases. It was a totally random blood perssure check. When hospital staff came to know that I had been given aripperizole injections, they told my sister to not give me those injections any more. My sister asked the staff to relieve me and we came home but I was not given aripperizole injections after that. 
But this is interesting that the psychiatrist was initially desperate to prescribe aripperizole despite that I had told him about my heart and blood pressure problems and his staff was asked to doctor blood pressure so that I would accept the injections.
Good thing is that only after stopping aripperizole, I started my treatment with good psychiatrist  doctor Naeem Aftab (who is an American national) and he gave me enough relief that I was able to get a break in my research and solve the problem of high order monte carlo simulations. I would always be thankful to Dr. Naeem Aftab for giving me relief at such a crucial point in my life.

Yet another experience for abuse was with a seasoned psychiatrist who is known for his connections with Pakistan army. When army dictator Pervaiz Musharraf ruled the country, he made this doctor the dean(president) of the university of health sciences which regulates most medical universities in Pakistan. He had treated me for three years in year 2001. He started my treatment without interviewing me and gave me electric shocks at the start to jumpstart the therapy. I was given electric shocks for fifteen days in early 2001. I still recall that doctor would place a wooden wedge between my teeth and then give me an injection and I still recall how numbness would move in my body from feet to the upper body after the injection. 
When going to that doctor's psychiatrist facility in 2001 I had to travel from Kot Addu to Rawalpindi. My family had given me some drug in my food and I became unconscious after an hour or so. I still recall how I was begging my younger brother to help me that I do not want to go anywhere and if he could help me but he like everybody else in the family refused. Slowly drug in food showed its effect and I have absolutely no memory of being taken in my father's car despite that it would have taken him at least eight hours to take me to Rawalpindi. Psychiatrist did not interview me and detained me and started giving me electric shocks. I still recall how I defecated in my bed there and they had to wash it. 
Anyway, I was taken to this psychiatrist in 2017 again. He was very clearly told that I had been given antipsychotic drug larjactil by another doctor and it backfired and I had extremely severe drug-induced jaundice. But the doctor was so haughty and cavalier and so desperate to retard me that he still insisted that I must get the same drug larjactil and said that it was not necessary that it would cause jaundice every time. Problem for the doctor was that most antipsychotics had failed to retard me and he wanted to give me some potent antipsychotic that had not been well-tried on me. Though the drug was given to me earlier and later discontinued, the doctor wanted to take his chances to retard me and he had no regard for my health. This doctor is a big crony of Pakistan army and really wanted to please the generals and therefore he decided to give me larjactil again. And as would already be obvious to most friends, after two weeks, I started to show all signs of drug-induced jaundice again and my body and eyes were all yellow. My Biluribin shot like anything. And it took more than two months to control jaundice after that. Though my biluribin came back to normal after two months, several less known enzymes in my liver remained disturbed for several years after that and continued to show as abnormal in my liver function test reports.
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: 2411
Joined: July 14th, 2002, 3:00 am

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

January 22nd, 2023, 6:45 am

I have been detained more than 30 times by various psychiatrists during past twenty-five years on orders of Pakistan Army.
Here, I will recall an incident eight years ago when I myself approached a lady psychiatrist for help and how she abused me, and her staff beat me for twenty minutes and then tied me and started my treatment with antipsychotics again. 
I am recalling this from early 2015. They had previously put me on extremely high antipsychotics and my creativity was all gone. I could barely do any intellectual work. At that time, I was able to convince my family to decrease the injections and they had agreed since I had already lost most of my creativity and intellectual capability. I think mind control agencies were also thinking that I had lost my creativity forever and they wanted to see if it was right time to decrease my drugs and still make sure that I would remain intellectually dull after injections had ended.
But I slowly started to work on my research and started to regain my brain. When mind control agencies realized that I had started to do better research, they asked my family to do something again to retard me. My father asked a self-stylized religious saint to come to our house and take care of me. He came to our house with one of his followers and told me that he wanted to give me injections and I would go to sleep for 24 hours, and they would take scans of my brain to treat me, but I continued to beg and plead him, and I was able to convince him to allow me to leave the home in my car. The supposed saint allowed me to leave since he was probably sure that he would get me later as I had no other place to go other than my home and, therefore, I was able to convince him to let me go outside. When I left the house, I made posts about the saint on at least two different forums from outside my house and pleaded for help. Enough people were following my story even at that time and the saint had to leave. I also called my father when I was outside and protested against this.
My family still remained very tense with me, and I was very afraid that they would force antipsychotics injections and mind control drugs on me therefore I stayed one night out of the home. Here is the post I made when I was away on April 14th, 2015, 2:09 pm
https://forum.wilmott.com/viewtopic.php?f=15&t=94796&start=315#p748191
"I am staying out of my home for the night since I had realized that my father will try to force me into detention again and I would request a court tomorrow for stay order to stop my father from hospitalizing me forcefully again and I would request the court that if there has to be a check on my mental health, it has to be done and investigated properly by a psychiatrist of my choice and I should remain free at the same time. I do not want to be at the mercy of my father's chosen psychiatrist as we saw in the past year that they continued to quote mental health laws and forcefully manipulate me into taking injections. If my father forcefully hospitalized me, I would be cutoff from the outer world and they would do whatever they like. My father's self-stylized saint(peer) had already hinted that he wanted to give me injections that would put me to sleep for 24 hours and he had no argument for my mental sickness at all.”

Next day, on April 15, 2015, I went to Lahore High Court to find some help but I was told that I had to submit an application that would be considered several weeks later when its turn would arrive. When I realized that there was no possibility of help from the court, I decided to see a psychiatrist on my own. I was driving in Garden town Lahore where I came across B**** psychiatric clinic and decided to see the psychiatrist Dr. N*** there. It was evening but the psychiatrist still not had arrived there. I waited for an hour in the reception and then had a consultation with her. I asked her to listen to my case carefully and then decide if I was sane enough and tell my parents about it. She said that I seemed perfectly fine and asked me that she wanted to hear what my family had to say. I agreed and took an appointment to visit her again at April 20, 2015. I took my mother on the planned day and my mother did not have anything decisive to say about any disease other than that I did not eat at home. The psychiatrist asked me to visit her after one week on 27 April 2015. The next week when I went again to visit the psychiatrist, on April 27, and was sitting in the waiting room so that I could visit the psychiatrist on my turn. Another lady who was a psychologist came to me and asked me to go with her in a different room to have a session with psychologist but I declined and said that I was only interested in seeing the psychiatrist who had promised to see me again the earlier week. After five minutes, at least four men came to the room and started besting me. They gave me slaps on my face with full force and gave me blows and they continued to do it for more than fifteen minutes. I had never been beaten like that ever before in my life. All this time, I was simply trying to raise my hand to somehow protect me. Since I was sitting on the sofa, only my face and head were the target of slaps and blows. They were very violent with all sort of slaps and blows on my face as I earlier mentioned that I was sitting and they were standing. . They literally continued to beat me and I continued to beg them to stop. After fifteen minutes of beating me, they tied my legs and lifted me and put me on a bed in a room in the psychiatrist facility and told me that doctor had gone to America and she could not see me. It was a complete lie and the psychiatrist was in her office and was interviewing other patients when I arrived. I continued to ask them to loosen the knots but they continued to make fun of me. I was totally surprised since Dr. N had behaved very nicely in the previous meeting held at 20th with my mother and myself and I was sure she would declare me mentally sane on this meeting. After I was kept tied for about half an hour, a new guard came and opened my hands and legs and said that they would keep me at the facility for three days. The next day my medication in the form of pills started and I was also given two more injections. I was given about nine pills at night and about eight pills in the morning. I was still not given the opportunity to meet the psychiatrist N, and I was told several different things by different people including that psychiatrist N had gone to America, and she had gone to Islamabad. About three days into my treatment, I saw through the glass walls that psychiatrist N was interviewing her clients in her office. After seven days, I was asked to meet psychiatrist N, and she said that she was unaware of the beating as she was in a meeting. Psychiatrist N also assured me that I had no schizophrenia and previous doctors had very wrongly diagnosed me but it was a case of some mania that she would properly treat this time.  Her staff continued to say that they were giving me drugs so that the effect of other drugs given to me by previous psychiatrists would decrease.

Before my computer was taken away from me, I was able to take notes for two days in the hospital on my computer that I write here. After first two days of medication, I was so extremely weak that I could barely walk and I had extreme difficulty speaking.

“My Diary for past two days.

4/27/2015
I had two sessions with the doctor N previously on the 20th of April and once before at 13 or 14th of April. I remained away from home during this time and second meeting on 20th of April, evening after the night when I remained away from home. I had told the doctor about my circumstances in the first meeting with her. She had said that I looked perfectly fine mentally but she needed to talk to my family. On 20th of April, I took my mother for a second joint session of myself and my and the psychiatrist said, after the meeting, that said she really could not call me schizophrenic but she needed one more sessions and asked me to come to her facility on 27th of April. 
When I arrived at the psychiatric facility, a psychologist had asked me to accompany her which I did and on the way to the her room, I asked for the reason, after which she replied that she wanted to take a session of mine. I told her that I already had a session with another psyc hologist and also with a psychiatrist so I would prefer to have a new session with the psychiatrist now. She agreed and I returned to the waiting room. I was sitting on a sofa in the waiting room on 27th at 8:00 PM (PST) in the line to see the psychiatrist when about five guards took control of me, while I was sitting on a sofa in the waiting room to see the doctor, and gave me an injection. I was beaten and my legs and hands were very strictly tied for more than hour. Though the doctor was in her consultation room and a lot of people were waiting to see her, I was told again and again that doctor was not present at the facility.
In the previous two sessions, she had given the impression I was healthy mentally but she used force without interviewing for the third time or seeing me and without requests to comply. If she was given any special information, she should have talked to me about it and she should have verified with me any change in circumstances.
One injection was given around 8 PM when I arrived for third session with the doctor N. I really think that the doctor was there since there was a large rush of visitors and her SUV was parked in the hospital but everybody among the staff continued to say that doctor did not come to the facility this evening.
I was kept tied for more than one hour. I was taken tied from the waiting room to my room. All these rooms have video cameras so you can ask Dr. N for a video of the events though she might make the excuse that cameras were not working. One of the staff had mentioned when they brought me into a patient room in the facility, that everything was watched by cameras.I would request people familiar with the matter to request her to show them footage of the cameras. Of course, there could be many excuses that cameras were not working but I insist that cameras were working.
Good Mental health facilities try to avoid treating humans like this.
Another injection was given at night before I slept. 
and my internet USB device was also taken. They simply took possession of everything out of my pockets and also took my laptop.
When I asked why they gave me injections, one of the staff told me you were ?hyper? and I was totally surprised since I was quietly sitting on the sofa in the waiting lounge for the doctor. I was told that I would stay in the hospital for three days. I am sure this matter can be resolved who is lying and who is truthful once you look apt video footage of cameras in most rooms.

4/28/2015
One injection was given in the morning. One injection was given around noon. All injections were IM (given in the muscle.)
Unknown pills(some pills in the morning +5 pills around noon + 3 pills at night) were given and I was told,? We will tell you know the names of these pills only when you leave.?
Computer was returned today but I was told that we did not take your mobile and they continued to say we never took my mobile. My mobile was never returned( despite I always keep my mobile on me.) 
I was also not given my EVO USB device and I was told you cannot write anything on internet. However the USB device was returned to my mother at night.
I was told today by the psychologist that doctor N had gone to America and will come back after seven days and only then she would be able to see you. I was told we are adjusting your medicine and see what was a good medicine. I was told they were discussing the drugs with her on phone and skype There were several conflicting statements about where Dr. N was. Somebody said she was just out of city and had gone to Islamabad.
When I asked my mother who is living with me at the hospital, I wanted a second opinion, because of beating and other irresponsible behavior of the psychiatrist, my mother would make all sort of excuses while the staff would say that you cannot leave the hospital until Dr. N arrives who is currently out of country.
Earlier today, I was told that I would live at the hospital for fifteen days and later I was told that I would live at the facility for seven days. When I was tied, somebody had told me that I would live in the hospital for three days only.
My mother told me please do not write anything wrong on internet otherwise, they would take your USB forcefully like Dr. A had done more than one year ago. The purpose was to threaten me to not write about any maltreatment so that the doctor would continue to freely manipulate me.
7-8 pills were given in the afternoon and similar number of pills were given at night. At many times during the day, I could barely walk and had extreme difficulty speaking.”
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: 2411
Joined: July 14th, 2002, 3:00 am

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

January 22nd, 2023, 6:49 am

My Letter To HRW About My Human Rights Abuse

Above is a very incomplete account of how various psychiatrists continued to play in hands of Pakistan army to retard me. It also does not cover all the time till year 2022 and the account stops several years earlier.
Pakistan Army has no personal animosity with me. Chief of Pakistan Army staff is given more than 50 billion rupees every year come rain or shine so that army continues American Mind control of intelligent people in Pakistan. Even when the relations between both countries are extremely bad, this bribe is always given to Pakistan army generals in time.

Before writing this post, I want to apologize to good jews but want to tell them there are enough evil jews who are doing everything to tarnish the great goodwill jews have so rightly earned through generations of hard work and being nice and kind to other people in the society. I want to request good jews to Please force these evil(jewish) people to end the bad practices that are starting to take root in American and other societies on their behest and before it is too late. I also really hope that my mind control would finally end(as I have been begging for past twenty years) and I would never have to write a post like this again.

In the past, I continued to mention about my mind control persecution from time to time but only started writing regularly about it when I arrived in UK on a Highly Skilled Migrant work visa. Mind control agencies did everything in their power to fail me in UK. People were asked to not give me a job. People I contacted were routinely told brazen lies about me totally shamelessly. When I realized that I had no future in UK, I returned to Pakistan after a six month stint in UK. Since my hard earned money had thoroughly insulted mind control infrastructure in UK as they had to drug entire cities with mind control chemicals in UK (read briefly about it in my application to HRW in a previous thread) for a nobody like me and American government had to move all their grand and influential puppets in UK (again for a nobody like me) to force people to drug the manufactured food. British Banks went to the extent to steal my money to bleed me. Read here: https://forum.wilmott.com/viewtopic.php?f=15&t=102298#p857494. British police forcefully stopped me from seeing law firms(Brief details are given in my application to HRW attached as a link below).  Since my money had given mind control agencies a very tough time, mind control agencies decided to never let me make significant money after that. My old Japanese employer was told to not hire me after I returned to Pakistan. Whoever I would contact someone in Europe for job or consulting, mind control agencies would move American embassy infrastructure in that country and somebody highly influential (or army or secret services of that particular country)  in that particular country would approach my target employer and again brazen lies and fabricated stories would be told about me shamelessly. I am a fighter in life and I continued my research despite all economic, coercive and other hardships. All odds were against me but I tried my best to continue.  I have been presenting my research to friends on this forum for past five or six years. At this point, I want to request good American and friends from other countries who have come to know me through my research to please use their influence to end my mind control forever.

Since things might heat up after my writing this and my persecution might increase, I want to ask European embassies in Pakistan to keep a vigil. I want to tell Europeans that my writing about mind control is in their great interest since the very same people who instigate retarding of intelligent muslims are behind retarding of dozens of intelligent europeans and once these people are exposed I am sure they will be far more careful in openly retarding European talent(that they do not like). 

I had told friends earlier that a jewish billionaire is Godfather of mind control. When my persecution started (in late 1997) at the university in New York which is a big time player in mind control of Muslims, blacks and foreigners, many university officials were very pleased that they were getting written in good books of the billionaire jewish Godfather. Though there are far richer billionaires in US who are staunchly opposed to mind control, they are not ready to shell out hundreds of millions of dollars to bribe anyone to end mind control while mind control Godfather continues to give large bribes to people to continue mind control. Many of the people related to defense in mind control are given extremely high paying jobs in Godfather and his other jewish friends' companies after they retire from mind control and Godfather is extremely generous towards them and it is well established and well known to people in mind control that after retarding muslims, blacks and others in their career, they will move to paradise after they retire. No wonder there is no let up in mind control whatever good people try.
We know in almost all classic folk lore stories evil is too strong and too sure of itself while good is mostly weak and just trying to protect itself from evil who is bent on damaging and eradicating the weak and the poor good but it is the weak and poor good that finally prevails. I want to tell good American friends that evil at this stage has become too bold and thousands of talented people are retarded every year. And it is just not muslims and blacks that are on the line, several hundreds of brilliant whites are retarded across United States by mind control agency every year that has become too emboldened due to lack of any accountability. Thousands of foreigners are also kept retarded in dozens of countries including many European countries. 
My only intention behind this post is that I want mind control to end from our societies. I do not have any joy in mentioning that there are some bad jewish actors behind it. In American society there are a large number of jews who have excelled in the professions of science, education, medicine and have made great contributions to our societies. There are a very large number of jewish professors each of whom would have taught tens of thousands of students on top of making extraordinary contributions to body of human knowledge through their great research. Then there are accomplished jewish scientists whose work, research and inventions make our everyday life better. There are great jewish doctors and surgeons who would treat countless sick people and make them recover from disease. The list of contributions of jewish people to humanity is very long and it continues. Then there are a large number of ordinary jewish folks who are known for their goodness and civility to other people in the society. When we know all of this, we do not want to say anything anti-jewish to hurt the feelings of so many good jewish people. But I still have to say there are really some bad people who are unconnected with most of the nice and accomplished jews and they instigate and continue cruel mind control torture on talented people of other ethnicities, religions and countries based on their personal dislike and hatred. My purpose is only to end the mind control victimization and torture on otherwise nice and talented people and I do not have any hidden intentions beyond that. And I am sure American society knows very well about the contributions of good Jews to both their country and broader humanity and my exposing some bad actors would never have any bad effect of any kind on these good and nice jews who we all respect and who are our role models.I want to tell friends something I have said before here that I am sure American society would eventually end the menace of mind control from their and other countries. I want to request all good Americans and Europeans to come forward and invite any investigative journalist you know to read my threads and ask them to help end the menace of mind control in our societies through their investigative journalism. Without any accountability evil will continue to grow stronger and then mind control would start to threaten even those people who consider themselves safe due to affiliations, status or wealth.
I want to request CNN, New York Times, Washington Post, Al-Jazeera 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. 
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.
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: 2411
Joined: July 14th, 2002, 3:00 am

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

January 22nd, 2023, 6:53 am

Friends, I have previously described several horror experiences with psychiatrists but there are many more such experiences that I have not posted on this thread. Today I am going to describe a continuing experience in which the psychiatrist did everything in his power to retard me.
This is from year 2004/2005. I had a sound logic at that time and I was working from Lahore at a job with a foreign Japanese company that was paying me $4000 per month. I was still on high antipsychotics and when high dosage of normal antipsychotics did not work, in order to retard me, the psychiatrist employed a procedure that is not known in psychiatric practice in any country. The psychiatrist would give me some drugs in a glucose drip every two/three days in the operation theater. When I would be given the glucose drip, I would gradually start to lose consciousness and when half of the drip bottle would have gone into my blood, I would literally be unconscious, and I would later be taken unconscious to my hospital bed by the hospital staff and I would wake up several hours later on the bed in my hospital room and I would be extremely weak. 
It was such a frightening experience that I would shudder from horror as the day of this treatment would come closer and continued to beg the psychiatrist to stop this treatment. The psychiatrist would say that he was giving me vitamins and vitamins were always harmless. He insisted that vitamins had to be given to me. He never told me what drugs he gave me that made me unconscious and never discussed it with me other than mentioning vitamins. The psychiatrist continued to perform this procedure for several weeks after sometimes second or usually third day. Most people cannot imagine how it would feel when the drug in glucose drip would go into my body and I would lose my senses. To this day I shudder from complete horror and recall the extremely sick feeling when I would slowly lose consciousness.
Now when I look back, I realize that they were giving me mind control drugs in the drip to take the intelligent neurotransmitters out of my body. They continued to try to take intelligent neurotransmitters out of my body again and again through this procedure for several weeks. I was completely helpless before my family and the psychiatrist and had to go through such unlawful medical procedures.
As friends would have realized that purpose of mind control agencies was always to retard me since neocon scumbags of pentagon and their backers were not capable of appreciating my humanity and did everything in their power to retard me with an iron fist. 
I have seen continuing pain, trauma and torture in my life only because I had some special neurotransmitters that people with hatred and venom were not ready to let me have since they considered it a threat to let a Muslim have those neurotransmitters.

After starting mind control in Lahore in early 2000's, bad jews (again apologies to good jews) were very emboldened how easy it was to manipulate army and government in Pakistan to start mind control of intelligent people in Pakistan. It was a time when Pervaiz Musharraf who was an army dictator ruled the country. He was very ready to please the CIA in order to get help from American army to prolong his illegal dictatorship in Pakistan. He fixed in place all the required mind control infrastructure in all large cities of Pakistan to please American army who was playing in hand of bad jews to damage the Muslim majority country.
When Americans rightly blame our country for terrorism, they must not forget that many neocon generals in American army have played in the hand of bad jews and have made every effort to systematically destroy talent in Pakistan on a very large scale using mind control technologies to keep it backward forever.
Mind control in Pakistan is ensured by top Pakistani army generals since they are given several hundred million dollars by US army every year and the top brass of Pakistan army divides this money among themselves with bigger fish getting larger share and smaller fish getting a smaller share. Therefore, mind control infrastructure in Pakistan is very detailed and thorough.
From my own experience, there is very large mind control activity in Lahore and Islamabad, the two cities where I have lived during the past twenty years. There are at least more than 500 mind control targets in Pakistan most of whom are computer science majors.
Mind control in Pakistan and many other places increased dramatically like never before. We have in Lahore a huge building called Arfa Towers where all the facilities for technology and IT companies were provided to attract new firms and entrepreneurs and later Arfa Towers became a scene of mind control carnage since tens of aspiring computer scientists and entrepreneurs were retarded and it became very easy for mind control agencies to find the talent since the facility attracted talent and retard it. Time between 2008 and 2016 was like black death for talent in technology in our country (I am not talking about pseudo-talent that American embassy continued to support and showcase heroically in the meantime.)  I still recoil with horror when I look back and recall how difficult it was to get good drinking water in Lahore during that time for more than six months in 2013-2014. I would have to go to remote parts of the city, go to villages around the city and sometimes even go to other cities and only then I would be able to get some good water after repeated attempts and my only worry during the day would be to somehow get good food and water.
At this point I like to tell friends that a lot of food and beverages that are drugged with mind control chemicals would be eaten or taken by most of the population that is not on mind control and they would never notice any anomaly in taste or any other effect since these mind control chemicals are inactive and inert and become chemically active only when targeted remotely with precise electromagnetic wave frequencies so only target victims are affected and this is a very cruel method to target intelligent people by drugging the entire supply of food and beverages and then focusing waves on the targeted individuals to activate the mind control chemicals. Pakistan army and mind control agencies would drug the entire public water supply and beverages knowing that the victim would have to drink something somewhere. Ground water is also so thoroughly drugged with mind control chemicals that entire public water supply of the city and several kilometers out of the city would be completely drugged with mind control chemicals. Pakistan army routinely does this in Lahore city on behest of American mind control agencies.
Ten years ago, army soldiers and agents would go to markets to drug the targeted food and beverages with mind control chemicals which they still. Large scale movements of soldiers and agents raise suspicions in general public and therefore mind control chemicals are supplied to beverage and food manufacturing companies in Pakistan, and they simply add the chemicals in food and beverages during the manufacturing process.
In Lahore city, there are more drugged beverages at any time than good beverages in small stores or large supermarkets alike since most of the beverages are drugged at manufacturing source by coca-cola, pepsi-cola and Nestle.
Coffee stimulates the brain and the brain connects in new ways after taking coffee and good coffee creates problems with keeping victims on mind control since their brain starts connecting in many new ways after taking good coffee. All coffee and I repeat that entire coffee in the country present in the stores is drugged with mind control chemicals. Most of the coffee on good stores is imported from foreign countries. I do not know how it works but importer is probably told by army to drug the imported coffee before distributing it in the market. It is even very difficult or rather impossible to get good coffee beans. Two or three years ago it was possible to find some brand of coffee that was good by trying all new brands but it has not worked for past two years now for me despite that I keep trying. I even know of instances that when I was able to buy good coffee of a certain brand from very large and posh stores, they took entire coffee brand off the shelf from all their branches within two to three days. People know that Corrupt Army in Pakistan that ensures mind control is more powerful than any political government here.
Tea used to be good but for past one year most mainstream Pakistani brands of black tea are drugged with mind control drugs. This has still not caught up thoroughly like coffee is thoroughly drugged and it is still possible to find some good foreign brands tea that is good.
All stimulant/energy drinks including red bull are well drugged at manufacturing source. Red bull was better till last year but then it became drugged everywhere. I even tried it at remote places in several cities other than Lahore and it has always been drugged lately.

Most of the soaps, shampoos, creams, toothpastes are drugged with mind control chemicals. I do not use shampoos or creams but whatever rare I tried them once in a while they were drugged and they charged my skin. All of these have mind control chemicals that charge the skin and make mind control extremely effective. Many people would be amazed when I tell them that even though I would be in my full senses before washing my head and face with a soap but after washing my head and face with a drugged soap, my eyesight would deteriorate and my conception of reality would completely change and sometimes I would face extreme anxiety. It is hard to emphasize that even a small thing like this can completely change the victim's state of mind and consciousness. Getting a good soap was very difficult for me till last year and I would drive for several hours in different parts of the city especially looking at all the pharmacies on the way to find some unknown brand or some soap that would have been manufactured several years ago when soaps were not getting completely drugged. I tried all the soaps including beauty soaps that are specially made for women, even many unknown brands, and specially imported soaps(which were all universally drugged thoroughly) and it was very very difficult to find a good soap. After finding a good soap, I would keep it in my pocket all the time. This is a small thing but you cannot live without it. Since our mouth is kept charged and some charges continue to go into victim's body from one's mouth. Therefore toothpastes are also added with mind control chemicals to charge inside of our mouth. You can imagine that after buying five or six tooth pastes of different remote brands, I would get a good tooth paste. I have recently been using toothpaste that is imported from abroad and is good. Toothpastes manufactured in Pakistan are all drugged with mind control chemicals. 
Another big problem is that pharmaceutical companies add mind control chemicals to their drugs(pills etc). Most of the mind control victims are targeted due to their talent and intelligence in mind many times might require special minerals that are rare in our food.  Most of the mineral and vitamin formulas are also drugged with mind control chemicals. Most mainstream mineral and vitamin pills in the market are thoroughly drugged with mind control chemicals. I never like to take names but I would like to tell friends that greatest crook of all times is Glaxosmithkline( I would invite them to sue me for writing this on Wilmott). GSK's mineral and vitamin formulas, effervescent calcium tablets, and toothpastes are all drugged with mind control chemicals. There is a tablet by the name Kemadrin that has to be taken with antipsychotics and GSK manufactures it and it is also drugged with mind control chemicals. My experience with GSK is so bad that If I have to buy any medicine and if it is made by GSK, I would try my utmost to avoid taking it for the fear of its being drugged with mind control chemicals and look for alternatives.
Injection fluanxol and clopixol are also drugged with mind control chemicals.
Again all this thorough infrastructure took more than fifteen years to develop in Pakistan and Pakistan army continued to work hard to develop it over the years. There are at least five hundred brilliant Pakistanis most of whom are computer scientists who are on active mind control to thwart them to contribute to society in any good way. 
All this infrastructure exists in Pakistan and was developed because neocon generals wanted to please bad but rich jews and American mind control agencies continue to perfect it over last twenty years. Again, mind control in Pakistan is ensured by top Pakistani army generals since they are given several hundred million dollars by US army
I have not talked about special infrastructure that is used to project EM waves on the target and this infrastructure is present on all major roads and public places in big cities and major highways and motorways in the country.
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: 2411
Joined: July 14th, 2002, 3:00 am

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

January 22nd, 2023, 12:59 pm

Friends, I did a two year monte carlo simulation in a stochastic volatility model. And took eight snapshots of density of stock and stochastic variance at .25 year intervals. Red line in graphs is density constructed from Z-series coeffs using hermite inner product method and green line is direct bin density. I used two million paths. The Z-series density construction within simulation works seemlessly as you can see in the graph. I conceived this method just last night and went ahead and programmed it. I am sure if there are any minor problems, we would be able to resolve them. Here are the graphs.
I would post Matlab program used to construct these graphs in twenty minutes and will come back with another post later tonight explaining the analytics of the method with latex equations.
Good thing is that we can calculate the Z-series coeffs within simulation and do all sort of variance calculations for var derivatives and also do hermite wise correlations and regressions all within monte carlo framework. However the current matlab program only calculates the Z-series density within simulation using hermite inner products with the SDE variable data.
Here are the SDEs of stock process and stochastic variance process.

dVt=kappa *(theta - Vt)*dt+sigma0 * Vt^gamma * dz1(t)
Xt(0)=x0
dXt=kappaX * (thetaX - Xt )*dt+sigmaX* Vt^gammaV * Xt^gammaX *dz2(t);
<dz1(t),dz2(t)>=rho *dt
in simulations below kappaX is zero.
Here are the stock and stochastic variance graphs at intervals of .25 years.
.
.
Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

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: 2411
Joined: July 14th, 2002, 3:00 am

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

January 22nd, 2023, 1:33 pm

Here is the program used to construct above graphs with all its auxiliary functions.
The program takes a small step and stops after every .25 years to construct the asset density and stochastic variance density. I am giving Z-series Coeffs that you get when program stops after one year (the 4th time).
You will get the following coeffs for asset density 
ch0 =

   1.000504293954663


ch =

   0.387944879882010   0.019230128572635   0.000494145447108   0.001588525145643  -0.000062189649459   0.000006642248086   0.000004857389595


c0 =

   0.985940107097660


c =

   0.385019572891282   0.009997878862670   0.001626067849219   0.001488891424346  -0.000164194830963   0.000006642248086   0.000004857389595

And the following coeffs for variance density.

dh0 =

   0.113983075015833

dh =

   0.082903984760398   0.034457076958627   0.010065124779018   0.001985239782762   0.000244600151872  -0.000018504490563  -0.000026167026254


d0 =

   0.085759284763932


d =

   0.059125150458094   0.021712936186735   0.004871585503626   0.002262807141202   0.000794107703207  -0.000018504490563  -0.000026167026254



Please enjoy the program.

.
.
function [] = SVMonteCarloDensity()

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


dt=.125/2/2/2;   % Simulation time interval.%Fodiffusions close to zero
             %decrease dt for accuracy.
Tt=128;%64*4*2;%16*2*4;%*4*4*1;%*4;%128*2*2*2;     % Number of simulation levels. Terminal time= Tt*dt; //.125/32*32*16=2 year; 
T=Tt*dt;

if(T>=1)
dtM=1/32;;
TtM=T/dtM;
else
dtM=T/32;
TtM=T/dtM;
end




v00=.250;   % starting value of SDE
beta1=0.0;
beta2=1.0;   % Second drift term power.
gamma=.950;%50;   % volatility power.                                                                                                                                                                                                                                                                     
kappa=1.50;%.950;   %mean reversion parameter.
theta=.075;%mean reversion target
sigma0=.9500;%Volatility value

%you can specify any general mu1 and mu2 and beta1 and beta2.
mu1=1*theta*kappa;   %first drift coefficient.
mu2=-1*kappa;    % Second drift coefficient.


%dVt=(mu1*Vt^beta1 + mu2*Vt^beta2)*dt+sigma0 * Vt^gamma * dz1(t)
%Xt(0)=x0
%dXt=(mu1X*Xt^alpha1+mu2X*Xt^alpha2)*dt+sigmaX* Vt^gammaV * Xt^gammaX *dz2(t);
%<dz1(t),dz2(t)>=rho *dt

x0=1.00;
gammaX=.65;
sigmaX=1.0;
thetaX=.50;
kappaX=0.0;
mu1X=thetaX*kappaX;
mu2X=-1*kappaX;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%rng(29079137, 'twister')
rng(15898837, 'twister')
paths=2000000;
V(1:paths)=v00;  %Original process monte carlo.
X=0.0;
X(1:paths)=x0;
alpha1=0;
alpha2=1;
a=mu1X;
b=mu2X;
rho=-.5;
sigma1=sigmaX;
gammaV=.5;
Random1(1:paths)=0;
Random2(1:paths)=0;

for ttM=1:TtM
Random1=randn(size(Random1));
Random2=randn(size(Random2));

time1=ttM*dtM

X(1:paths)=X(1:paths)+ ...
    (a* X(1:paths).^alpha1 + b* X(1:paths).^alpha2)* dtM + ...
    sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*Random1(1:paths) * sqrt(dtM) + ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*Random2(1:paths)*sqrt(dtM) + ...
    (a*alpha1* X(1:paths).^(alpha1-1)+b*alpha2* X(1:paths).^(alpha2-1)).* ...
    (((a* X(1:paths).^alpha1 + b* X(1:paths).^alpha2)* dtM^2/2)+ ...
    (sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*Random1(1:paths) *(1-1/sqrt(3)).*dtM^1.5+ ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*Random2(1:paths)*(1-1/sqrt(3)).*dtM^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)) *dtM^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).* dtM^1.5 + ...
    sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*(Random1(1:paths).^2-1) * dtM/2 + ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*Random1(1:paths).*Random2(1:paths)*dtM/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).*dtM^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).* dtM^1.5 + ...
    sigma0*V(1:paths).^gamma.*Random1(1:paths).*Random2(1:paths)*dtM/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)*dtM^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)*dtM^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).* dtM^1.5 + ...
    sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*Random1(1:paths).*Random2(1:paths) * dtM/2 + ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*(Random2(1:paths).^2-1)*dtM/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).*dtM^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).* dtM^1.5 + ...
    sigma0*V(1:paths).^gamma.*(Random2(1:paths).^2-1)*dtM/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).* dtM^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)*dtM^1.5;
X(X<0)=.0000001;
if(rem(ttM,8)==0) %On every eighth monte carlo step construct the density

MaxCutOff=100;
NoOfBins=200;
[XDensity,IndexOutX,IndexMaxX] = MakeDensityFromSimulation_Infiniti_NEW(X,paths,NoOfBins,MaxCutOff );

SeriesOrder=7;
NoOfBins=200;
MaxCutOff=9999999;
%Below function finds hermite coefficients of monte carlo simulated SDE
%of the stock asset.
[ch0,ch] = FindHermiteCoefficientsFromSimulation_Infiniti_NEW(X,paths,NoOfBins,MaxCutOff );
[c0,c] = ConvertHCoeffsToZCoeffs(ch0,ch,7);
ch0
ch
c0
c
str=input('Look at Coeffs of Z-series of stock SDE')

%Below construct density on Gaussian grid.
%First calculate normal random variable on a grid below
dNn=.1/2;   % Normal density subdivisions width. would change with number of subdivisions
Nn=45*4;  % No of normal density subdivisions
NnMid=((1+Nn)/2)*dNn;
Z(1:Nn)=(((1:Nn)*dNn)-NnMid);
%Z
%str=input('Look at Z');
%Now calculate Y as a function of normal random variable.
Y(1:Nn)=c0;
for nn=1:SeriesOrder
    Y(1:Nn)=Y(1:Nn)+c(nn)*Z(1:Nn).^nn;
end

%Now take change of densities derivative of Y with respect to normal
DfY(1:Nn)=0;
for nn=2:Nn-1
    DfY(nn) = (Y(nn + 1) - Y(nn - 1))/(Z(nn + 1) - Z(nn - 1));
    %Change of variable derivative for densities
end
DfY(Nn)=DfY(Nn-1);
DfY(1)=DfY(2);

%Now calculate the density of Y from density of normal random variable
%using change of probability derivative.
pY(1:Nn)=0;
for nn = 1:Nn    
    pY(nn) = (normpdf(Z(nn),0, 1))/abs(DfY(nn));
end

plot(Y(1:Nn),pY(1:Nn),'r',IndexOutX(1:IndexMaxX),XDensity(1:IndexMaxX),'g');

title(sprintf('Stock Density: x0 = %.2f,thetaX=%.2f,kappaX=%.2f,gammaX=%.2f,sigmaX=%.2f,rho=%.2f,v0 =%.2f,kappa=%.2f,theta=%.2f,gamma=%.2f,sigma0=%.2f,T=%.2f,dt=%.3f',x0,thetaX,kappaX,gammaX,sigmaX,rho,v00,kappa,theta,gamma,sigma0,time1,dtM));
legend({'Z-Series Density of Stock From Hermite Polynomials','Monte Carlo Density'},'Location','northeast')

str=input('Look at density of stock from simulated data. From Z-series Coefficients in red, Directly from data in green');
end

VBefore=V;

    V(1:paths)=V(1:paths)+ ...
        (mu1.*V(1:paths).^beta1 + mu2.*V(1:paths).^beta2)*dtM + ...
        sigma0*V(1:paths).^gamma .*Random2(1:paths)*sqrt(dtM) + ...
        (mu1.*beta1*V(1:paths).^(beta1-1) + mu2.*beta2.*V(1:paths).^(beta2-1)).* ...
        ((mu1.*V(1:paths).^beta1 + mu2.*V(1:paths).^beta2)*dtM^2/2 + ...
        sigma0*V(1:paths).^gamma .*Random2(1:paths)*(1-1/sqrt(3))*dtM^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).*dtM^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)*dtM^1.5 + ...
        sigma0.*V(1:paths).^gamma .*(Random2(1:paths).^2-1)*dtM/2) + ...
        .5*sigma0*gamma*(gamma-1).*V(1:paths).^(gamma-2) .* ...
        sigma0^2.*V(1:paths).^(2*gamma) .*Random2(1:paths).*1/sqrt(3)*dtM^1.5;


if(rem(ttM,8)==0)    
V(V<=0)=.0000001;
MaxCutOff=100;
NoOfBins=1000;
[VDensity,IndexOutV,IndexMaxV] = MakeDensityFromSimulation_Infiniti_NEW(V,paths,NoOfBins,MaxCutOff );
%Below function finds hermite coefficients of monte carlo simulated SDE
%of stochastic variance.
NoOfBins=400;
MaxCutOff=9999999;
[dh0,dh] = FindHermiteCoefficientsFromSimulation_Infiniti_NEW(V,paths,NoOfBins,MaxCutOff );

[d0,d] = ConvertHCoeffsToZCoeffs(dh0,dh,7);
dh0
dh
d0
d
str=input('Look at Coeffs of stochastic variance Z-Series')


%Below construct variance density on Gaussian grid.
%First calculate normal random variable on a grid below
dNn=.1/2;   % Normal density subdivisions width. would change with number of subdivisions
Nn=45*4;  % No of normal density subdivisions
NnMid=((1+Nn)/2)*dNn;
Z(1:Nn)=(((1:Nn)*dNn)-NnMid);
%Z
%str=input('Look at Z');
%Now calculate Y as a function of normal random variable.
Y(1:Nn)=d0;
for nn=1:SeriesOrder
    Y(1:Nn)=Y(1:Nn)+d(nn)*Z(1:Nn).^nn;
end

%Now take change of densities derivative of Y with respect to normal
DfY(1:Nn)=0;
for nn=2:Nn-1
    DfY(nn) = (Y(nn + 1) - Y(nn - 1))/(Z(nn + 1) - Z(nn - 1));
    %Change of variable derivative for densities
end
DfY(Nn)=DfY(Nn-1);
DfY(1)=DfY(2);

%Now calculate the density of Y from density of normal random variable
%using change of probability derivative.
pY(1:Nn)=0;
for nn = 1:Nn    
    pY(nn) = (normpdf(Z(nn),0, 1))/abs(DfY(nn));
end
plot(Y(1:Nn),pY(1:Nn),'r',IndexOutV(1:IndexMaxV),VDensity(1:IndexMaxV),'g');
legend({'Z-Series Density From Hermite Polynomials','Monte Carlo Density'},'Location','northeast')
title(sprintf('Variance Density: v0 =%.2f,kappa=%.2f,theta=%.2f,gamma=%.2f,sigma0=%.2f,T=%.2f,dt=%.3f',v00,kappa,theta,gamma,sigma0,time1,dtM));

str=input('Look at density of volatility from simulated data. From Z-series Coefficients in red and directly from data in green');    
end    

    
end

%SVolMeanAnalytic=thetaV+(V0-thetaV)*exp(-kappaV*dt*Tt)
SVolMeanAnalytic=theta+(v00-theta)*exp(-kappa*dt*Tt)
SVolMeanMC=sum(V(1:paths))/paths
AssetMeanAnalytic=x0
AssetMeanMC=sum(X(1:paths))/paths



end
.
.
The following function is responsible for calculation of hermite coeffs with hermite inner product method. I will give detailed equations in a few hours. These hermite coeffs can later be converted to Z-series coeffs for density construction.
.
function [ch0,ch] = FindHermiteCoefficientsFromSimulation_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=999999;
Xmin1=999999;
Xmin2=999999;
Xmax=0;
Xmax1=0;
Xmax2=0;
mean=0;
for p=1:Paths
%if(X(p)>MaxCutOff)
%X(p)=MaxCutOff;
%end
%if(X(p)<0)
%X(p)=0;
%end
mean=mean+X(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
end


%Xmin
%Xmin1
%Xmin2

%Xmax
%Xmax1
%Xmax2
%str=input('Look at Xmin and Xmax');
%IndexMax=NoOfBins+1;
BinSize=(Xmax2-Xmin2)/NoOfBins;
%IndexMax=floor((Xmax-Xmin)/BinSize+.5)+1
IndexMax=floor((Xmax2-Xmin2)/BinSize+.5)+1

XDensity(1:IndexMax)=0.0;

for p=1:Paths
index=real(floor(real(X(p)-Xmin2)/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;
XDensity(index)=XDensity(index)+1.0/Paths;

end

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

XCDF(1:IndexMax)=0;
Z(1:IndexMax)=0;
XCDF(1)=XDensity(1)*.5;
for nn=2:IndexMax
    XCDF(nn)=XCDF(nn-1)+XDensity(nn-1)*.5+XDensity(nn)*.5;
    Z(nn)=norminv(XCDF(nn));
end

%XCDF
%Z

%str=input('Look at XCDF and Z');


ch0=mean;
ch(1:7)=0;
for nn=1:IndexMax
ch(1)=ch(1)+IndexOut(nn).*Z(nn).*XDensity(nn);
ch(2)=ch(2)+.5*IndexOut(nn).*(Z(nn).^2-1).*XDensity(nn);
ch(3)=ch(3)+1/6*IndexOut(nn).*(Z(nn).^3-3*Z(nn)).*XDensity(nn);
ch(4)=ch(4)+1/24*IndexOut(nn).*(Z(nn).^4-6*Z(nn).^2+3).*XDensity(nn);
ch(5)=ch(5)+1/120*IndexOut(nn).*(Z(nn).^5-10*Z(nn).^3+15*Z(nn)).*XDensity(nn);
ch(6)=ch(6)+1/720*IndexOut(nn).*(Z(nn).^6-15*Z(nn).^4+45*Z(nn).^2-15).*XDensity(nn);
ch(7)=ch(7)+1/720/7*IndexOut(nn).*(Z(nn).^7-21*Z(nn).^5+105*Z(nn).^3-105*Z(nn)).*XDensity(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 [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=0;
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
.
.
.
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
Marsden
Posts: 582
Joined: August 20th, 2001, 5:42 pm
Location: Maryland

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

January 22nd, 2023, 3:23 pm

Amin, thank you for making your accounts of your situation more tractable.

A few things are apparent to me, and maybe the only reason you haven't realized them yourself is due to your strong medication.

First, you have no local allies. It seems that even your family is complicit in your mistreatment.

Second, your tormentors are not worried about what you might do in your current state; the mere fact that you are allowed -- freely, I assume -- to post here and to relate your mistreatment, and that you have been doing it for years, indicates that they are confident that nothing will come of your communications.

Third, it is likely that you are mentally ill in some way. You should not dismiss this possibility. Even so, it is inhumane and immoral to force treatment that you do not want on you, assuming (as seems to be the case) that you do not pose a physical threat to anyone. And part of any cognitive issues you have may in fact be caused by improper treatment.

The upshot of it all is that you are on your own. You have for years done everything in your power to recruit outsiders to help you, to no avail. If Human Rights Watch couldn't help you -- and I suspect that at the very least they contacted the agencies you named as being behind your mistreatment, apparently with no effect -- no inquiry from a concerned citizen will do so either.

It seems clear -- and maybe the only reason you haven't come to this conclusion on your own is due to your medically-induced fog -- that what you need to do is to escape your physical situation. Your family, whatever authorities participate in your mistreatment -- you need physically do disappear from them.

What keeps you from doing this? It seems that you are being fed and housed, and provided computer access, and escape would probably lose you these things. Is your mental well-being worth it? Only you can decide.

Conditions would likely be very difficult for you if you disappear, but you're clever, and people survive much more difficult situations than what you'd likely face. Take a menial job; become a beggar; sneak on a freight train to get out of your geographic location. Maybe you can store up some resources to help you before you go.

But this seems, from where I sit, to be the cost of your freedom.

And with that advice given, I walk away.
 
User avatar
Amin
Topic Author
Posts: 2411
Joined: July 14th, 2002, 3:00 am

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

January 22nd, 2023, 5:26 pm

Friends, here is the explanation about the program. I will first give main equations and then relate them to the program to make it easy for friends to understand the program.
The main idea is to use the orthogonality property of hermite polynomials with respect to standard normal density. Let us assume we have a random variable X and we can represent it as a Z-series. All we know is that our random variable can be represented by a Hermite series version of Z-series(as both are equivalent), we do not know the precise coefficients yet and these coefficients are the ones we want to find out. Let us represent X as a hermite series as

[$]X \,= ah_0 \, + \, ah_1 \, H_1(Z) \, + ah_2 \, H_2(Z) \, + ... + \,  ah_n \, H_n(Z) \, [$]

We multiply X with first hermite polynomial and integrate with respect to Gaussian density to find

[$] \displaystyle\int_{-\infty}^{\infty} \, X \, H_1(Z) \, p(Z) \, dZ[$]
[$]\displaystyle\int_{-\infty}^{\infty} \, (ah_0 \, + \, ah_1 \, H_1(Z) \, + ah_2 \, H_2(Z) \, + ... + \,  ah_n \, H_n(Z) \,) \, H_1(Z) \, p(Z) \, dZ[$]
[$]=ah_1[$]

Similalry taking scalar product of X and second hermite polynomial with respect to Gaussian density would give us

[$] \displaystyle\int_{-\infty}^{\infty} \, X \, H_2(Z) \, p(Z) \, dZ[$]
[$]\displaystyle\int_{-\infty}^{\infty} \, (ah_0 \, + \, ah_1 \, H_1(Z) \, + ah_2 \, H_2(Z) \, + ... + \,  ah_n \, H_n(Z) \,) \, H_2(Z) \, p(Z) \, dZ[$]
[$]=2!  \, ah_2[$]

Taking scalar product of X with nth hermite polynomial with respect to Gaussian density would give us

[$] \displaystyle\int_{-\infty}^{\infty} \, X \, H_n(Z) \, p(Z) \, dZ[$]
[$]\displaystyle\int_{-\infty}^{\infty} \, (ah_0 \, + \, ah_1 \, H_1(Z) \, + ah_2 \, H_2(Z) \, + ... + \,  ah_n \, H_n(Z) \,) \, H_n(Z) \, p(Z) \, dZ[$]
[$]=n!  \, ah_n[$]

So basically we have to be able to take scalar product of X and nth hermite polynomial with respect to Gaussian density to find scaled value of coefficient of nth hermite polynomial.

In order to be able to do this, I first constructed a monte carlo density by dividing the valid domain into equal grid spacings of [$]\Delta X[$] and calculated probability mass within each grid cell. Since the grid is uniform width, For each of the P monte carlo paths, we can just use one division per path to assign weight 1/P to appropriate grid cell. Once the iteration of this is complete over all paths, we get total probability mass in each of the grid cell as a result so that summed over all the grid cells probability mass becomes one. If there are M grid cells, probability mass in mth grid cell is given as [$]\Delta P_m [$]
Now we associate a value of Z with center of each of the grid cells. For this we take sum of probability mass over all previous grid cells plus half of the probability mass in the current cell where we want to find the value of Z. 
This value of Z is found by norminv(sum of all the probability mass up to center of the grid cell)
It is the value of CDF at a point X that associates a corresponding Z to that point. So the value of Z at center of a grid cell is found by inversion of CDF of X at center of that grid cell.
Once we have found [$]Z_m[$] associated with center of mth grid cell, we can replace our inner product integrals (between X and H_n(Z)) with respect to Gaussian density by finite sums over all the grid cells as

[$] \displaystyle\int_{-\infty}^{\infty} \, X \, H_n(Z) \, p(Z) \, dZ[$]
[$] \displaystyle\sum_{m=1}^{M} \, X_m \, H_n(Z_m) \, p(Z_m) \, \Delta Z_m[$]

But we know that  probability mass in mth cell is given as
[$]p(Z_m) \, \Delta Z_m=p(X_m) \, \Delta X_m = \Delta P_m [$]


So we can write as
[$] \displaystyle\int_{-\infty}^{\infty} \, X \, H_n(Z) \, p(Z) \, dZ[$]
[$] \displaystyle\sum_{m=1}^{M} \, X_m \, H_n(Z_m) \, p(Z_m) \, \Delta Z_m[$]
[$] \displaystyle\sum_{m=1}^{M} \, X_m \, H_n(Z_m) \, \Delta P_m \,[$]

which means that 
[$]n!  \, ah_n \, = \, \displaystyle\sum_{m=1}^{M} \, X_m \, H_n(Z_m) \, \Delta P_m \,[$]

All the values in RHS are known . [$]X_m[$] is center of mth grid cell. [$]Z_m[$] is value found by inversion of CDF at [$]X_m[$] and [$]\Delta P_m \,[$] which is the probability mass in mth grid cell was also calculated when we divided P monte carlo paths over the grid cells with 1/P weight.

Now relating it to the program, 
[ch0,ch] = FindHermiteCoefficientsFromSimulation_Infiniti_NEW(X,Paths,NoOfBins,MaxCutOff )

is the function where we did all of the above calculations in the loop given below as


for nn=1:IndexMax
ch(1)=ch(1)+IndexOut(nn).*Z(nn).*XDensity(nn);
ch(2)=ch(2)+.5*IndexOut(nn).*(Z(nn).^2-1).*XDensity(nn);
ch(3)=ch(3)+1/6*IndexOut(nn).*(Z(nn).^3-3*Z(nn)).*XDensity(nn);
ch(4)=ch(4)+1/24*IndexOut(nn).*(Z(nn).^4-6*Z(nn).^2+3).*XDensity(nn);
ch(5)=ch(5)+1/120*IndexOut(nn).*(Z(nn).^5-10*Z(nn).^3+15*Z(nn)).*XDensity(nn);
ch(6)=ch(6)+1/720*IndexOut(nn).*(Z(nn).^6-15*Z(nn).^4+45*Z(nn).^2-15).*XDensity(nn);
ch(7)=ch(7)+1/720/7*IndexOut(nn).*(Z(nn).^7-21*Z(nn).^5+105*Z(nn).^3-105*Z(nn)).*XDensity(nn);
end

Here ch(.) are hermite coefficients that are being calculated.
Here  IndexOut(nn) is value of X(nn) associated with nnth grid cell. Z(nn) is value of Z associated with nnth grid cell and XDensity(nn) is probability mass associated with nnth grid cell.
Sorry that IndexOut(nn) is a bad variable name but you can replace it with X(nn).
Once we have hermite coefficients, we can easily convert them to Z-series coefficients.
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: 2411
Joined: July 14th, 2002, 3:00 am

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

January 25th, 2023, 5:59 am

Friends, I will be posting a program for calculations of "hermite-wise correlations" in a day or two in monte-carlo setting. I also have ideas about a simpler method to find hermite-wise correlations in smaller samples. I expect to post these programs tomorrow or in another day.
It turns out to be slightly more complicated as compared to what I suggested in an older post.
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: 2411
Joined: July 14th, 2002, 3:00 am

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

January 25th, 2023, 4:55 pm

Friends, I am writing this post to complain about increase of  food drugging activity in Lahore city. I have been going to remote parts of the city to get good food and water but now Mind control agencies (with the help of Pak Army soldiers) have started distributing mind control drugs among small restaurants even in remote areas. They give mind control drugs to small restaurants where cooked food is available and ask them to freely add mind control drugs in the food they prepare. Today I was hit by mind control drugs when I took food from a restaurant where I never suspected they would have reached but he had already added drugs in the food and I only realized it after I had eaten some food. Pakistan Army is distributing mind control drugs among small restaurants in more and more neighborhoods with passing time. 
It is also extremely difficult to get good bottled water but underground water at many places in the city is still good but I am very afraid if friends did not act to stop them now, Pakistan army will drug underground water in Lahore city very carefully in next few days.
There is another very important thing that I want to tell friends. It seems that mind control agents have again started to alter my programs. I wrote a function today to calculate hermite polynomials correlation between two stochastic variables in a monte carlo setting. The function seemed to work very well and I was getting very reasonable values. Then I thought that my variables are always misnomers and I should change the names of many variables so it would be easier for friends to understand the program. I went ahead and changed the names of many variables and re-ran the program. But then I realized that its output had changed. I spent a long time trying to see where I had made the error but could not find any source of error. I copied the new function with bad output and pasted it in a different matlab file and repeatedly used undo button in matlab editor in original file to reverse all the changes in the function that I had made. When I re-ran the old function, its output was good again as I had reversed all the changes. Since I had pasted the changed function in a new file, I compared both functions and still could not find the error in the function with bad output. Then I decided to compare all the inner variables in both functions to see where they would diverge so I would know where the error in modified function was. But when I ran the modified function that I had copy-pasted in a separate file before undo, it started giving good values again. And I was totally aghast since the same function was giving bad values. I am really afraid that mind control agents really do not want me to do any good research and distribute it among friends and therefore they changed the function somewhere but when I decided to compare inner variables of both functions on every step, they reverted it back since they realized when I would see different inner output on the same code, I would automatically blame them. Though this was a common practice for them to alter my programs more than six years ago, these days it is not an everyday issue and mind control agents really do not change output of my programs but I am afraid that they are becoming worried that my attempt at doing good research is creating larger problems for them and they want to stop me from doing it and they have become willing now to alter my programs to stop me from distributing good research with friends.
I want to request friends to please protest with mind control agencies and American defense to not distribute mind control drugs among street restaurants in Lahore city and also not to drug underground water that is still good in many parts of the city. And also please ask them to not alter my matlab programs.

About the progress on my research. I hope to post a matlab function today that constructs a two dimensional density using joint realizations of two simulated variables in every path and then uses this density to calculate correlation between hermite polynomials of same order associated with the two simulated variables. This is still preliminary and is building block part of a larger program but I have decided to post it and I will come back with a more detailed program in another two 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: 2411
Joined: July 14th, 2002, 3:00 am

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

January 25th, 2023, 6:51 pm

Friends, I am posting this program that is embedded in correlated Stochastic Volatility simulations. At each step, it calculates the correlations between hermite polynomials of same order associated with asset and stochastic variance. It is still preliminary and supposed to be part of a larger program that I will post in another two days. I am posting this version for friends who are also interested in similar research. I will soon come back with the detailed program.
.
.
%This function processes joint observations of two variables X and Y from 
%common monte carlo paths and makes a two dimensional density of X and Y.
%Later it finds correlations between hermite polynomials of X with hermite
%polynomials of Y of the same order.
.
.
function [corr1,corr2,corr3,corr4,corr5,corr6,corr7] = FindHermiteCorrelationsFromSimulation_Infiniti_NEW02(X,Y,Paths,NoOfBinsX,NoOfBinsY)

%This function processes joint observations of two variables X and Y from 
%common monte carlo paths and makes a two dimensional density of X and Y.
%Later it finds correlations between hermite polynomials of X with hermite
%polynomials of Y of the same order.



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

XYProbMass2D(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);
if(real(indexX)<1)
indexX=1;
end
if(real(indexX)>IndexMaxX)
indexX=IndexMaxX;
end

indexY=real(floor(real(Y(p)-Ymin2)/BinSizeY+.5)+1);
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;
end

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

XCDF(1:IndexMaxX)=0;
Zx(1:IndexMaxX)=0;
XCDF(1)=XProbMass(1)*.5;
Zx(1)=norminv(XCDF(1));
for nn=2:IndexMaxX
    XCDF(nn)=XCDF(nn-1)+XProbMass(nn-1)*.5+XProbMass(nn)*.5;
    Zx(nn)=norminv(XCDF(nn));
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
corr1=0;
corr2=0;
corr3=0;
corr4=0;
corr5=0;
corr6=0;
corr7=0;
for nn=1:IndexMaxX
    for mm=1:IndexMaxY
        corr1=corr1+Zx(nn).*Zy(mm).*XYProbMass2D(nn,mm);
        corr2=corr2+1/2*(Zx(nn).^2-1).*(Zy(mm).^2-1).*XYProbMass2D(nn,mm);
        corr3=corr3+1/6*(Zx(nn).^3-3*Zx(nn)).*(Zy(mm).^3-3*Zy(mm)).*XYProbMass2D(nn,mm);
        corr4=corr4+1/24*(Zx(nn).^4-6*Zx(nn).^2+3).*(Zy(mm).^4-6*Zy(mm).^2+3).*XYProbMass2D(nn,mm);
        corr5=corr5+1/120*(Zx(nn).^5-10*Zx(nn).^3+15*Zx(mm)).*(Zy(mm).^5-10*Zy(mm).^3+15*Zy(mm)).*XYProbMass2D(nn,mm);
        corr6=corr6+1/720*(Zx(nn).^6-15*Zx(nn).^4+45*Zx(nn).^2-15).*(Zy(mm).^6-15*Zy(mm).^4+45*Zy(mm).^2-15).*XYProbMass2D(nn,mm);
        corr7=corr7+1/7/720*(Zx(nn).^7-21*Zx(nn).^5+105*Zx(nn).^3-105.*Zx(nn)).*(Zy(mm).^7-21*Zy(mm).^5+105*Zy(mm).^3-105*Zy(mm)).*XYProbMass2D(nn,mm);
        
    end
end




end
.
.
.
function [] = SVMonteCarloDensity()

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


dt=.125/2/2/2;   % Simulation time interval.%Fodiffusions close to zero
             %decrease dt for accuracy.
Tt=128;%64*4*2;%16*2*4;%*4*4*1;%*4;%128*2*2*2;     % Number of simulation levels. Terminal time= Tt*dt; //.125/32*32*16=2 year; 
T=Tt*dt;

if(T>=1)
dtM=1/32;;
TtM=T/dtM;
else
dtM=T/32;
TtM=T/dtM;
end




v00=1.0;%.250;   % starting value of SDE
beta1=0.0;
beta2=1.0;   % Second drift term power.
gamma=.950;%50;   % volatility power.                                                                                                                                                                                                                                                                     
kappa=1.50;%.950;   %mean reversion parameter.
theta=1.0;%.075;%mean reversion target
sigma0=.9500;%Volatility value

%you can specify any general mu1 and mu2 and beta1 and beta2.
mu1=1*theta*kappa;   %first drift coefficient.
mu2=-1*kappa;    % Second drift coefficient.


%dVt=(mu1*Vt^beta1 + mu2*Vt^beta2)*dt+sigma0 * Vt^gamma * dz1(t)
%Xt(0)=x0
%dXt=(mu1X*Xt^alpha1+mu2X*Xt^alpha2)*dt+sigmaX* Vt^gammaV * Xt^gammaX *dz2(t);
%<dz1(t),dz2(t)>=rho *dt

x0=1.00;
gammaX=.85;
sigmaX=.250;
thetaX=.50;
kappaX=0.0;
mu1X=thetaX*kappaX;
mu2X=-1*kappaX;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%rng(29079137, 'twister')
rng(15898837, 'twister')
paths=2000000;
V(1:paths)=v00;  %Original process monte carlo.
X=0.0;
X(1:paths)=x0;
alpha1=0;
alpha2=1;
a=mu1X;
b=mu2X;
rho=-.95;
sigma1=sigmaX;
gammaV=.5;
Random1(1:paths)=0;
Random2(1:paths)=0;
mm=0;
for ttM=1:TtM
Random1=randn(size(Random1));
Random2=randn(size(Random2));

time1=ttM*dtM
Xbefore(1:paths)=X(1:paths);
X(1:paths)=X(1:paths)+ ...
    (a* X(1:paths).^alpha1 + b* X(1:paths).^alpha2)* dtM + ...
    sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*Random1(1:paths) * sqrt(dtM) + ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*Random2(1:paths)*sqrt(dtM) + ...
    (a*alpha1* X(1:paths).^(alpha1-1)+b*alpha2* X(1:paths).^(alpha2-1)).* ...
    (((a* X(1:paths).^alpha1 + b* X(1:paths).^alpha2)* dtM^2/2)+ ...
    (sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*Random1(1:paths) *(1-1/sqrt(3)).*dtM^1.5+ ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*Random2(1:paths)*(1-1/sqrt(3)).*dtM^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)) *dtM^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).* dtM^1.5 + ...
    sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*(Random1(1:paths).^2-1) * dtM/2 + ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*Random1(1:paths).*Random2(1:paths)*dtM/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).*dtM^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).* dtM^1.5 + ...
    sigma0*V(1:paths).^gamma.*Random1(1:paths).*Random2(1:paths)*dtM/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)*dtM^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)*dtM^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).* dtM^1.5 + ...
    sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*Random1(1:paths).*Random2(1:paths) * dtM/2 + ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*(Random2(1:paths).^2-1)*dtM/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).*dtM^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).* dtM^1.5 + ...
    sigma0*V(1:paths).^gamma.*(Random2(1:paths).^2-1)*dtM/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).* dtM^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)*dtM^1.5;

DX=X-Xbefore;
%Uncomment to find Z-series of diffusion noise term of  asset.
% X(X<0)=.0000001;
% if(rem(ttM,8)==0) %On every eighth monte carlo step construct the density
% mm=mm+1;
% MaxCutOff=100;
% NoOfBins=1000;
% DX=X-Xbefore;
% [XDensity,IndexOutX,IndexMaxX] = MakeDensityFromSimulation_Infiniti_NEW(DX,paths,NoOfBins,MaxCutOff );
% 
% SeriesOrder=7;
% NoOfBins=2000;
% MaxCutOff=9999999;
% %Below function finds hermite coefficients of monte carlo simulated SDE
% %of the stock asset.
% [ch0,ch] = FindHermiteCoefficientsFromSimulation_Infiniti_NEW(DX,paths,NoOfBins,MaxCutOff );
% [c0,c] = ConvertHCoeffsToZCoeffs(ch0,ch,7);
% ch0
% ch
% c0
% c
% 
% str=input('Look at Coeffs of Z-series of stock SDE')
% 
% %Below construct density on Gaussian grid.
% %First calculate normal random variable on a grid below
% dNn=.1/2;   % Normal density subdivisions width. would change with number of subdivisions
% Nn=45*4;  % No of normal density subdivisions
% NnMid=((1+Nn)/2)*dNn;
% Z(1:Nn)=(((1:Nn)*dNn)-NnMid);
% %Z
% %str=input('Look at Z');
% %Now calculate Y as a function of normal random variable.
% Y(1:Nn)=c0;
% for nn=1:SeriesOrder
%     Y(1:Nn)=Y(1:Nn)+c(nn)*Z(1:Nn).^nn;
% end
% 
% %Now take change of densities derivative of Y with respect to normal
% DfY(1:Nn)=0;
% for nn=2:Nn-1
%     DfY(nn) = (Y(nn + 1) - Y(nn - 1))/(Z(nn + 1) - Z(nn - 1));
%     %Change of variable derivative for densities
% end
% DfY(Nn)=DfY(Nn-1);
% DfY(1)=DfY(2);
% 
% %Now calculate the density of Y from density of normal random variable
% %using change of probability derivative.
% pY(1:Nn)=0;
% for nn = 1:Nn    
%     pY(nn) = (normpdf(Z(nn),0, 1))/abs(DfY(nn));
% end
% 
% plot(Y(1:Nn),pY(1:Nn),'r',IndexOutX(1:IndexMaxX),XDensity(1:IndexMaxX),'g');
% 
% title(sprintf('Stock Density: x0 = %.2f,thetaX=%.2f,kappaX=%.2f,gammaX=%.2f,sigmaX=%.2f,rho=%.2f,v0 =%.2f,kappa=%.2f,theta=%.2f,gamma=%.2f,sigma0=%.2f,T=%.2f,dt=%.3f',x0,thetaX,kappaX,gammaX,sigmaX,rho,v00,kappa,theta,gamma,sigma0,time1,dtM));
% legend({'Z-Series Density of Stock From Hermite Polynomials','Monte Carlo Density'},'Location','northeast')
% 
% str=input('Look at density of stock from simulated data. From Z-series Coefficients in red, Directly from data in green');
% end

Vbefore=V;

    V(1:paths)=V(1:paths)+ ...
        (mu1.*V(1:paths).^beta1 + mu2.*V(1:paths).^beta2)*dtM + ...
        sigma0*V(1:paths).^gamma .*Random2(1:paths)*sqrt(dtM) + ...
        (mu1.*beta1*V(1:paths).^(beta1-1) + mu2.*beta2.*V(1:paths).^(beta2-1)).* ...
        ((mu1.*V(1:paths).^beta1 + mu2.*V(1:paths).^beta2)*dtM^2/2 + ...
        sigma0*V(1:paths).^gamma .*Random2(1:paths)*(1-1/sqrt(3))*dtM^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).*dtM^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)*dtM^1.5 + ...
        sigma0.*V(1:paths).^gamma .*(Random2(1:paths).^2-1)*dtM/2) + ...
        .5*sigma0*gamma*(gamma-1).*V(1:paths).^(gamma-2) .* ...
        sigma0^2.*V(1:paths).^(2*gamma) .*Random2(1:paths).*1/sqrt(3)*dtM^1.5;

DV=V-Vbefore;
%Uncomment to find Z-series of diffusion noise term of  variance SDE.
% if(rem(ttM,8)==0)    
% 
%     %V(V<=0)=.0000001;
%     DV=V-Vbefore;
% MaxCutOff=100;
% NoOfBins=1000;
% [VDensity,IndexOutV,IndexMaxV] = MakeDensityFromSimulation_Infiniti_NEW(DV,paths,NoOfBins,MaxCutOff );
% %Below function finds hermite coefficients of monte carlo simulated SDE
% %of stochastic variance.
% NoOfBins=400;
% MaxCutOff=9999999;
% [dh0,dh] = FindHermiteCoefficientsFromSimulation_Infiniti_NEW(DV,paths,NoOfBins,MaxCutOff );
% 
% [d0,d] = ConvertHCoeffsToZCoeffs(dh0,dh,7);
% dh0
% dh
% d0
% d
% 
% str=input('Look at Coeffs of stochastic variance Z-Series')
% 
% 
% %Below construct variance density on Gaussian grid.
% %First calculate normal random variable on a grid below
% dNn=.1/2;   % Normal density subdivisions width. would change with number of subdivisions
% Nn=45*4;  % No of normal density subdivisions
% NnMid=((1+Nn)/2)*dNn;
% Z(1:Nn)=(((1:Nn)*dNn)-NnMid);
% %Z
% %str=input('Look at Z');
% %Now calculate Y as a function of normal random variable.
% Y(1:Nn)=d0;
% for nn=1:SeriesOrder
%     Y(1:Nn)=Y(1:Nn)+d(nn)*Z(1:Nn).^nn;
% end
% 
% %Now take change of densities derivative of Y with respect to normal
% DfY(1:Nn)=0;
% for nn=2:Nn-1
%     DfY(nn) = (Y(nn + 1) - Y(nn - 1))/(Z(nn + 1) - Z(nn - 1));
%     %Change of variable derivative for densities
% end
% DfY(Nn)=DfY(Nn-1);
% DfY(1)=DfY(2);
% 
% %Now calculate the density of Y from density of normal random variable
% %using change of probability derivative.
% pY(1:Nn)=0;
% for nn = 1:Nn    
%     pY(nn) = (normpdf(Z(nn),0, 1))/abs(DfY(nn));
% end
% plot(Y(1:Nn),pY(1:Nn),'r',IndexOutV(1:IndexMaxV),VDensity(1:IndexMaxV),'g');
% legend({'Z-Series Density From Hermite Polynomials','Monte Carlo Density'},'Location','northeast')
% title(sprintf('Variance Density: v0 =%.2f,kappa=%.2f,theta=%.2f,gamma=%.2f,sigma0=%.2f,T=%.2f,dt=%.3f',v00,kappa,theta,gamma,sigma0,time1,dtM));
% 
% str=input('Look at density of volatility from simulated data. From Z-series Coefficients in red and directly from data in green');    
% end    


%find correlations between hermite polynomials of same order associated with 
%asset and volatility diffusion terms
NoOfBinsv=100;
NoOfBinsx=100;
   
%Below function to calculate correlation of same order hermite polynomials
[corr1,corr2,corr3,corr4,corr5,corr6,corr7] = FindHermiteCorrelationsFromSimulation_Infiniti_NEW02(DX,DV,paths,NoOfBinsx,NoOfBinsv); 
corr1
corr2
corr3
corr4
corr5
corr6
corr7
   str=input('Look at corrs');
end

%SVolMeanAnalytic=thetaV+(V0-thetaV)*exp(-kappaV*dt*Tt)
SVolMeanAnalytic=theta+(v00-theta)*exp(-kappa*dt*Tt)
SVolMeanMC=sum(V(1:paths))/paths
AssetMeanAnalytic=x0
AssetMeanMC=sum(X(1:paths))/paths



end
.
.
The stochastic volatility program is run with -.95 correlation between stock and stochastic volatility diffusions. Here is the hermites correlation on first time step that you will see on screen.

corr1 =

  -0.947841155761345


corr2 =

   0.896664461062579


corr3 =

  -0.843967323299367


corr4 =

   0.782313532194083


corr5 =

  -0.707861129845129


corr6 =

   0.580058382134738


corr7 =

  -0.443654522888022

Look at corrs
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: 2411
Joined: July 14th, 2002, 3:00 am

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

January 27th, 2023, 12:06 am

Friends, it is 4:50 am in the morning in Lahore, Pakistan. I decided to sleep at 12:30 am when I could not do any more work as my body bitterly wanted to go to sleep. But after lying on bed, I have not been able to sleep well at all. They continue to target medium frequency waves on the victim to not allow the victim to sleep at all. They have done it partially on many past nights but at this time, I am without proper sleep despite that it is early morning now and roughly about five hours have passed since I have been trying to sleep. 
I had made some progress in my research last night and wanted to post another interim version again last night but I was too tired to be able to post anything on internet. Now four and half hours after falling on bed, I am complaining of sleep deprivation torture.
I got off the bed at 3:20 am and tried many things for a better sleep and fell on bed again but nothing worked. When I am writing now at 5:00 am, I am more mentally distressed now after extremely poor sleep and microwave torture on the head than I was when I tried to sleep at 12:20 am.
Please protest to American government and defense to end mind control torture and directed microwave torture on innocent civilian victims.
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: 2411
Joined: July 14th, 2002, 3:00 am

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

January 27th, 2023, 6:00 pm

Friends, the day before yesterday I posted a program that calculates correlations between hermite polynomials of same order of two different but correlated diffusions. In that program I constructed a two dimensional density from joint observations of two diffusions and then found correlations between hermite polynomials of different diffusions by integrating over the joint two dimensional density. I am posting a slightly modified version of the same program.

I am also posting another function that directly calculates correlations between hermite polynomials (of same order) associated with observations of simulated correlated diffusions using values of Zx and Zy associated with observations of each of the diffusions of X and Y. This program does not require calculations of two dimensional density and gives simulation monte carlo weight of 1/P to each joint observation of X and Y where P are total number of simulation paths. This is direct calculation of correlations between data without integration over the joint density. 

Here is the main program.
.
function [] = SVMonteCarloDensity()

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


dt=.125/2/2/2;   % Simulation time interval.%Fodiffusions close to zero
             %decrease dt for accuracy.
Tt=128;%64*4*2;%16*2*4;%*4*4*1;%*4;%128*2*2*2;     % Number of simulation levels. Terminal time= Tt*dt; //.125/32*32*16=2 year; 
T=Tt*dt;

if(T>=1)
dtM=1/32;;
TtM=T/dtM;
else
dtM=T/32;
TtM=T/dtM;
end




v00=1.0;%.250;   % starting value of SDE
beta1=0.0;
beta2=1.0;   % Second drift term power.
gamma=.950;%50;   % volatility power.                                                                                                                                                                                                                                                                     
kappa=1.50;%.950;   %mean reversion parameter.
theta=1.0;%.075;%mean reversion target
sigma0=.9500;%Volatility value

%you can specify any general mu1 and mu2 and beta1 and beta2.
mu1=1*theta*kappa;   %first drift coefficient.
mu2=-1*kappa;    % Second drift coefficient.


%dVt=(mu1*Vt^beta1 + mu2*Vt^beta2)*dt+sigma0 * Vt^gamma * dz1(t)
%Xt(0)=x0
%dXt=(mu1X*Xt^alpha1+mu2X*Xt^alpha2)*dt+sigmaX* Vt^gammaV * Xt^gammaX *dz2(t);
%<dz1(t),dz2(t)>=rho *dt

x0=1.00;
gammaX=.85;
sigmaX=.250;
thetaX=.50;
kappaX=0.0;
mu1X=thetaX*kappaX;
mu2X=-1*kappaX;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%rng(29079137, 'twister')
rng(15898837, 'twister')
paths=2000000;
V(1:paths)=v00;  %Original process monte carlo.
X=0.0;
X(1:paths)=x0;
alpha1=0;
alpha2=1;
a=mu1X;
b=mu2X;
rho=-.95;
sigma1=sigmaX;
gammaV=.5;
Random1(1:paths)=0;
Random2(1:paths)=0;
mm=0;
for ttM=1:TtM
Random1=randn(size(Random1));
Random2=randn(size(Random2));

time1=ttM*dtM
Xbefore(1:paths)=X(1:paths);
X(1:paths)=X(1:paths)+ ...
    (a* X(1:paths).^alpha1 + b* X(1:paths).^alpha2)* dtM + ...
    sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*Random1(1:paths) * sqrt(dtM) + ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*Random2(1:paths)*sqrt(dtM) + ...
    (a*alpha1* X(1:paths).^(alpha1-1)+b*alpha2* X(1:paths).^(alpha2-1)).* ...
    (((a* X(1:paths).^alpha1 + b* X(1:paths).^alpha2)* dtM^2/2)+ ...
    (sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*Random1(1:paths) *(1-1/sqrt(3)).*dtM^1.5+ ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*Random2(1:paths)*(1-1/sqrt(3)).*dtM^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)) *dtM^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).* dtM^1.5 + ...
    sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*(Random1(1:paths).^2-1) * dtM/2 + ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*Random1(1:paths).*Random2(1:paths)*dtM/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).*dtM^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).* dtM^1.5 + ...
    sigma0*V(1:paths).^gamma.*Random1(1:paths).*Random2(1:paths)*dtM/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)*dtM^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)*dtM^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).* dtM^1.5 + ...
    sqrt(1-rho^2)* sigma1* V(1:paths).^gammaV.* X(1:paths).^gammaX .*Random1(1:paths).*Random2(1:paths) * dtM/2 + ...
    rho* sigma1* V(1:paths).^gammaV .*X(1:paths).^gammaX .*(Random2(1:paths).^2-1)*dtM/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).*dtM^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).* dtM^1.5 + ...
    sigma0*V(1:paths).^gamma.*(Random2(1:paths).^2-1)*dtM/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).* dtM^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)*dtM^1.5;

DX=X-Xbefore;
%Uncomment to find Z-series of diffusion noise term of  asset.
% X(X<0)=.0000001;
% if(rem(ttM,8)==0) %On every eighth monte carlo step construct the density
% mm=mm+1;
% MaxCutOff=100;
% NoOfBins=1000;
% DX=X-Xbefore;
% [XDensity,IndexOutX,IndexMaxX] = MakeDensityFromSimulation_Infiniti_NEW(DX,paths,NoOfBins,MaxCutOff );
% 
% SeriesOrder=7;
% NoOfBins=2000;
% MaxCutOff=9999999;
% %Below function finds hermite coefficients of monte carlo simulated SDE
% %of the stock asset.
% [ch0,ch] = FindHermiteCoefficientsFromSimulation_Infiniti_NEW(DX,paths,NoOfBins,MaxCutOff );
% [c0,c] = ConvertHCoeffsToZCoeffs(ch0,ch,7);
% ch0
% ch
% c0
% c
% 
% str=input('Look at Coeffs of Z-series of stock SDE')
% 
% %Below construct density on Gaussian grid.
% %First calculate normal random variable on a grid below
% dNn=.1/2;   % Normal density subdivisions width. would change with number of subdivisions
% Nn=45*4;  % No of normal density subdivisions
% NnMid=((1+Nn)/2)*dNn;
% Z(1:Nn)=(((1:Nn)*dNn)-NnMid);
% %Z
% %str=input('Look at Z');
% %Now calculate Y as a function of normal random variable.
% Y(1:Nn)=c0;
% for nn=1:SeriesOrder
%     Y(1:Nn)=Y(1:Nn)+c(nn)*Z(1:Nn).^nn;
% end
% 
% %Now take change of densities derivative of Y with respect to normal
% DfY(1:Nn)=0;
% for nn=2:Nn-1
%     DfY(nn) = (Y(nn + 1) - Y(nn - 1))/(Z(nn + 1) - Z(nn - 1));
%     %Change of variable derivative for densities
% end
% DfY(Nn)=DfY(Nn-1);
% DfY(1)=DfY(2);
% 
% %Now calculate the density of Y from density of normal random variable
% %using change of probability derivative.
% pY(1:Nn)=0;
% for nn = 1:Nn    
%     pY(nn) = (normpdf(Z(nn),0, 1))/abs(DfY(nn));
% end
% 
% plot(Y(1:Nn),pY(1:Nn),'r',IndexOutX(1:IndexMaxX),XDensity(1:IndexMaxX),'g');
% 
% title(sprintf('Stock Density: x0 = %.2f,thetaX=%.2f,kappaX=%.2f,gammaX=%.2f,sigmaX=%.2f,rho=%.2f,v0 =%.2f,kappa=%.2f,theta=%.2f,gamma=%.2f,sigma0=%.2f,T=%.2f,dt=%.3f',x0,thetaX,kappaX,gammaX,sigmaX,rho,v00,kappa,theta,gamma,sigma0,time1,dtM));
% legend({'Z-Series Density of Stock From Hermite Polynomials','Monte Carlo Density'},'Location','northeast')
% 
% str=input('Look at density of stock from simulated data. From Z-series Coefficients in red, Directly from data in green');
% end

Vbefore=V;

    V(1:paths)=V(1:paths)+ ...
        (mu1.*V(1:paths).^beta1 + mu2.*V(1:paths).^beta2)*dtM + ...
        sigma0*V(1:paths).^gamma .*Random2(1:paths)*sqrt(dtM) + ...
        (mu1.*beta1*V(1:paths).^(beta1-1) + mu2.*beta2.*V(1:paths).^(beta2-1)).* ...
        ((mu1.*V(1:paths).^beta1 + mu2.*V(1:paths).^beta2)*dtM^2/2 + ...
        sigma0*V(1:paths).^gamma .*Random2(1:paths)*(1-1/sqrt(3))*dtM^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).*dtM^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)*dtM^1.5 + ...
        sigma0.*V(1:paths).^gamma .*(Random2(1:paths).^2-1)*dtM/2) + ...
        .5*sigma0*gamma*(gamma-1).*V(1:paths).^(gamma-2) .* ...
        sigma0^2.*V(1:paths).^(2*gamma) .*Random2(1:paths).*1/sqrt(3)*dtM^1.5;

DV=V-Vbefore;
%Uncomment to find Z-series of diffusion noise term of  variance SDE.
% if(rem(ttM,8)==0)    
% 
%     %V(V<=0)=.0000001;
%     DV=V-Vbefore;
% MaxCutOff=100;
% NoOfBins=1000;
% [VDensity,IndexOutV,IndexMaxV] = MakeDensityFromSimulation_Infiniti_NEW(DV,paths,NoOfBins,MaxCutOff );
% %Below function finds hermite coefficients of monte carlo simulated SDE
% %of stochastic variance.
% NoOfBins=400;
% MaxCutOff=9999999;
% [dh0,dh] = FindHermiteCoefficientsFromSimulation_Infiniti_NEW(DV,paths,NoOfBins,MaxCutOff );
% 
% [d0,d] = ConvertHCoeffsToZCoeffs(dh0,dh,7);
% dh0
% dh
% d0
% d
% 
% str=input('Look at Coeffs of stochastic variance Z-Series')
% 
% 
% %Below construct variance density on Gaussian grid.
% %First calculate normal random variable on a grid below
% dNn=.1/2;   % Normal density subdivisions width. would change with number of subdivisions
% Nn=45*4;  % No of normal density subdivisions
% NnMid=((1+Nn)/2)*dNn;
% Z(1:Nn)=(((1:Nn)*dNn)-NnMid);
% %Z
% %str=input('Look at Z');
% %Now calculate Y as a function of normal random variable.
% Y(1:Nn)=d0;
% for nn=1:SeriesOrder
%     Y(1:Nn)=Y(1:Nn)+d(nn)*Z(1:Nn).^nn;
% end
% 
% %Now take change of densities derivative of Y with respect to normal
% DfY(1:Nn)=0;
% for nn=2:Nn-1
%     DfY(nn) = (Y(nn + 1) - Y(nn - 1))/(Z(nn + 1) - Z(nn - 1));
%     %Change of variable derivative for densities
% end
% DfY(Nn)=DfY(Nn-1);
% DfY(1)=DfY(2);
% 
% %Now calculate the density of Y from density of normal random variable
% %using change of probability derivative.
% pY(1:Nn)=0;
% for nn = 1:Nn    
%     pY(nn) = (normpdf(Z(nn),0, 1))/abs(DfY(nn));
% end
% plot(Y(1:Nn),pY(1:Nn),'r',IndexOutV(1:IndexMaxV),VDensity(1:IndexMaxV),'g');
% legend({'Z-Series Density From Hermite Polynomials','Monte Carlo Density'},'Location','northeast')
% title(sprintf('Variance Density: v0 =%.2f,kappa=%.2f,theta=%.2f,gamma=%.2f,sigma0=%.2f,T=%.2f,dt=%.3f',v00,kappa,theta,gamma,sigma0,time1,dtM));
% 
% str=input('Look at density of volatility from simulated data. From Z-series Coefficients in red and directly from data in green');    
% end    


%find correlations between hermite polynomials of same order associated with 
%asset and volatility diffusion terms
NoOfBinsv=100;
NoOfBinsx=100;
   
%Below function to calculate correlation of same order hermite polynomials
[corr1,corr2,corr3,corr4,corr5,corr6,corr7] = FindHermiteCorrelationsFromSimulation_Infiniti_NEW04B(DX,DV,paths,NoOfBinsx,NoOfBinsv); 
corr1
corr2
corr3
corr4
corr5
corr6
corr7
   str=input('Look at corrs--1--using two dimensional density');
   
[corr1,corr2,corr3,corr4,corr5,corr6,corr7] = FindHermiteCorrelationsFromSimulationData_Infiniti_NEW04(DX,DV,paths,NoOfBinsx,NoOfBinsv);    
 corr1
corr2
corr3
corr4
corr5
corr6
corr7
   str=input('Look at corrs--2--Directly between simulated Data observations of DX and DV');
     
end

%SVolMeanAnalytic=thetaV+(V0-thetaV)*exp(-kappaV*dt*Tt)
SVolMeanAnalytic=theta+(v00-theta)*exp(-kappa*dt*Tt)
SVolMeanMC=sum(V(1:paths))/paths
AssetMeanAnalytic=x0
AssetMeanMC=sum(X(1:paths))/paths



end
.
Here is the updated version of old function that was used to calculate hermite wise correlations using two dimensional density.
.
function [corr1,corr2,corr3,corr4,corr5,corr6,corr7] = FindHermiteCorrelationsFromSimulation_Infiniti_NEW04B(X,Y,Paths,NoOfBinsX,NoOfBinsY)

%This function processes joint observations of two variables X and Y from 
%common monte carlo paths and makes a two dimensional density of X and Y.
%Later it finds correlations between hermite polynomials of X with hermite
%polynomials of Y of the same order.



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;
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;
end



XCDF(1:IndexMaxX)=0;
Zx(1:IndexMaxX)=0;
XCDF(1)=XProbMass(1)*.5;
Zx(1)=norminv(XCDF(1));
for nn=2:IndexMaxX
    XCDF(nn)=XCDF(nn-1)+XProbMass(nn-1)*.5+XProbMass(nn)*.5;
    Zx(nn)=norminv(XCDF(nn));
end
% Zxa(1)=Zx(1);
% Zxa(2:IndexMaxX)=.5*Zx(1:IndexMaxX-1)+.5*Zx(2:IndexMaxX);
% Zxb(1:IndexMaxX-1)=Zxa(2:IndexMaxX);
% Zxb(IndexMaxX)=Zx(IndexMaxX);

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
% Zya(1)=Zy(1);
% Zya(2:IndexMaxY)=.5*Zy(1:IndexMaxY-1)+.5*Zy(2:IndexMaxY);
% Zyb(1:IndexMaxY-1)=Zya(2:IndexMaxY);
% Zyb(IndexMaxY)=Zy(IndexMaxY);

    EH1y_1=0;
    EH1y_2=0;
    EH1y_3=0;
    EH1y_4=0;
    EH1y_5=0;
    EH1y_6=0;
    EH1y_7=0;
    
    EH1x_1=0;
    EH1x_2=0;
    EH1x_3=0;
    EH1x_4=0;
    EH1x_5=0;
    EH1x_6=0;
    EH1x_7=0;


EH2x_1=0;
EH2x_2=0;
EH2x_3=0;
EH2x_4=0;
EH2x_5=0;
EH2x_6=0;
EH2x_7=0;

EH2y_1=0;
EH2y_2=0;
EH2y_3=0;
EH2y_4=0;
EH2y_5=0;
EH2y_6=0;
EH2y_7=0;

for nn=1:IndexMaxX
    
        EH1x_1=EH1x_1+Zx(nn).*XProbMass(nn);
        EH1x_2=EH1x_2+(Zx(nn).^2-1).*XProbMass(nn);
        EH1x_3=EH1x_3+(Zx(nn).^3-3*Zx(nn)).*XProbMass(nn);
        EH1x_4=EH1x_4+(Zx(nn).^4-6*Zx(nn).^2+3).*XProbMass(nn);
        EH1x_5=EH1x_5+(Zx(nn).^5-10*Zx(nn).^3+15*Zx(nn)).*XProbMass(nn);
        EH1x_6=EH1x_6+(Zx(nn).^6-15*Zx(nn).^4+45*Zx(nn).^2-15).*XProbMass(nn);
        EH1x_7=EH1x_7+(Zx(nn).^7-21*Zx(nn).^5+105*Zx(nn).^3-105.*Zx(nn)).*XProbMass(nn);
        EH2x_1=EH2x_1+Zx(nn).*Zx(nn).*XProbMass(nn);
        EH2x_2=EH2x_2+(Zx(nn).^2-1).*(Zx(nn).^2-1).*XProbMass(nn);
        EH2x_3=EH2x_3+(Zx(nn).^3-3*Zx(nn)).*(Zx(nn).^3-3*Zx(nn)).*XProbMass(nn);
        EH2x_4=EH2x_4+(Zx(nn).^4-6*Zx(nn).^2+3).*(Zx(nn).^4-6*Zx(nn).^2+3).*XProbMass(nn);
        EH2x_5=EH2x_5+(Zx(nn).^5-10*Zx(nn).^3+15*Zx(nn)).*(Zx(nn).^5-10*Zx(nn).^3+15*Zx(nn)).*XProbMass(nn);
        EH2x_6=EH2x_6+(Zx(nn).^6-15*Zx(nn).^4+45*Zx(nn).^2-15).*(Zx(nn).^6-15*Zx(nn).^4+45*Zx(nn).^2-15).*XProbMass(nn);
        EH2x_7=EH2x_7+(Zx(nn).^7-21*Zx(nn).^5+105*Zx(nn).^3-105.*Zx(nn)).*(Zx(nn).^7-21*Zx(nn).^5+105*Zx(nn).^3-105.*Zx(nn)).*XProbMass(nn);
end
    for nn=1:IndexMaxY
        EH1y_1=EH1y_1+Zy(nn).*YProbMass(nn);
        EH1y_2=EH1y_2+(Zy(nn).^2-1).*YProbMass(nn);
        EH1y_3=EH1y_3+(Zy(nn).^3-3*Zy(nn)).*YProbMass(nn);
        EH1y_4=EH1y_4+(Zy(nn).^4-6*Zy(nn).^2+3).*YProbMass(nn);
        EH1y_5=EH1y_5+(Zy(nn).^5-10*Zy(nn).^3+15*Zy(nn)).*YProbMass(nn);
        EH1y_6=EH1y_6+(Zy(nn).^6-15*Zy(nn).^4+45*Zy(nn).^2-15).*YProbMass(nn);
        EH1y_7=EH1y_7+(Zy(nn).^7-21*Zy(nn).^5+105*Zy(nn).^3-105.*Zy(nn)).*YProbMass(nn);
        
        EH2y_1=EH2y_1+Zy(nn).*Zy(nn).*YProbMass(nn);
        EH2y_2=EH2y_2+(Zy(nn).^2-1).*(Zy(nn).^2-1).*YProbMass(nn);
        EH2y_3=EH2y_3+(Zy(nn).^3-3*Zy(nn)).*(Zy(nn).^3-3*Zy(nn)).*YProbMass(nn);
        EH2y_4=EH2y_4+(Zy(nn).^4-6*Zy(nn).^2+3).*(Zy(nn).^4-6*Zy(nn).^2+3).*YProbMass(nn);
        EH2y_5=EH2y_5+(Zy(nn).^5-10*Zy(nn).^3+15*Zy(nn)).*(Zy(nn).^5-10*Zy(nn).^3+15*Zy(nn)).*YProbMass(nn);
        EH2y_6=EH2y_6+(Zy(nn).^6-15*Zy(nn).^4+45*Zy(nn).^2-15).*(Zy(nn).^6-15*Zy(nn).^4+45*Zy(nn).^2-15).*YProbMass(nn);
        EH2y_7=EH2y_7+(Zy(nn).^7-21*Zy(nn).^5+105*Zy(nn).^3-105.*Zy(nn)).*(Zy(nn).^7-21*Zy(nn).^5+105*Zy(nn).^3-105.*Zy(nn)).*YProbMass(nn);

    end
    
%     EH1y_1
%     EH1y_2
%     EH1y_3
%     EH1y_4
%     EH1y_5
%     EH1y_6
%     EH1y_7
%     
%     EH2y_1
%     EH2y_2
%     EH2y_3
%     EH2y_4
%     EH2y_5
%     EH2y_6
%     EH2y_7
% str=input('Look at hermite expectations');
corr1=0;
corr2=0;
corr3=0;
corr4=0;
corr5=0;
corr6=0;
corr7=0;
for nn=1:IndexMaxX
    for mm=1:IndexMaxY
        corr1=corr1+Zx(nn).*Zy(mm).*XYProbMass2D(nn,mm)/sqrt(EH2x_1)/sqrt(EH2y_1);
        corr2=corr2+(Zx(nn).^2-1).*(Zy(mm).^2-1).*XYProbMass2D(nn,mm)/sqrt(EH2x_2)/sqrt(EH2y_2);
        corr3=corr3+(Zx(nn).^3-3*Zx(nn)).*(Zy(mm).^3-3*Zy(mm)).*XYProbMass2D(nn,mm)/sqrt(EH2x_3)/sqrt(EH2y_3);
        corr4=corr4+(Zx(nn).^4-6*Zx(nn).^2+3).*(Zy(mm).^4-6*Zy(mm).^2+3).*XYProbMass2D(nn,mm)/sqrt(EH2x_4)/sqrt(EH2y_4);
        corr5=corr5+(Zx(nn).^5-10*Zx(nn).^3+15*Zx(nn)).*(Zy(mm).^5-10*Zy(mm).^3+15*Zy(mm)).*XYProbMass2D(nn,mm)/sqrt(EH2x_5)/sqrt(EH2y_5);
        corr6=corr6+(Zx(nn).^6-15*Zx(nn).^4+45*Zx(nn).^2-15).*(Zy(mm).^6-15*Zy(mm).^4+45*Zy(mm).^2-15).*XYProbMass2D(nn,mm)/sqrt(EH2x_6)/sqrt(EH2y_6);
        corr7=corr7+(Zx(nn).^7-21*Zx(nn).^5+105*Zx(nn).^3-105.*Zx(nn)).*(Zy(mm).^7-21*Zy(mm).^5+105*Zy(mm).^3-105*Zy(mm)).*XYProbMass2D(nn,mm)/sqrt(EH2x_7)/sqrt(EH2y_7);
        
    end
end

end
.
Here is the second new function that directly calculates the correlations between hermite polynomials without integrating over two dimensional joint density.
.
function [corrP1,corrP2,corrP3,corrP4,corrP5,corrP6,corrP7] = FindHermiteCorrelationsFromSimulationData_Infiniti_NEW04(X,Y,Paths,NoOfBinsX,NoOfBinsY)

%This function processes observations of X and Y to create their densities.
%We backout associated Zx and Zy on the density grid points using 
%inverse cdf function. 
%At the sametime whil calculating the above densities, we assign each 
%monte carlo path a grid index and distance from the center of the grid.
%This helps us quickly find Zxp associated with each monte carlo path by 
%interpolating values of Zx on the boundaries of the X grid. 
%grids.% Similarly This also helps us quickly find Zyp associated with 
%each monte carlo path by interpolating values of Zy on the boundaries 
%of the Y grid.
%Once we calculate Zxp and Zyp associated with each monte carlo path
%cheaply using above algorithm, we use them for finding path-wise
%correlation between hermite polynomials of Zxp and Zyp.
%We do not calculate two-dimensional density in this new function and two
%dimensional density is not needed.


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;


XProbMass(1:IndexMaxX)=0;
YProbMass(1:IndexMaxY)=0;
Yp(1:Paths)=0;
Ydelta(1:Paths)=0;
Xp(1:Paths)=0;
Xdelta(1:Paths)=0;

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


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

%Below we note the grid cell index associated with each monte carlo path
%This grid cell index means that Zxp associated with the particular path
%would lie within boundaries of this grid cell.
%We also calculate the displacement of monte carlo simulated path value 
%from the center of the grid cell.
%We can reconstruct each of the monte carlo simulated value from sum of 
% the centre of the associated grid cell and its displacement from 
%the centre of the particular grid cell.
Xp(p)=indexX;
Xdelta(p)=X(p)-Xn(indexX);



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

%Below we repeat the calculation of associated grid cell center and 
%displacement from the center of grid cell for simulated variable Y. 
Yp(p)=indexY;
Ydelta(p)=Y(p)-Ym(indexY);



%XDensity(index)=XDensity(index)+1.0/Paths/BinSize;
XProbMass(indexX)=XProbMass(indexX)+1.0/Paths;
YProbMass(indexY)=YProbMass(indexY)+1.0/Paths;
end


%Below Zxa is array carrying values of Z on left boundary of X grid cells
%Below Zxb is array carrying values of Z on right boundary of X grid cells
XCDF(1:IndexMaxX)=0;
Zxb(1:IndexMaxX)=0;
XCDF(1)=XProbMass(1);
Zxb(1)=norminv(XCDF(1));
for nn=2:IndexMaxX-1
    XCDF(nn)=XCDF(nn-1)+XProbMass(nn);
    Zxb(nn)=norminv(XCDF(nn));
end
Zxb(IndexMaxX)=norminv(XCDF(IndexMaxX-1)+.25*XProbMass(IndexMaxX));
Zxa(1)=norminv(XCDF(1)*.75);
Zxa(2:IndexMaxX)=Zxb(1:IndexMaxX-1);



%Below Zya is array carrying values of Z on left boundary of Y grid cells
%Below Zyb is array carrying values of Z on right boundary of Y grid cells
YCDF(1:IndexMaxY)=0;
Zyb(1:IndexMaxY)=0;
YCDF(1)=YProbMass(1);
Zyb(1)=norminv(YCDF(1));
for nn=2:IndexMaxY-1
    YCDF(nn)=YCDF(nn-1)+YProbMass(nn);
    Zyb(nn)=norminv(YCDF(nn));
end
Zyb(IndexMaxY)=norminv(YCDF(IndexMaxY-1)+.25*YProbMass(IndexMaxY));
Zya(1)=norminv(YCDF(1)*.75);
Zya(2:IndexMaxY)=Zyb(1:IndexMaxY-1);


%Below find values of Zx and Zy associated with each simulation path
%by cheaply interpolating from the values of Zx and Zy on boundaries of
%grid cells. Zxa is left boundary Z. Zxb is right boundary Z.
%Zya is value of Z on left boundary of Y grid and Zyb is Z on right boundary.
%For this we use originally calculated values of center of grid associated
%with each monte carlo path and displacement from center as I described
%earlier.
Zxp(1:Paths)=Zxa(Xp(1:Paths)).*(.5*BinSizeX-Xdelta(1:Paths))/BinSizeX+Zxb(Xp(1:Paths)).*(.5*BinSizeX+Xdelta(1:Paths))/BinSizeX;
Zyp(1:Paths)=Zya(Yp(1:Paths)).*(.5*BinSizeY-Ydelta(1:Paths))/BinSizeY+Zyb(Yp(1:Paths)).*(.5*BinSizeY+Ydelta(1:Paths))/BinSizeY;

%Below calculate hermite correlations by summing calculations of values 
%of hermite polynomials over all paths.

    corrP1=sum(Zxp(1:Paths).*Zyp(1:Paths))/sqrt(sum(Zxp(1:Paths).^2))/sqrt(sum(Zyp(1:Paths).^2));
    corrP2=sum((Zxp(1:Paths).^2-1).*(Zyp(1:Paths).^2-1))/sqrt(sum((Zxp(1:Paths).^2-1).^2))/sqrt(sum((Zyp(1:Paths).^2-1).^2));
    corrP3=sum((Zxp(1:Paths).^3-3*Zxp(1:Paths)).*(Zyp(1:Paths).^3-3*Zyp(1:Paths)))/sqrt(sum((Zxp(1:Paths).^3-3*Zxp(1:Paths)).^2))/sqrt(sum((Zyp(1:Paths).^3-3*Zyp(1:Paths)).^2));
    corrP4=sum((Zxp(1:Paths).^4-6*Zxp(1:Paths).^2+3).*(Zyp(1:Paths).^4-6*Zyp(1:Paths).^2+3))/sqrt(sum((Zxp(1:Paths).^4-6*Zxp(1:Paths).^2+3).^2))/sqrt(sum((Zyp(1:Paths).^4-6*Zyp(1:Paths).^2+3).^2));
    corrP5=sum((Zxp(1:Paths).^5-10*Zxp(1:Paths).^3+15*Zxp(1:Paths)).*(Zyp(1:Paths).^5-10*Zyp(1:Paths).^3+15*Zyp(1:Paths)))/sqrt(sum((Zxp(1:Paths).^5-10*Zxp(1:Paths).^3+15*Zxp(1:Paths)).^2))/sqrt(sum((Zyp(1:Paths).^5-10*Zyp(1:Paths).^3+15*Zyp(1:Paths)).^2));
    corrP6=sum((Zxp(1:Paths).^6-15*Zxp(1:Paths).^4+45*Zxp(1:Paths).^2-15).*(Zyp(1:Paths).^6-15*Zyp(1:Paths).^4+45*Zyp(1:Paths).^2-15))/sqrt(sum((Zxp(1:Paths).^6-15*Zxp(1:Paths).^4+45*Zxp(1:Paths).^2-15).^2))/sqrt(sum((Zyp(1:Paths).^6-15*Zyp(1:Paths).^4+45*Zyp(1:Paths).^2-15).^2));
    corrP7=sum((Zxp(1:Paths).^7-21*Zxp(1:Paths).^5+105*Zxp(1:Paths).^3-105*Zxp(1:Paths)).*(Zyp(1:Paths).^7-21*Zyp(1:Paths).^5+105*Zyp(1:Paths).^3-105*Zyp(1:Paths)))/sqrt(sum((Zxp(1:Paths).^7-21*Zxp(1:Paths).^5+105*Zxp(1:Paths).^3-105*Zxp(1:Paths)).^2))/sqrt(sum((Zyp(1:Paths).^7-21*Zyp(1:Paths).^5+105*Zyp(1:Paths).^3-105*Zyp(1:Paths)).^2));

%     Paths
%     corrP1
%     corrP2
%     corrP3
%     corrP4
%     corrP5
%     corrP6
%     corrP7
%     str=input('Look at CorrP1');
% 




end

.
.
.
Here is the output comparison of correlations calculated with both methods in the first step of simulation. This is directly copied from matlab screen. Please note that corresponding correlations calculated with each of the two methods match with each other well.

time1 =


   0.031250000000000


IndexMaxX =

   101


IndexMaxY =

   101


corr1 =

  -0.949183452536722


corr2 =

   0.899807263855206


corr3 =

  -0.850933403909789


corr4 =

   0.800799240531867


corr5 =

  -0.748708460339308


corr6 =

   0.692354670405357


corr7 =

  -0.636364169023430

Look at corrs--1--using two dimensional density

IndexMaxX =

   101


IndexMaxY =

   101


corr1 =

  -0.949810309939746


corr2 =

   0.901101916616058


corr3 =

  -0.853022697232446


corr4 =

   0.804356800948378


corr5 =

  -0.755360437736705


corr6 =

   0.702919493820407


corr7 =

  -0.644527734650945

Look at corrs--2--Directly between simulated Data observations of DX and DV
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: 2411
Joined: July 14th, 2002, 3:00 am

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

January 27th, 2023, 6:15 pm

Friends, in this post I want to present the ideas about hermite-specific correlation and regression that I have been mentioning for some time.
Suppose we have Z-series hermite representations of two correlated random variables as

[$]X= ah_0 \, + \, ah_1 H_1(Z_1)\, + \, ah_2 H_2(Z_1)\, + \, ah_3 H_3(Z_1)\, + \, ... + \, ah_n H_n(Z_1) [$]

and for Y

[$]Y= bh_0 \, + \, bh_1 H_1(Z_2)\, + \, bh_2 H_2(Z_2)\, + \, bh_3 H_3(Z_2)\, + \, ... + \, ah_n H_n(Z_2) [$]

please note that in hermite representation the constant term in RHS is always equal to mean. So we could have equally written

[$]X= \mu_X \, + \, ah_1 H_1(Z_1)\, + \, ah_2 H_2(Z_1)\, + \, ah_3 H_3(Z_1)\, + \, ... + \, ah_n H_n(Z_1) [$]

[$]Y= \mu_Y \, + \, bh_1 H_1(Z_2)\, + \, bh_2 H_2(Z_2)\, + \, bh_3 H_3(Z_2)\, + \, ... + \, ah_n H_n(Z_2) [$]

Suppose we have a large set of observations in pairs of X and Y and we want to find their hermite-wise correlation. This is only very natural since all hermite polynomial components of variance within each of the probability distribution are orthogonal to each other.

Suppose we have a total of P (as in total paths of joint evolution of both stochastic processes)  joint observations of stochastic processes X and Y.
For Finding Correlation between first hermite polynomial components, we write the equation for the correlation between first hermites as

[$]\rho_{XY,1} \, = \,  \frac{\displaystyle\sum_{p=1}^{P} ah_1 \, Z_{1,p} \, bh_1 \, Z_{2,p} \,}{\sqrt{\displaystyle\sum_{p=1}^{P} ah_1^2 \, {Z_{1,p}}^2 \,\displaystyle\sum_{p=1}^{P} \, bh_1^2 \, {Z_{2,p}}^2 \,}}[$]

Please notice that for calculation of above equation, we first have to find the specific values of [$] Z_{1,p}[$] and [$]Z_{2,p}[$] that are associated with particular pth observation of [$]X_p[$] and [$]Y_p[$] by some inversion method. I will comment on this inversion at the end of this post.
Similarly for 2nd hermite polynomial, we would have the correlation between X and Y equation calculated over joint observations of RVs as

[$]\rho_{XY,2} \, = \,  \frac{\displaystyle\sum_{p=1}^{P} ah_2 \, ({Z_{1,p}}^2-1) \, bh_2 \, ({Z_{2,p}}^2-1) \,}{\sqrt{\displaystyle\sum_{p=1}^{P} ah_2^2 \, {(Z_{1,p}^2-1)}^2 \,\displaystyle\sum_{p=1}^{P} \, bh_2^2 \, {({Z_{2,p}}^2-1})^2 \,}}[$]

similarly for nth hermite polynaomial correlations, we would write as

[$]\rho_{XY,n} \, = \,  \frac{\displaystyle\sum_{p=1}^{P} ah_n \, H_n(Z_1) \, bh_n \, H_n(Z_2) \,}{\sqrt{\displaystyle\sum_{p=1}^{P} ah_n^2 \, {H_n(Z_1)}^2 \,\displaystyle\sum_{p=1}^{P} \, bh_n^2 \, {H_n(Z_2)}^2 \,}}[$]

Please note that correlations are in joint products of hermite polynomials and their coefficients are only good to make sure they are non-zero and are important to determine the sign of correlation only.

We know from simple regression theory that once we know correlation between two variables, we can write the regression equation between them as

[$]Y \, = \, \mu_Y \, + \, \rho_{XY} \frac{s_Y}{s_X} \, (X\, - \, \mu_X) [$]

So we could write a variant of the above traditional formula in our new case with hermite correlations as

[$]Y \, = \, \mu_Y \, + \, \rho_{XY,1} \frac{bh_1}{ah_1} \, Z_1 \, + \, \rho_{XY,2} \frac{bh_2}{ah_2} \, ({Z_1}^2 -1) \, + \, \rho_{XY,3} \frac{bh_3}{ah_3} \, ({Z_1}^3 -3 Z_1) + ...+\, \rho_{XY,n} \frac{bh_n}{ah_n} \, H_n(Z_1)[$]

There is one caveat and that is when we are in mote carlo framework and we want to find above correlations and regressions, we have to invert extremely large number of observations of X and Y to find their underlying Z's as monte carlo paths usually would be very large. But this can safely be done by inverse-series in Bessel coordinates. The specific value of Z associated with observed/simulated data points remains the same in both bessel and original coordinates. Finding them in Bessel coordinates has extremely small error for most SDE distributions I encountered in 2D stochastic volatility models when inverse-series method is used. The error is somewhat larger in deep tails  but still quite small and we would get very valid estimates of correlations and regressions using this series inversion method as used in mathematica. 
Using series inversion in original coordinates would generally have much larger errors deep in the tail. But since The specific value of Z associated with observed/simulated data points remains the same in both bessel and original coordinates, we can find them in bessel coordinates (for much better accuracy) and then safely use the same value of Z for correlation and regression analytics in original coordinates.
I hope to post a worked out matlab program on this in another 2 days.
.
.
Please notice that method used in new function in the previous post is in line with the latex equations suggested in above copied post 1673. I have not used hermite coefficients in calculations of correlations since they would simply cancel out. In this new program, I have not used inverse series and rather used interpolation over a grid to find values of Z associated with monte carlo simulated random variables.
Over the weekend, I will be posting new programs for regression over several variables as suggested in post 1673 and in another post earlier.
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: 2411
Joined: July 14th, 2002, 3:00 am

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

January 28th, 2023, 3:31 pm

Friends, despite my repeated protests, mind control agencies continue to drug food and beverages throughout Lahore city even in many remote areas. Today I had my lunch at a small street restaurant and even though I was careful to make sure that staff did not add anything in the cooked food placed in trays after my arrival, I realized that food was mildly drugged after I had taken it. Restaurant staff must have been adding mind control chemicals regularly to their food. When I left the restaurant, the staff was looking very suspiciously at me. I believe Pakistan army agents reached there and tried to ask them to give me drugged water or something else. Some people who had come later also left simultaneously in a van when I left the small restaurant.
Later I tried to get good water for several hours, but I still could not get good water. Nestle and Dasani (coca-cola) water had been good in the market for past one year but Nestle water with new manufacturing dates is slightly drugged in the market. It is not extremely drugged to completely alter my state of consciousness and create extreme anxiety, but it is still slightly drugged to alter my mental state enough to not let me concentrate and work after I had taken Nestle water. Over past week, I tried Nestle water at many places where I was sure that Pakistan army would never have drugged bottled water but still Nestle water was not good. 
So today I spent several hours trying to get good water but to no avail. I bought water from multiple places while being extremely careful, and it was still not good. I also filled water bottles with water supply and water pumped from underground from several different places and I still could not get good water. Then I bought some sweet drinks of less known brands and came back home with water that was as good as I could find (though it was still drugged) after attempting several times.
I want to tell friends that mind control agencies and Pakistan army are not decreasing the persecution activity and drugging of food and beverages in the city. Underground water was good just a few days ago but I repeatedly failed to get good ground water today despite trying again and again. Even though they might be saying different things to good American people, mind control agencies are totally adamant and resolute in their attempts to retard me, and I do not think they will stop or decrease their activities anytime soon.
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