Add to your simulation program, the simulation of the SDE for Geometric Brownian motion and Vasicek process.
#Code VB.Net
https://drive.google.com/file/d/1H0-ZDydHAcNYE99PgGGagWG48yS0qGPj/view?usp=sharing
The code contains the stochastic processes of the applications:
- 13_A
- where represent the sum of i Bernoulli random variables px(1-p)(1-x) observed at the times j=1, …, i.
- Represent with histogram the distribution of f(i) at different time. (f(i) is the sum of i Bernoulli random variables)
- compute the absolute and relative frequency of the f(i)’s contained in the interval (p-ε, p+ε)
'generate for m paths n points
Public Function Generate_path() As Path
...
for i = 0 to n
...
p = 0.5 ' or a value between 0,1
Dim v As Double = R.NextDouble
If v <= p Then
path.sequence.Add(0)
else
path.sequence.Add(1)
...
next
...
End Function
- 15_A
- where illustrate the Glivenko-Cantelli theorem
- and create both the histogram and the empirical CDF of the sample mean
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'Increase m and n for closer to theor function
For i = prec_m To m - 1
listOfPath.Add(Generate_glCantPath(i))
Next
...
n += 1
prec_m = m
m += n
End Sub
' Uniform convergence of empirical CDF to the theoretical convergence
'1/n*(sum of indicator function)
Public Function Generate_glCantPath(m_path As Integer) As Path
...
For i = 0 To n
Dim ran As Double = R.NextDouble() * 100
If ran < v Then
path.sequence.Add(1)
path.gl_canMean += 1
Else
path.sequence.Add(0)
path.gl_canMean += 0
End If
Next
path.gl_canMean /= n
...
End function
- 18_A
- where represent Poisson Distribution
- P(i) = P(i-1) + Random step(i), for i = 1, …, n, where Random step(i) is now a Bernoulli random variable with success probability equal to λ * (1/n)
- represent with histogram the distribution of P(i).
- Represent also the distributions of the following quantities (and any other quantity that you think of interest):
- Distance (time elapsed) of individual jumps from the origin
- Distance (time elapsed) between consecutive jumps
'generate for m paths n points
Public Function Generate_path() As Path
...
for i = 1 to n +1
...
Dim prob As Double = path.probability(i - 1)
p = lambda/n' or a value between 0,1
Dim v As Double = R.NextDouble
If v <= p Then
path.probability.Add(prob + v)
else
path.probability.Add(prob)
...
next
...
End Function
- 20_A
- where represent Brownian Motion
- P(t) = P(t-1) + Random step(t), for t = 1, …, n, where Random step(t) is now: σ * sqrt(1/n) * Z(t), where Z(t) is a N(0,1) random variable
- represent with histogram the distribution of P(t).
'Generate N(0,1)
Public Function Generate_z()
Dim u1 As Double
Dim u2 As Double
Dim s As Double = 1.0
While s >= 1.0
u1 = 2.0 * R.NextDouble - 1
u2 = 2.0 * R.NextDouble - 1
s = u1 * u1 + u2 * u2
End While
Return u1 * Math.Sqrt((-2 * Math.Log(s)) / s)
End Function
Public Function Generate_pathNormal()
...
For i = 1 To n
Dim z As Double = Generate_z()
'Generate Rademacher random variable
Dim v As Double = R.NextDouble * 2.0 - 1
Dim rand As Double = (sigma / Math.Sqrt(n) * z)
If v <= rand Then
...
End if
...
End Function
- 23_A
- Geometric Brownian motion
- Vasicek process
https://drive.google.com/file/d/1OXINcmOoxhJx-ptDG324MYrnrg_xfqZx/view?usp=sharing

Collaboration:
Luca Scarmozzino https://stats4cyber.wordpress.com/












