Giter Site home page Giter Site logo

avellaneda-stoikov's Introduction

Avellaneda-Stoikov HFT model implementation

Avellaneda-Stoikov HFT market making algorithm implementation

Quickstart

Set up python environment:

python3 -m virtualenv venv
#source venv/bin/activate #linux
venv\Scripts\activate.bat # windows

Install dependencies:

pip install -r requirements.txt

Check model parameters in main.py and then execute the code:

python main.py

Results

Figure 1 show results of a simulation using the following parameters:

  • gamma: 0.1
  • sigma: 2
  • T: 1
  • k: 1.5
  • M: 0.5

The first chart shows price, indiference price and bid, ask quotes evolution. The second chart shows the profit and loss evolution. The last chart shows the inventory evolution.

Simulation Results

Figure 2 shows the distribution of PnL over 1000 simulations.

Pnl Histogram

avellaneda-stoikov's People

Contributors

fedecaccia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

avellaneda-stoikov's Issues

Sigma Unit in Avellaneda -Stoikov market making model

In Reserve Price Equation and Reserve Spread Equation, sigma ** 2 is used to measure market volatility risk, like

            r[n] = s[n] - q[n] * gamma * sigma ** 2 * (T - dt * n)
            r_spread = 2 / gamma * math.log(1 + gamma / k) + gamma * (sigma ** 2) * (T - t / float(M))

sigma*2 is given by preset in demo code to generate brownian process, and it can be calculate by std of brownian path.
As I do such experiment, I found interesting thing

import numpy as np
import brownian as bm

delta = 2  # The Wiener process parameter.
T = 10.0  # Total time.
N = 500  # Number of steps.
dt = T / N  # Time step size
m = 100  # Number of realizations to generate.
x = np.empty((m, N + 1))  # Create an empty array to store the realizations.
x[:, 0] = 1000  # Initial values of x.
bm.brownian(x[:, 0], N, dt, delta, out=x[:, 1:])

# %% check std and vol risk price
std = np.diff(x, axis=1).std(axis=1) / np.sqrt(dt)
# all sequence std close to delta
np.testing.assert_allclose(delta, std, rtol=0.1)
# so vol risk is gamma * sigma ** 2 = 4 * gamma, risk value / S0 is 4 * gamma / 1000 = 0.004 gamma

# %% round x to min float price 0.1, std value and risk value is not change
x_round = np.round(x, 1)
std_round = np.diff(x_round, axis=1).std(axis=1) / np.sqrt(dt)
np.testing.assert_allclose(delta, std_round, rtol=0.1)

# %% If price Unit changed, like previous unit is dollar/gram, to dollar/10gram, aka new price is 10 * x

x_10 = 10 * x_round
std_10 = np.diff(x_10, axis=1).std(axis=1) / np.sqrt(dt)
# std also times 10 times
np.testing.assert_allclose(delta * 10, std_10, rtol=0.1)
# so vol risk is gamma * sigma ** 2 = 400 * gamma, risk value / S0 is 400 * gamma / 10000 = 0.04 gamma

So, why vol risk changed when we just change price unit?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.