"The purpose of studying economics is not to acquire a set of ready made answers to economic questions, but to learn how to avoid being deceived by economists" - Jean Robinson
I have been fascinated about the idea of building a AI that does trades for some time but I am. I am not alone it is believed 60-75% of trades are now algorithmic and I would suspect that will increase over time. So when I got through analysing I thought id right a blog post with my misadventures in building a AI trader.
Also the AI got big..... The current model largely can trade on any currency in the world. Ok I couldn't fit everything in but it's got all the ones that average people might think of and all the cryptocurrencies.
I also got it so it learned on its own the trades which made it very independent and you could just leave it running and see what it learned.
So I am trying to build a neural network as a theoretical test to see how easy is it to predict the world economy. My idea was there exists large language models and I could try to make a large financial model. Sounds ludicrous but I did it. I do not want to detail the inner workings of the neural network itself but I wanted to run through some of my test data.
Rough Capabilities
So I wanted the following capabilities for this AI. It needed to be autonomous and resistant to system death and to this end I wanted it to wholly decide whether it would buy or sell entirely on its own. This meant building something that performed reinforcement learning over streaming data in real time.
Being real time meant it needed to be able to adapt overtime and be resilient so a lot of work went into exception handling its API downloads.
A huge amount of work was done on how and what it learned and I'm not going to go into that but it's what makes it autonomous.
A look at what the top traders in the world make comes from Kaggle that over a year is 120% returns for the top 3 of all time and rapidly go down from there. A look at what evidence is out there for the more human level traders is 90% of traders do not make money and those that do are 50-60% accurate.
Therefore that was my targets that if I could get 50% accuracy I would assume that this AI would be good enough for further consideration.
I wanted this AI to run faster than most human perceive, orient, act and learn cycles and went for a 2 minute window for any trades. That is the model needs to run collect the data make its predictions and learn in 2 minutes.
The idea with that time window choice is to be able for the AI to act faster and be more knowledgeable on new events on the markets than anyone baring someone looking at the data in real-time. This way anyone so much as taking a coffee break it will beat.
I wanted this AI to run on a £100-200 pound refurbished PC i had got and not the data science PC I did not had. Building bigger could come later but this was just a proof of concept.
The AI was intended as a anti-Neo Liberal model. What I mean by this is that the standard theory of economics was that a price is naturally including all information already and the only reliable method to outperform the market was to have new information that is not in the price and act on that information before that information becomes widely known. This is the type of thinking that produces AI that do sentiment analysis on Elon Musk's tweets so the price of Tesla fluctuates when he says things. I did not want to do this; it feels silly. Therefore the AI receives price data but not outside world data. The AI is not allowed to hook-up to satellites and count cars to guess oil prices or download because that is "outside data". I did this because this is the standard belief and I wanted to know really what was the baseline performance of the AI without giving it data that was a "edge".
This withholding of data that might be novel or unique is on purpose because I feel that it allows the test to be also a theoretical exercise in can the AI outperform human capabilities without any special data because any success would also mean the AI is just good at its job and more likely to be trusted to be autonomous.
The design is modular the Elon Musk tweet detector could be added in later.
I wanted this AI to be running across the full spectrum of global economy. To this end I loaded it with what I considered the most popular crypto currencies, all the major currencies pair traded against each other, and a large number of the minor currencies against the dollar. This was to my mind "most" of the worlds currencies and meant if the AI could handle that then well what else could it handle if I scaled it up and put in more markets?
There's a shot down below of all the currency tickets below.
The design is modular and designed to seamlessly handle everything about the AI. It handles the API and getting data, it does everything else and stores its decisions in a little set of data. In the future other assets could be traded on and other data could be added and its fairly modular in how the code is written to allow redesign of these components.
This modularity is setup so in future it could handle stocks, shares, futures etc.
All this together puts it roughly around the 16-17 million parameter size which makes it a small Large Language Model if it did language which is why I am referring to it as the large financial model. I have to stress this is my first prototype of this design a lot (and I mean a lot) of strange design choices where made building this from a gambit of both normal past projects and wacky home experiments. I do not know if you downloaded Pytorch if you would get the same results as the design I used was entirely bespoke code from start to finish and I built from scratch through trial and error.
Being scaled up so big as a small large language model and containing most of the world currency data also lets me call it my large financial model like a large language model.

The Results Of Paper Trading
So I have to say that this was my first attempt I started on the 08-05-2024 it broke around midnight last night for a sloppy mistake but I restarted it and then ran from 09-05-2024 till 11-05-2024. This means the AI only got 3 days solid trading only two of which where eligible for currency trades. I had not built it to do currency trades across multiple exchanges so it was bounded to working in work hours for currencies. Cryptocurrencies where traded 24/7.
In short it had the equivalent of 2 days on currency pair trading, and 3 days on cryptocurrency trading. During that time it made 1105 market actions either buying or selling a trade in a wholly simulated manner. This was just paper trading to see if the core concept worked.
It achieved a 57% accuracy on average across the various currencies it received a average 101% compounding affect over that time across its different trading tickers. Extrapolated out over a year that would put it beating the best performing traders of all time though I think that is somewhat spin on my part as its untested to the length of a whole year. But considering it's the first test of a prototype managing a 1% return is good and 1105 trades probably give the average of what to expect from it. Both of these affects is astounding given it is new and all that upfront design work really paid off as it learns and adapts to the environment
What it made most of its money on is the Bit coin. See below. Though this is owing to it seems fairly good at making money at a 1% rate on average but bitcoin is so expensive that it's like 1% on a house rather than a few dollars!

Though when making it compounding values you can see that in a few places it lost a little money but only a little and makde positive trades in multiple places.
To explain what I mean by compounding I mean for say bitcoin if i make 3 trades in a row the first makes a 101% return the next a 99% loss and the final 101% then it would show 1.09 or 100.9% as the compounding values to show i.e. 1.01*0.99*1.01.
This means that across all the tickers the AI performed well and if it did not outright make money did not lose the principal or have any major market crashes.

Where it did make losses they where minor and only in one instance resulted in the loss of whole tokens during the 3 day period.

Accuracy was good none flat lined a few got below 40% but on the whole it seemed accurate.

I have removed the instances where it got 100% accuracy to show a closer look of what worked.

A big worry I had proved unfounded in that I thought the AI would just devolve into jumping in and out of positions. i.e. performing high frequency trading. The value is in seconds so the scale goes up in 10,000 which roughly equates to 2.7 hours meaning it does seem to tend to buy and hold performing trades as market actions along what it predicts the market is doing and my worry that it would only do high frequency trading seems not to apply.
Max time any trade was held was 20,000 seconds i.e. a little over two days which was the whole session. It seemed to vary bothy between tickers as to what time it would take about a trade. This fact that it has done lots of trades on some assets and little on others it was has meant I think it is currently very under trained overall and suspect it might be underfiting not overfitting which makes me hopeful

I used a scatter plot and the idea of market actions to differentiate between the tickers it was trading alot on and those was trading a little. On the whole it seems stable and keeps the 1% ROI as it gets more experience. This is one of the reasons I am hopeful it could be autonomous as it can do continuous learning and while you might want

The evidence seems to show the AI might stick around this 50% accuracy and it can be clearly seen some

Also the places where it held for a long time where where it did not make many buy and sell at all and therefore in those roles it remained under experienced.

Bit coin being expensive tended to mean while it had the most value it also did not have the same swings that could win or lose money which is why I think it was important to focus on averages and overall performance.

By the end there was a little bit of evidence the AI was making more money but would have to train it for a much longer time to get that data.
X is date Y is ROI.

One thing that really struck me was that it sort of seemed the AI in its current configuration would start just holding a position for a lengthy time and its another time I felt that certain aspect of its system was only just starting to wake up. The Y axis is time a position is held you can see that sequentially over time at the same angle the AI just got some of the assets it never traded in work up and it performed trades with them. The line is too perfect and it makes me suspicious the whole AI needs more time and id need to run a very long test to let it run out of these sudden wake up trades.
I also think it probably needs all those different systems working to let all the other settle in and work at their peak performance and those systems then fine tune against each other.

What Worked
Conclusion it worked really well all things considering. It really hit me that it according to the Neo Liberal gospel it should not function this well as its not providing new information into a market space. Its kind of wild that it beat the best traders of all time; I know that's admittedly over 3 days and not a career but its a prototype and they had a career to get their stuff right :).
I expected it to crass and burn a bit more instead and I am probably underestimating how much blood sweat and tears went into planning it all out and fine tuning every nook and crevice of it. On test day It just worked.
I plan to post this on LinkedIn with the problem last time I even mentioned cryptocurrency on LinkedIn 3 people from HMRC viewed my LinkedIn page. It felt kind of err overkill so just a reminder this was a paper trading excercise no money was made in the making of this AI -yet.
Though then there is the question is it best to monetise it by using it or selling signals. I need to look into that.
I also now have a baseline to see what things I might add in improve the model. I'm surprised it's so high and considering the amount of trades and currencies it used it's pretty much all the relevant data so it feels pretty open and closed that as a model it worked. Though it was a short test and problems could happen with it later.
Though those are incredible results for a prototype and I think it makes me question what is money and the markets for. Theoretically it's all meant to be meeting of the minds price determination instead for the AI to work at all suggests it's more mathematical.
Can you predict the world economy I would say yes...
Appendix
60-75% trades involve computers
Kaggle compound interest on the statistics of the top traders on the world
Trading performance of the best traders (2022) | Kagels Trading (kagels-trading.com)
Add comment
Comments