There’s no Fastai code in this, I actually got the idea after taking Andrew Ng’s course on Machine Learning many years ago when it was still taught in Matlab. I basically transformed the Mnist model into one that predicts stock prices. The main preprocessing that I used was converting a 20 day stock chart to a 40x40 grid of ascii art (where 1’s represented filled pixels and 0’s represented white space) and trained a network on that. The bottom boundary of the grid represented the 20 day low and the upper boundary represented the 20 day high and i scaled everything according to that when drawing out the grid.
I had that idea since I used to work for a hedge fund manager who swore by making all of his trading decisions by just “looking at the stock charts” and tried replicating this way of thinking using a NN.
The data I used was the S&P500 daily open, high, low, and closing prices from 1950 to 1980 (yes, you read that right, nothing from after 1980.) I basically “painted” those candlestick charts on the 40x40 grid using literally 1’s and 0’s. It seemed to perform almost as well out of sample, including during bad years like 2008. Cutting it off at 1980 also made it easier to backtest out of sample for many decades. And if you’ve read any books on stock chart patterns from the 1960s or so and compared them to the books written today, you won’t find radically different patterns being described (although their names may differ.)
Initially, i flattened the network and trained it as a vanilla strongly connected network. Later when I discovered Keras, I retrained it there on a GPU on both strongly connected and CNN networks.
When I discovered Fastai, I tried recreating this but couldn’t do so and resorted to converting my Keras implentation to Pytorch. I also dropped the CNN implementation since, as hard as it is to believe, it strongly underperforms the strongly connected one.
For some reason, I was getting decent performance on stocks and other securities than the S&P500 even though i trained it on the sp500’s chart patterns from the 50s to 70s, although my accuracy dropped slightly (averaging in the low 70s for most other stocks and securities rather than high 70s for the S&P out of sample.)
I later extended my model to predicting bitcoin and other crypto currencies using the same method as well and it seems to pick up on similar recurring chart patterns that were common in the S&P500.
Fyi, I don’t actively trade stocks or other securities, prefering to buy and hold an index portfolio although I still rely on the results of this model when deciding to rebalance my portfolio or investing new money coming in (I try to wait for a sell signal on my s&p investment if it’s already overweight at 60% and I want to reduce it to 50% for example.)
If anyone says they can predict bitcoin or any investment with over 90% accuracy, RUN. Although you can do better than a simple coin flip, the world we live in is too uncertainty to sustain such high accuracies in predicting the price of any publicly traded security.