Monday, March 2, 2015
Basically the idea is to allow the user to come up with trading algorithms easily by simply connecting different modules with "cables" and eventually routing the output to (for example) a chart/plot. I've found however that it's also a very useful data munging tool for data pre-processing and analysis. One picture is worth n words, so here's a screenshot (click for full size image):
Here I took the bid and ask prices for AAPL during one day and sent it to the Chart on the right. Then I took the cumulative dollar value trades (price * quantity * sign... basically the order flow), discarded the hidden orders and sent it to the Chart on a different axis. Pretty simple!
Getting the order flow took a bit too many modules (Multiply, Not and Sum modules), but it was pretty quick to do. It might make sense to have a custom "Function" module which would have user defined inputs and outputs and a simple mathematical expression between... anyway, the product is still in beta and developing fast, so maybe that will be implemented eventually. Mind you, there is a custom "JavaModule", but since I don't really know Java, it's pretty useless for me... anyway, I've heard a Python module is coming too!
Also, if you have a trading algorithm in mind, you can run a full backtest... and this is with event time data, bid and ask prices, trades etc... basically full order book data with all orders sent to the order book (not just trades as in my example above). Pretty impressive when compared to e.g. Quantopian's 1 min bars...
Wednesday, February 4, 2015
Using Ipython Notebook and Theano on an AWS GPU machine
Friday, October 10, 2014
Cython is awesome
...and here's the Cython optimized version:
Previously I had to wait about 30s for 1000000 iterations, and now it takes only about .1 seconds... definitely worth the effort ;) (BTW sorry about the lack of documentation... anyway, the algo has an adaptive time step, since I'm simulating some pretty wildly behaving SDEs).
Wednesday, August 6, 2014
Anyway, the idea is roughly as follows (it's been a while since I worked on this stuff, so my apologies for some possible inaccuracies): let's pretend we live in a two dimensional universe and that this universe is a two dimensional quantum gravity theory, which is "asymptotically $AdS_2$", which is very similar to a hyperbolic plane $\mathbb H_2$ but of minkowskian signature (google it or stop reading). Or just think of $\mathbb H_2$. The "asymptotic symmetries" of $\mathbb H_2$ are such diffeomorphisms which preserve the metric near the boundary. For $\mathbb H_2$ these symmetries are isomorphic to circle diffeomorphisms $Diff(S^1)$, which is an infinite dimensional group. The only thing we need to assume about the quantum gravity theory is that it is integrable w.r.t to the asymptotic symmetries, which in this context just means that every physical state can be mapped to another physical state by the asymptotic symmetries extended to all of the space (a la Conformal Field Theory).
The toy model I used in the "Easy Holography" paper was basically just a pixelated image (of a bunny, since it was submitted on Easter). A rough estimate of the entropy of that "model" is then a logarithm of the number of all distinct images that are mapped from an original image by the asymptotic symmetry group, which is isomorphic to $Diff(S^1)$.
Wednesday, December 18, 2013
Finally managed to complete an early version of my PyArb statistical arbitrage project... I published it in GitHub as a Python module here, although the best way to view it right away would be to check out the IPython Notebook here at nbviewer.ipython.org. It is a model dependent equity statistical arbitrage backtest module for Python. Roughly speaking, the input is a universe of N stock prices over a selected time period, and the output is a mean reverting portfolio which can be used for trading. The idea is to model "interacting" (correlated, anticorrelated or cointegrated) stock prices as a system of stochastic differential equations, roughly as
$$ dX_t^i = A^i_j X_t^j dt + X_t^i dW_t^i,$$
where $X_t$ are the prices and $dW_t$ are white noises.
The stochastic part doesn't yet play any important role, but that will soon change...
This is just a backtest for a strategy, so there's no saying it will actually work in a live situation (but I'm planning to try paper trading next). Specifically, there's no slippage and impact modelling, short sell contract and borrow costs etc. I just assumed a flat rate \$.005 per share cost from Interactive Brokers' website as a sort of ballpark figure. It gives a roughly 12% annualized returns with a Sharpe ratio of about 5 and a maximum drawdown of 0.6%. Maybe that sounds a bit too good to be true? Well maybe I made a mistake, go ahead and check the code! :) (I need to check it again myself anyway or give it a go in e.g. Quantopian).
Here's a plot of the cumulative returns for a period of about 300 days. The "mode=0" is the best portfolio and corresponds to the lowest eigenvalue of the evolution matrix $A$ in the equation above.
Saturday, September 14, 2013
Market data structure functions
I recently got some minute level stock market data from The Bonnot Gang for some data analytic (and stat arb design) purposes, when I noticed some funny behavior in the data structure function. Now the concept of a structure function may not be very widely known with quants/ data analysts/ economists, so here's a definition:
Suppose there's a time series
where for a given sample of data you just replace the ensemble expectation
These types of structure functions have been studied for some time now in finance in the context of similarities between financial markets and hydrodynamic turbulence. I think it all started in 1996 with the paper Turbulent cascades in foreign exchange markets by Ghashghaie et al. They computed the structure functions for some FX market data, and found a scaling relation
So I did some of my own data analysis with the Bonnot Gang data (I hope it's not bad data!). Here's a few plots of the structure functions, first for
This is close to linear, i.e.
Clearly you can't fit a power law in all of this, but there seems to be clear power law regimes divided by about 6, 18, 60 and 180 minutes! I don't know the reason for this, but if I had to guess, I'd say it's because of traders/ algorithms operating w.r.t different data timeframes... or maybe it's because of the finite tick size...
Anyway, I don't have time to get to the bottom of this, but maybe someone else will... so if you see this stuff on a paper someday, you saw it first here!! ;)
Written with StackEdit. Try it out, it's awesome!! You can do MathJax and sync everything in Google Drive or Dropbox and publish directli in Blogger, Wordpress, Tumblr etc.!
Tuesday, April 30, 2013
From a mathematical point of view, I was a bit awe-struck by Pierre Henry-Labordere's "Analysis, Geometry and Modeling in Finance". Apparently there's a close connection between the geometry of black holes (well, at least the hyperbolic types) and stochastic volatility models! It would be extremely cool to be able to actually research and design models like that which would actually work and be useful! Anyway, I doubt real quant life is that fancy, but I'll be happy if the job involves PhD level math of some kind.
I'd love to hear other people's stories about switching from academia to industry or finance. Anyone here with similar experiences?