Need Help with coding in Python

profiletimtimnbebe
pricing_simulator.docx

Pricing Simulator

Inputs would be:

Asset price (initial worth of the traded stock before entered into the simulation) which can be derived from average available online like Ibbotson.

Formula ex. Brownian motion, Fractal, random walks, etc to be used for price generation trend.

Python example:

'''
geometric brownian motion with drift!
    mu=drift factor [Annahme von Risikoneutralitaet]
    sigma: volatility in %
    T: time span
    dt: lenght of steps
    S0: Stock Price in t=0
    W: Brownian Motion with Drift N[0,1] 
'''

import matplotlib.pyplot as plt

import numpy as np

T = 2

mu = 0.1

sigma = 0.01

S0 = 20

dt = 0.01

N = round(T/dt)

t = np.linspace(0, T, N)

W = np.random.standard_normal(size = N)

W = np.cumsum(W)*np.sqrt(dt) ### standard brownian motion ###

X = (mu-0.5*sigma**2)*t + sigma*W

S = S0*np.exp(X) ### geometric brownian motion ###

plt.plot(t, S)

plt.show()

The example above will yield a price simulation we still need to simulate: volume fluctuations and generate trades around the graph simulation buys and sells.

Average volatility to be simulated which than will be randomly influenced to simulate real market conditions like announcements, news, follower pattern (where people join the buying or selling trend).

A multiplier when volatility increases the volume increases.

A sharp price drop will trigger a volume increase in shorting the stock. Change in Delta

A sharp price increase will trigger a volume increase in longing the stock. Change in Delta

Volume: Companies with about 30 million outstanding shares have average volumes of 200k. Which is about 476 transactions a minute or 8 a second with an influx around announcements and opening hours.

Anticipated volume ~ 150000 trades per day which is the average of stock with a 200mi market cap.

Pseudo code:

for ( test duration ) To simulate an 8 hour day in 10 minutes we need 260 trades a second for 10 minutes

Generate 8 Orders with Brownian motion and store them in array

Generate 8 Orders with in vicinity of first set using a random small multiplier .01 ~ .05 X Order

Resend the Original 8 orders stored in Array with opposing side to generate trades.

If price has downward motion for 4 ticks increase short sales volume by 4 until next single upward motion

If price has upward motion for 6 ticks increase long sales volume by 2 until next downward motion