[PYTHON] I calculated the stochastic integral (I to integral)

■ There are the following methods for stochastic integration

Riemann sum formula) $ \sum_{j=0}^{N-1} h(t_j) (t_{j+1}-t_j) $

Ito integral. Stochastic process method extended by Kiyoshi Ito formula) $ \sum_{j=0}^{N-1}h(t_j) (W(t_{j+1})-W(t_j)) $. <=> $ \int_0^{T} h(t)dW(t) $.

Stratonovich integrals formula) \sum_{j=0}^{N-1}h\big(\frac{t_j+t_{j+1}}{2}\big)(W(t_{j+1})-W(t_j))

Ito integral calculation

When $ h (t) \ equiv W (t) $, Ito integral is

\begin{align*}
\sum_{j=0}^{N-1} W(t_j) (W(t_{j+1})-W(t_j)) \\
&=\sum_{j=0}^{N-1} ({W(t_{j+1})}^2 - {W(t_{j+1})}^2 + 2 W(t_j) W(t_{j+1}) - {W(t_j)}^2  - {W(t_j)}^2) \\
&= \frac{1}{2} \sum_{j=0}^{N-1} ({W(t_{j+1})}^2 - {W(t_j)}^2 - (W(t_{j+1}) - W(t_j))^2 )\\
&= \frac{1}{2} (W(T)^2 - W(0)^2)  -  \frac{1}{2} \sum_{j=0}^{N-1} (W(t_{j+1}) - W(t_j))^2
\end{align*}

$ \ sum_ {j = 0} ^ {N-1} (W (t_ {j + 1}) --W (t_j)) ^ 2 $ is equal to the variance of the Wiener Process and can be set to $ T . $ \ sum_ {j = 0} ^ {N-1} (W (t_ {j + 1}) --W (t_j)) ^ 2 = \ frac {1} {2} (W (T) ^ 2- It can be expressed as T) $$.

Let's calculate Ito integral.

N=10000;
M=1;
T = 1.0
dt = T / N;

t = np.arange(0.0,1.0, dt);
dW = np.sqrt(dt)*randn(N,M); # (N, M)queue
W = np.cumsum(dW,axis=0);
e = np.array([[0]])
W_=np.concatenate((e,W[:-1]), axis=0)  #Put 0 in the initial value W(0)As.

ito = np.dot(W_.T,dW) # (10000, 1).T * (10000, 1)  => (1, 1)
np.abs(ito - 0.5*(W[-1]**2 - T) )[0][0]

## output
##  0.00414652405737

Reference article

https://www.semanticscholar.org/paper/An-Algorithmic-Introduction-to-Numerical-Simulation-Higham/1c4126f96df7690dd40dab5f34ee4be5a5f95fbb

--Wikipedia "Kiyoshi Ito" https://ja.wikipedia.org/wiki/%E4%BC%8A%E8%97%A4%E6%B8%85

Recommended Posts

I calculated the stochastic integral (I to integral)
I tried to move the ball
I tried to estimate the interval.
I want to pin Spyder to the taskbar
I want to output to the console coolly
I tried to summarize the umask command
I want to handle the rhyme part1
I want to handle the rhyme part3
I tried to summarize the graphical modeling.
I tried to estimate the pi stochastically
I tried to touch the COTOHA API
I want to display the progress bar
I want to handle the rhyme part2
I want to handle the rhyme part5
I want to handle the rhyme part4
I tried web scraping to analyze the lyrics.
I tried to optimize while drying the laundry
I tried to save the data with discord
I wanted to play with the Bezier curve
I want to handle the rhyme part7 (BOW)
I tried to correct the keystone of the image
Qiita Job I tried to analyze the job offer
[Python] I will upload the FTP to the FTP server.
I want to customize the appearance of zabbix
LeetCode I tried to summarize the simple ones
I want to use the activation function Mish
I tried to implement the traveling salesman problem
I want to display the progress in Python!
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
I want to see the file name from DataLoader
I tried to graph the packages installed in Python
I tried to detect the iris from the camera image
I want to grep the execution result of strace
I want to scroll the Django shift table, but ...
I tried to summarize the basic form of GPLVM
I tried to touch the CSV file with Python
I started to analyze
I tried to solve the soma cube with python
I wanted to use the Python library from MATLAB
I want to inherit to the back with python dataclass
I want to fully understand the basics of Bokeh
I tried to debug.
I tried to approximate the sin function using chainer
I tried to put pytest into the actual battle
[Python] I tried to graph the top 10 eyeshadow rankings
I want to write in Python! (3) Utilize the mock
I tried to visualize the spacha information of VTuber
I tried to paste
The road to Pythonista
I tried to erase the negative part of Meros
I made a command to markdown the table clipboard
I tried to solve the problem with Python Vol.1
I felt that I ported the Python code to C ++ 98.
What I did to ssh to the VPS Ubuntu environment
I want to handle the rhyme part6 (organize once)
I want to automate ssh using the expect command!
I tried to simulate the dollar cost averaging method
I want to publish the product at the lowest cost
I counted the grains
I tried to redo the non-negative matrix factorization (NMF)