Skip to content

Instantly share code, notes, and snippets.

@louismeunier
Created April 8, 2025 12:58
Show Gist options
  • Select an option

  • Save louismeunier/b7793e840be8bf0ed03ffeb08e4d1e84 to your computer and use it in GitHub Desktop.

Select an option

Save louismeunier/b7793e840be8bf0ed03ffeb08e4d1e84 to your computer and use it in GitHub Desktop.
sdes.m
(* Stochastic Logistic Model Simulations (essentially just geometric Brownian motion) *)
M = 5000; (* Sample size *)
T = 5; (* Max time to simulate to *)
Datum1 = Table[2 RandomInteger[] - 1, {j, 1, M*T}];
Datum2 = Table[2 RandomInteger[] - 1, {j, 1, M*T}];
Datum3 = Table[2 RandomInteger[] - 1, {j, 1, M*T}];
B[t_, 1] := (1/Sqrt[M]) * Sum[Datum1[[j]], {j, 1, Floor[M*t]}];
B[t_, 2] := (1/Sqrt[M]) * Sum[Datum2[[j]], {j, 1, Floor[M*t]}];
B[t_, 3] := (1/Sqrt[M]) * Sum[Datum3[[j]], {j, 1, Floor[M*t]}];
Nr[t_, 1] := Exp[1/2 t + B[t, 1]];
Nr[t_, 2] := Exp[1/2 t + B[t, 2]];
Nr[t_, 3] := Exp[1/2 t + B[t, 3]];
Plot[{
Nr[t, 1],
Nr[t, 2],
Nr[t, 3],
Exp[t]
}, {t, 0, T - .5},
PlotRange -> Full,
PlotTheme -> "Minimal",
PlotStyle -> {
{Blue, Thickness[0.0015]},
{Magenta, Thickness[0.0015]},
{Purple, Thickness[0.0015]}, {Red, Thickness[0.004]}
}
]
(* Plot just some instance of Brownian Motion *)
Plot[B[t, 3], {t, 0, T}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment