← Simulation & Statistics

Simulation & Statistics · Part 10 of 12

Wiener Process

In a Wiener process w(t):

  1. If the time intervals [s, t] and [s', t'] do not intersect, then the increments w(t) - w(s) and w(t') - w(s') are independent random variables.
  2. As the increments w(t) - w(s) are normal random variables with E{w(t) - w(s)} = 0 and Var{w(t) - w(s)} = t - s

This way we have that w(ti+1) - w(ti) ~ N(0, ti+1 - ti) for the simulation.

Simulation

Given a normal random variable w(ti+1) = w(ti) + √(ti+1 - ti) due time instants ti is posible to pick them as we see fit, as the moment in which two instants are -sufficiently short- to match to other process simulated on the system.

Brownian Movement

Is given by the following equation:

Brownian motion: x(ti+1) − x(ti) = μ(ti+1 − ti) + σ(w(ti+1) − w(ti)), a drift plus a scaled Wiener step

For the simulation we will use

Simulation step: x(ti+1) = x(ti) + μ(ti+1 − ti) + σ √(ti+1 − ti) · ζ, where ζ is a standard normal number

Geometric Brownian Movement

Is given by the following stochastic differential equation

Geometric Brownian motion: dx(t) = μ x(t) dt + σ x(t) dw(t)

Its solution can be written in the following way

Its solution: x(ti+1) = x(ti) · exp{(μ − σ²/2)(ti+1 − ti) + σ · w(ti+1)}

Result

The $ Exchange window set up for a run: initial price 73.0738, 10 days, and an empty chart

A 10-day run from 73.0738: the price crashes to near 0 on day 1, then jumps in spikes to 23.71 on day 4 and 38.11 on day 8

The Buy/Sell window on day 8: $1 buys 38.11 rubles, with $100 available to exchange on the Buy tab

Implementation

C#
Random random = new Random();
const int miu = 1;
const double k = 0.1; //0.02

int days = (int) inputDays.Value;
double price = (double) inputPrice.Value;

chart1.Series[0].Points.AddXY(0, price);

for (int i = 1; i <= days; i++)
{
    //price = price * (1 + k * (random.NextDouble() - 0.5));
    // e^((miu - (price*price/2)) * k + price * random)
    double w = miu + Math.Sqrt(k) * (random.NextDouble() - 0.5);
    price = Math.Exp((miu - (price*price/2)) * k + (price * w));
    chart1.Series[0].Points.AddXY(i, price);
}