Skip to content

Instantly share code, notes, and snippets.

@Nikolaj-K
Last active January 12, 2021 23:01
Show Gist options
  • Save Nikolaj-K/8c56fe6f3c0287b34a130652dbf338cd to your computer and use it in GitHub Desktop.
Save Nikolaj-K/8c56fe6f3c0287b34a130652dbf338cd to your computer and use it in GitHub Desktop.
linear-normal rising stock model
import numpy as np
import matplotlib.pyplot as plt
# Config
n = 1000 # Compute 1000 grid points
ys = np.zeros(n + 1)
ys[0] = 25000 # $
y_fin = 32000 # $
sigma = 22 # $
t_init = 200000 # day
t_end = 200112 # day
mu = (y_fin - ys[0]) / n # $ per time
dt = float(t_end - t_init) / n # per time
ts = np.arange(t_init, t_end + dt, dt)
# Stochastics
def dW(t):
# This model is currently actually independent of t
# Note: Use e.g. Levy flights for something wilder,
# or maybe there's something more natural in stock prices
return np.random.normal(loc=0.0, scale=np.sqrt(dt))
# Simulate
for i in range(1, ts.size):
t = (i - 1) * dt
y = ys[i - 1]
ys[i] = y + mu * dt + sigma * dW(t)
# Plot
plt.plot(ts, ys, c="green")
plt.xlabel("day time")
plt.title("fucking Bitcoin")
h = plt.ylabel("$$$")
h.set_rotation(0)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment