How I made $500k with machine learning and high frequency trading(jspauld.com)
jspauld.com
How I made $500k with machine learning and high frequency trading
http://jspauld.com/post/35126549635/how-i-made-500k-with-machine-learning-and-hft
308 comments
I don't have much experience with finance or working experience with machine learning, but I've always wondered how much room there was for a clever amateur to profit in this space, even as it's crowded with much more sophisticated professionals with much more sophisticated algorithms and machines.
I'm thinking back to Garry Kasparov's piece in the NY Book Review a couple years back: http://www.nybooks.com/articles/archives/2010/feb/11/the-che...
He talks about a chess tournament in which it was "anything goes"...competitors could be human, computers, or humans with computers. The expected outcome was that a grandmaster using a Deep Blue-like computer would win, but the winners ended up being a couple of amateurs with three computers:
> The surprise came at the conclusion of the event. The winner was revealed to be not a grandmaster with a state-of-the-art PC but a pair of amateur American chess players using three computers at the same time. Their skill at manipulating and “coaching” their computers to look very deeply into positions effectively counteracted the superior chess understanding of their grandmaster opponents and the greater computational power of other participants. Weak human + machine + better process was superior to a strong computer alone and, more remarkably, superior to a strong human + machine + inferior process.
So in HFT, how much room is there for an amateur to profit over professionals by having a sophisticated process?
I'm thinking back to Garry Kasparov's piece in the NY Book Review a couple years back: http://www.nybooks.com/articles/archives/2010/feb/11/the-che...
He talks about a chess tournament in which it was "anything goes"...competitors could be human, computers, or humans with computers. The expected outcome was that a grandmaster using a Deep Blue-like computer would win, but the winners ended up being a couple of amateurs with three computers:
> The surprise came at the conclusion of the event. The winner was revealed to be not a grandmaster with a state-of-the-art PC but a pair of amateur American chess players using three computers at the same time. Their skill at manipulating and “coaching” their computers to look very deeply into positions effectively counteracted the superior chess understanding of their grandmaster opponents and the greater computational power of other participants. Weak human + machine + better process was superior to a strong computer alone and, more remarkably, superior to a strong human + machine + inferior process.
So in HFT, how much room is there for an amateur to profit over professionals by having a sophisticated process?
There is an air of either incredibility or sheer jealousy in these comments. Nevertheless, I just wanted to tell the OP that he did a great job. Thanks for sharing. I work in the finance industry as a quantitative software developer, and it certainly is not an easy job for one person to do. In fact, I tried (independent of my professional work) doing this myself, and I ended up losing a lot of money. If people are trying to do this, please please be careful. Big companies, like ones I have worked at, have technical and human resources that are vastly more powerful.
Great work, very interesting to me. Counter to what we're constantly told through the media this stuff can be done. Doing it year after year seems to be the elusive part. Intuitively, once you've proven your technique on 1000+ trades it's not luck.
I developed a fully-automated low-frequency stat arb system that I ran in 2007 based on a perhaps even simpler algorithm. It traded various equities equally to the long and short side regardless of market conditions so widespread rally or collapse was irrelevant. I logged about 20-30 trades/day - much slower.
The results, using no leverage, were +90% in a year with a worst drawdown of 2% and a Sharpe ratio of 2. Total trades were 5000+. Month-to-month the results were very consistent until the uptick rule was nixed in July 2007. August 2007 was a record winner for me, but Sept-Dec 2007 fell flat, not losing, but with greatly diminished profits and the same variation and more frequently getting slammed all-long or all-short instead of a mix that was often near-neutral. Also getting fills better than my orders then completely disappeared, as this was the beginning of the HFT middlemen - including your own brokerage. I shut it down at the start of 2008, keeping the profits intact and moving on to other priorities.
I continued to monitor the theoretical results for a couple of years but the conditions didn't return so I eventually cancelled my data feed.
I developed a fully-automated low-frequency stat arb system that I ran in 2007 based on a perhaps even simpler algorithm. It traded various equities equally to the long and short side regardless of market conditions so widespread rally or collapse was irrelevant. I logged about 20-30 trades/day - much slower.
The results, using no leverage, were +90% in a year with a worst drawdown of 2% and a Sharpe ratio of 2. Total trades were 5000+. Month-to-month the results were very consistent until the uptick rule was nixed in July 2007. August 2007 was a record winner for me, but Sept-Dec 2007 fell flat, not losing, but with greatly diminished profits and the same variation and more frequently getting slammed all-long or all-short instead of a mix that was often near-neutral. Also getting fills better than my orders then completely disappeared, as this was the beginning of the HFT middlemen - including your own brokerage. I shut it down at the start of 2008, keeping the profits intact and moving on to other priorities.
I continued to monitor the theoretical results for a couple of years but the conditions didn't return so I eventually cancelled my data feed.
Being pedantic, 4000 trades a day isn't HFT. This is stil algo trading, of which HFT is a subset.
I consider HFT to be any strategy where speed itself is the what gives the edge. Colocation is usually a prerequisite, though not sufficient. It's a shame HFT gets all the attention, when it's really a tiny portion of trading activity. Algo-trading in general is 70%+ of market activity in the US.
Also limiting trades isn't really adequate risk management. The tech exists to very accurately model your exposures. This is something I see underdeveloped a lot, and what separates the top trading firms from the rest.
Still I commend you creating a model, working out how to test and execute it automatically and actually trading your own money.
I really think more hackers should be actively managing their money, (in general, not like in the article). We have these amazing liquid markets, all time low spreads/commissions, products like ETFs/derivatives to accurately and cheaply execute a given strategy, and a huge increase in tech to model risk, but personal personal investing is the same as the 60s.
I consider HFT to be any strategy where speed itself is the what gives the edge. Colocation is usually a prerequisite, though not sufficient. It's a shame HFT gets all the attention, when it's really a tiny portion of trading activity. Algo-trading in general is 70%+ of market activity in the US.
Also limiting trades isn't really adequate risk management. The tech exists to very accurately model your exposures. This is something I see underdeveloped a lot, and what separates the top trading firms from the rest.
Still I commend you creating a model, working out how to test and execute it automatically and actually trading your own money.
I really think more hackers should be actively managing their money, (in general, not like in the article). We have these amazing liquid markets, all time low spreads/commissions, products like ETFs/derivatives to accurately and cheaply execute a given strategy, and a huge increase in tech to model risk, but personal personal investing is the same as the 60s.
Take a look at the VIX from 2009 until today and you'll understand why you stopped making money.
I've been considering trying HFT myself for a while. I'm competent with Machine Learning and am a Software Developer by day, so I can program and can sysadmin well enough to get something up and running without any trouble at all.
But, every time I've tried to actually get started, I've always found the amount of research required before being able to begin is just staggering.
It seems like the logical course of single-programmer HFT trading being:
- Find sample data
- Build your trading program using sample data
- When you're happy: connect to live API and set your trading program loose
- Iterate.
However, the first step and the third step seem like the ones which require the most research.
Is there somewhere which has a straightforward dump of timestamped market data available to download (free or not), in order to actually develop a working program?
Likewise, figuring out what to actually trade with, and which service to use is also pretty taxing.
But, every time I've tried to actually get started, I've always found the amount of research required before being able to begin is just staggering.
It seems like the logical course of single-programmer HFT trading being:
- Find sample data
- Build your trading program using sample data
- When you're happy: connect to live API and set your trading program loose
- Iterate.
However, the first step and the third step seem like the ones which require the most research.
Is there somewhere which has a straightforward dump of timestamped market data available to download (free or not), in order to actually develop a working program?
Likewise, figuring out what to actually trade with, and which service to use is also pretty taxing.
I run a 12 person HFT group in Denver. This is an excellent description of how an individual can bootstrap themselves into success. Great story, and nicely presented.
The one interesting point that he glossed over is what his indicators were. He wrote, "The indicators that were most useful were all relatively simple and were based on recent events in the market I was trading as well as the markets of correlated securities."
Which doesn't really tell you much.
The one interesting point that he glossed over is what his indicators were. He wrote, "The indicators that were most useful were all relatively simple and were based on recent events in the market I was trading as well as the markets of correlated securities."
Which doesn't really tell you much.
There is a coursera course called "Computational Investing, Part I" that I am taking that aims to build a market trading simulator to test a trading model. It just started so it's not too late to join.
https://www.coursera.org/course/compinvesting1
https://www.coursera.org/course/compinvesting1
A lot of people are stating that this is like gambling - it is - but not in the sense that you think. Firstly he doesn't use his entire bankroll on each trade, secondly he goes long-short consistently over very short periods of time, thirdly he's too tiny to actually move markets, and fourthly he is in and out within a day - where his max var. is 100% on thousands of tiny trades. Think of it like this - he has $100 - he bets $10 of that each day. He can blow that $10 - no problems.
Worst case he runs out of capital over a period of weeks.
He can't blow up in the way that you think - but he can have large drawdowns over a period of weeks.
Markets are eventually consistent scalable systems - and that is why we prefer them over central planning. In the medium term they prices things correctly, cheaply and efficiently (decade+).
In the short term however (sub-decade) - they can't price jack.
Markets are inefficient period - if they weren't, well then P=NP and you could just put your NP-hard problems into a market and get back cheap, quick, accurate results. Oh - wait - protein folding is actually harder than that.
There are 2 major ways to make money in the markets. Value-Growth and statistical arb (often high frequency). The former (Buffett) is highly concentrated bets on the future of business (I'm value - long TSLA/GOOG/Samsung). The latter is looking for thousands of small diversified statistically significant correlations above 50% (random guesses) and trading costs between securities/price movements over short time intervals (aka statistical ghosts in the data - RenTech/Shaw).
Both work. Both work well. And will continue to do so as long as markets exist.
Worst case he runs out of capital over a period of weeks.
He can't blow up in the way that you think - but he can have large drawdowns over a period of weeks.
Markets are eventually consistent scalable systems - and that is why we prefer them over central planning. In the medium term they prices things correctly, cheaply and efficiently (decade+).
In the short term however (sub-decade) - they can't price jack.
Markets are inefficient period - if they weren't, well then P=NP and you could just put your NP-hard problems into a market and get back cheap, quick, accurate results. Oh - wait - protein folding is actually harder than that.
There are 2 major ways to make money in the markets. Value-Growth and statistical arb (often high frequency). The former (Buffett) is highly concentrated bets on the future of business (I'm value - long TSLA/GOOG/Samsung). The latter is looking for thousands of small diversified statistically significant correlations above 50% (random guesses) and trading costs between securities/price movements over short time intervals (aka statistical ghosts in the data - RenTech/Shaw).
Both work. Both work well. And will continue to do so as long as markets exist.
This reminds me of an AMA from a few years ago. Really interesting if you are into stuff like this:
http://www.reddit.com/r/IAmA/comments/9s9d7/iama_100_automat...
http://www.reddit.com/r/IAmA/comments/9s9d7/iama_100_automat...
Relax with the vitriol. The guy is sharing an interesting personal story, not providing a step-by-step HOWTO or recommending people follow his suit. In fact, the article is really an ad for his startup Courseware.
This article is missing a crucial piece of data: what was the initial investment.. earning 500k with 10k initial investment is genious, with 10M initial investment it's just another year on the stock market.
The charts show he was trading between Jun 2009 and Oct 2010. How much of his gains could be attributed to the market recovery in general? The Dow went from about 7000 to 11000, the Russell from about 600 to 800.
Pls do not follow the advice of the OP. I started a hedgefund in 2004 doing HF platform arbitrage and ran it for 5yrs and i can honestly tell you that this is just survivorship bias. This is a very complex field and being off slightly, having a slight bias, a fraction of a point off your execution pricing and a slightly flawed money management system is recipe for disaster.
The biggest issue is the confusion that you can apply machine learning to HF trading. HF trading sub 15min mark is more about playing the deal flow, and only the institutions have an edge on this. This is why goldman had to separate the buy and sell sides in the early 2000's. Above 15mins you are able to find an edge using time series analyses since the market is scaling invariant according to Benoit Mandelbrot and this does not apply to dealflow. Also having access to dealflow allows you to predict volatilty seconds ahead which allows you decrease your risk and increase you reward as well as handle your costs since the volatility will impact your transaction costs even if transaction costs themselves stay the same. There is just so much stuff to cover that a comment will not do justice in explaining what is wrong with this guys logic.
The biggest issue is the confusion that you can apply machine learning to HF trading. HF trading sub 15min mark is more about playing the deal flow, and only the institutions have an edge on this. This is why goldman had to separate the buy and sell sides in the early 2000's. Above 15mins you are able to find an edge using time series analyses since the market is scaling invariant according to Benoit Mandelbrot and this does not apply to dealflow. Also having access to dealflow allows you to predict volatilty seconds ahead which allows you decrease your risk and increase you reward as well as handle your costs since the volatility will impact your transaction costs even if transaction costs themselves stay the same. There is just so much stuff to cover that a comment will not do justice in explaining what is wrong with this guys logic.
If anyone has questions for me happy to answer as best I can.
Don't do this with your own money. Found a startup building HFT tools, and then raise money for it, and use other people's money to test your tools.
If the tools work, sell them. If they don't, tweak them, try it again, and sell them until they do.
This is risk management.
If the tools work, sell them. If they don't, tweak them, try it again, and sell them until they do.
This is risk management.
I started the infrastructure for this kind of thing a while ago. It's BSD licensed.
It is a software implementation of the Viable System Model (VSM), a model for autonomous systems developed by Stafford Beer. It provides structure, communications, auditing and alerting for autonomous systems.
Part of it is base code for dealing with stocks and options, treating securities positions as autonomous systems that have the scaffolding for running simulations on themselves. It's in Smalltalk and runs under Squeak and Pharo. It can be found at:
http://home.rbcarleton.com/rbc/software/smalltalk/VSA/
I won't try to advertise it as a complete solution, but it might be the start of one.
It is a software implementation of the Viable System Model (VSM), a model for autonomous systems developed by Stafford Beer. It provides structure, communications, auditing and alerting for autonomous systems.
Part of it is base code for dealing with stocks and options, treating securities positions as autonomous systems that have the scaffolding for running simulations on themselves. It's in Smalltalk and runs under Squeak and Pharo. It can be found at:
http://home.rbcarleton.com/rbc/software/smalltalk/VSA/
I won't try to advertise it as a complete solution, but it might be the start of one.
Wait. This is not HFT. There's a huge difference between automated and high frequency trading. What he does is only automated scalping at best (or at the fastest).
Automated trading is more on strategy, while HFT has more to do with volume and speed. With automated trading, you predict price movements. HFT involves being a liquidity provider. You don't use market technical indicators in HFT, you wait for some really huge orders.
HFT firms won't bother him. Those are dealing with an entirely different set of algorithms. He should have contacted brokers instead.
Automated trading is more on strategy, while HFT has more to do with volume and speed. With automated trading, you predict price movements. HFT involves being a liquidity provider. You don't use market technical indicators in HFT, you wait for some really huge orders.
HFT firms won't bother him. Those are dealing with an entirely different set of algorithms. He should have contacted brokers instead.
Is there a way to do this with Python or Ruby? I could just as well program this in C#, but I have a friend who can code a little, but doesn't really need everything in C# to do what he wants. The value add of offering the simulator, including the taking into account the bid/ask prices and a stochastic model for latency. Combine this with a web based code editor and easy hosting, and I think this would be a viable product.
Looking at your first chart there, is there a reason (other than market conditions) you were making significantly more at the end of '09 than mid '10?
Could you comment on how your "curve fitting" algorithm worked? Did you end up with an equation for each curve? Im working on something that requires curve fitting and any kind of tip would be helpful.
I am curious as to exactly why the profitability decreased steadily and rather rapidly all the way to ~zero. The article doesn't seem to expound on that unless I missed something.
Is this a result of bots on the other side adapting in some way to what you were doing? I would have thought you would be too small a player for them to notice.
Is this a result of bots on the other side adapting in some way to what you were doing? I would have thought you would be too small a player for them to notice.
Very important to understand that making $500k speculatively is not evidence of an 'edge', nor is trading frequency evidence of the absence of luck. From March 2009 through much of 2010, the market was strongly bullish - if his algorithm showed a positive market bias then his returns would primarily be a function of timing (read luck: and there are a million variants on the nature of the bias that could be unwittingly responsible for his returns, despite the frequency of trades).
We cannot even tell if $500k is a good risk adjusted return - we have no information on volatility, nature of the exposure or most importantly how much money he started with?
Not exactly shocked Jim Simons didn't return his email. But completely shocking that he walked away from a successful automated trading strategy... the only thing rarer than a free lunch is a man willing to walk away from one. suspect.
We cannot even tell if $500k is a good risk adjusted return - we have no information on volatility, nature of the exposure or most importantly how much money he started with?
Not exactly shocked Jim Simons didn't return his email. But completely shocking that he walked away from a successful automated trading strategy... the only thing rarer than a free lunch is a man willing to walk away from one. suspect.
The high point of my trading was October 2009 when I made almost 100k. After this I continued to spend the next four months trying to improve my program despite decreased profit each month. Unfortunately by this point I guess I’d implemented all my best ideas because nothing I tried seemed to help much.
It is of course possible that once you made "real" money with your algorithm it was spotted by the other algorithms which then started working against it. (Aka exploiting it) Having talked with people in that space (hft) I was left with the impression that an insane amount of analysis was done on those trades.
It is of course possible that once you made "real" money with your algorithm it was spotted by the other algorithms which then started working against it. (Aka exploiting it) Having talked with people in that space (hft) I was left with the impression that an insane amount of analysis was done on those trades.
Would you be able to open source any of the code behind your trading system? Maybe not the "secret sauce", but it would be interesting to see how you processed the data feeds, modeled the data, entered orders, etc.
[deleted]
Trust me, you earned that much because of your luck. Otherwise Andrew Ng would have partnered with another finance professor and they would have been the richest people on earth!! Imagine trading with their expert systems on global markets.
I traded stocks and Forex for years and my experience says, it is not for everyone. What ever indicators,discipline or model you follow it is going to work only if you have the right intuition or luck!
I traded stocks and Forex for years and my experience says, it is not for everyone. What ever indicators,discipline or model you follow it is going to work only if you have the right intuition or luck!
You said "Growth stopped" but your P&L shows negative growth approaching zero. Would it be more fair to say that your profitability turned to zero?
Thanks for the post, it's very inspirational.
Could you explain this part, specifically what do you mean by "bucket"?
"To accomplish this I tracked predicted price moves in 50 buckets that depended on the range that the indicator value fell in. This produced unique predictions for each bucket that I was then able to graph in Excel. As you can see the expected price change increases as the indicator value increases."
Could you explain this part, specifically what do you mean by "bucket"?
"To accomplish this I tracked predicted price moves in 50 buckets that depended on the range that the indicator value fell in. This produced unique predictions for each bucket that I was then able to graph in Excel. As you can see the expected price change increases as the indicator value increases."
It could have easily been called "how i lost 500k with machine learning". Like gambling, it's easy to manipulate statistics to show that you did well in some period of time.
I worked for a large investment bank about 10 years ago, writing trading programs for quant traders who were market makers. The quants called guys like him "retail" investors and they gleefully picked off all those trades. It's how they made all their money.
So, everyone else, beware of making this a case study in how to make lots of money really fast. You are more likely to lose money.