Project presented as a partial fullfilment requirement for the Cardano Developer Professional (CDP) program.
An implementation of the Stochastic Supply Curve (Çetin, Jarrow & Protter, 2004) based on Blais & Protter (2010), Árdal (2013) and Hossaka (2018) approaches through Binance's API endpoint live feed data.
- Network.Wreq API on Binance's endpoint;
- IO JSON Parser for GET method data;
- Implementation of records and data types;
- Treating data and getting indicators;
- Simple SSC regression;
- Checking OLS results;
- R2.
- Organising files (app.Main, app.Utils, app.SSC): the damn thing is running with
cabal repl
,:l repl.hs
and by calling themain
function explicitly (cabal run
not working); - Static plots on Haskell (no cheating with R or Python);
- Live updates of plots (cheating with Python);
- CSV live feed update (cheating with Python);
- Real time plots. Kinda of...
system $ "python pyfile.py"
; - Better threads and making
system $ "python pyfile.py"
to call for the proper virtual env (or conda env).
- Definitely improving the types in the future...
- Saving CSV with Haskell;
- Concurrent non-vanishing thread (
controlProcess
instead of the simplesystem $
); - Plotting with Haskell seems only feasible under Nix ¬¬;
- Implement Stoikov (2018)!!!
Python has to be installed with the libraries in requirementsPy.yaml. livePlot_AAAA.py
scripts have to be run separately (after or during run cabal
), one environment for each possible plot.
Both saving CSV writting and live plotting are base on the scripts on py_files folder... ... to be improved.
Classical Geometrical Brownian Motion:
The Stochastic Process for an asset price
Under this economy, the expectation of the cash balance at the end of the execution schedule,
The first term is the Mark-to-Market value of the portfolio at time
The third and final term, the Liquidity Cost, is the only one varying with the control $(v_{t}){t \in [0,T]}$. The function $L\left(\frac{v{t}}{V_{t}}\right)$ is assumed to be convex and it is minimal when is proportional do
The "Saw-Tooth Pattern": Lehalle (2012) and Guéant (2016):
The Limit Order Book (LOB from now on) is considered to be the ``ultimate microscopic level of description of financial markets´´ (Bouchaud et. ali, 2002).
Even though it is a static picture, a snapshot of market conditions at a fixed time, it is far from being stationary and well-behaved: complicated global phenomena emerge from interactions between heterogeneous agents (Gould et. ali, 2013).
Market conditions may be path-dependent and building a LOB through time relies heavily on data consistency and studying its conditional behavior is complex. As explained by Gould et ali (2013) this is so because its state space is huge: if there are P different choices for a price in a given LOB, then the state space of the current depth (volume/quantity for a bid/ask price) profile alone expressed in a lot size
A LOB organizes prices and quantities for an order-driven market and, as one the main points in this work, when there is Market Liquidity Risk it may change and change deeply, rapidly and drastically.
Let
Since the volume is monotone over the depth of each side of the LOB, the Stochastic Supply Curve is expected to have an upward slope such as follows:
A possible simple estimate of the
If
Parametric interpretation of log-level assumes a convenient form in this approach. Taking the derivative of Y with respect to
This means that a change in one
Mid-price:
Imbalance:
Weighted mid-price:
Bid-ask spread:
The mid-price:
- Not a martingale (Bid-ask bounce);
- Medium frequency signal;
- Doesn't use volume at the best bid and ask prices.
The weigheted mid-price:
- Uses the volume at the best bid and ask prices;
- High frequency signal;
- Is quite noise, particularly when the spread widens to two ticks.
Reproduce ideas from Hossaka (2018) in Haskell, specially based on the following plots with live feed data!
Both plots report price moevements of MULT3 Brazilian equity on March 20th 2017.
The first plot gives the path of the
The second one gives the path of the bid and ask prices.
The animated gif below shows the evolution of the Stochastic Supply Curve minute-by-minute.
Robert Almgren and Neil Chriss. Value under liquidation. Risk, 12(12):61–63, 1999.
Hannes Ardal. A supply curve analysis for the Icelandic Housing Financing Fund bond market. PhD thesis, University of Iceland, 2013.
Marcel Blais and Philip Protter. An analysis of the supply curve for liquidity risk through book data.International Journal of Theoretical and Applied Finance, 13(06):821–838, 2010.
Jean-Philippe Bouchaud, Marc M´ezard, Marc Potters, et al. Statistical properties of stock order books: empirical results and models. Quantitative finance, 2(4): 251-256, 2002.
Umut Çetin, Robert A Jarrow, and Philip Protter. Liquidity risk and arbitrage pricing theory. Finance and stochastics, 8(3):311–341, 2004.
Umut Cetin, Robert Jarrow, Philip Protter, and Mitch Warachka. Pricing options in an extended black scholes economy with illiquidity: Theory and empirical evidence. The Review of Financial Studies, 19(2):493–529, 2006
Martin D Gould, Mason A Porter, Stacy Williams, Mark McDonald, Daniel J Fenn, and Sam D Howison. Limit order books. Quantitative Finance, 13(11): 1709-1742, 2013.
Guilherme Hideo Assaoka Hossaka. Stochastic Supply Curves and Liquidity Costs: Estimation for Brazilian Equities. MSc dissertation, School of Applied Mathematics (EMAp), Getúlio Vargas Foundation - RJ, 2016.
Sasha Stoikov. The micro-price: a high-frequency estimator of future prices. Quantitative Finance. Taylor & Francis Journals, vol. 18(12), 1959-1966, 2018.