mdibo / avellaneda-stoikov Goto Github PK
View Code? Open in Web Editor NEWPython code for High-frequency trading in a limit order book by Marco Avellaneda and Sasha Stoikov
Python code for High-frequency trading in a limit order book by Marco Avellaneda and Sasha Stoikov
as issue
same experiment, if I change price unit in S generator, vol risk value changed. It is not make sense, So what is wrong in my experiment.
import math
import numpy as np
def vol_risk_price(price_unit=1):
S0 = 100. # initial price
T = 1.0 # time
sigma = 2 # volatility
M = 200 # number of time steps
dt = T / M # time step
Sim = 1000 # number of simulations
I = 1
std = list()
for i in range(1, Sim + 1):
###reservation price:
### r(s,t) = s - q * gamma * sigma**2 * (T-t)
S = np.zeros((M + 1, I))
S[0] = S0
for t in range(1, M + 1):
z = np.random.standard_normal(I)
S[t] = S[t - 1] + sigma * math.sqrt(dt) * z
std.append(np.diff(S[:, 0] * price_unit).std(ddof=1) / np.sqrt(dt))
average_risk_percent_in_s0 = np.mean(std) ** 2 / (S0 * price_unit)
return average_risk_percent_in_s0
var = vol_risk_price()
# 0.04 = 2**2 / 100
np.testing.assert_allclose(var, 0.04, rtol=0.1)
var = vol_risk_price(10)
# 0.04 = 20**2 / 1000
np.testing.assert_allclose(var, 0.4, rtol=0.1)
Hi Marco! I was working also in an implementation of this algorithm, and I had a doubt about how to compute probabilities. Researching, I found your code and I see you compute probabilities of order execution using the following formula:
probA = 1 - np.exp(-lambdaA * dt)
instead of just use
probA = lambdaA * dt
as I undertand the authors explain.
Why do you use this implementation? Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.