Hi,
My name is Joaquín, and for over 15 years, I’ve been working as a systems engineer in the financial sector. I run a software company where we develop technology primarily for banks, investment funds, brokers, etc., with a special focus on AI and Big Data.
In recent years, I’ve been developing an artificial intelligence platform for trading US stocks and I’d like to share my experience for those curious about how this technology works, its benefits and challenges, and to answer any questions you might have.
Currently, I use an artificial intelligence model based on Meta's Llama-2, and as a "second opinion," I use OpenAI's GPT API.
I have pre-trained the AI model according to my strategy, and it operates directly through Interactive Brokers via an API. The core functions of the model include:
1. Real-time market monitoring
The model receives real-time updates on prices, ratios, and news and processes them according to the strategy to detect buying or selling opportunities and execute the corresponding orders. This allows me to detect and manage new positions or close existing ones, although there are additional steps involved to properly qualify a trade.
2. Monitoring portfolio exposure
The model continuously processes and calculates the portfolio’s exposure and risk, as well as the results obtained. This allows determining the appropriate size of a new position based on the risk and current portfolio composition and to manage open positions and their performance. Instead of using Take Profit or Stop Loss, the AI acts as a trailing stop, capturing gains or cutting losses based on the current context (e.g., holding a position upon positive news or closing it on negative news).
3. Calculating statistics, ratios, and prices
The AI constantly calculates market ratios and statistics. I apply various mathematical formulas to technically support the above fundamentals and precisely determine buying or selling prices, for example, measuring average trading volume over different periods to calculate the VWAP, estimating the average historical price variation of the asset, its relation to the indices, etc.
4. Training the model based on results
In parallel to the main model, I have two other AI models operating in demo mode. The first one learns in real-time about the positions taken by the main model and has the freedom to modify the strategy and make decisions. Training this model simultaneously allows me to leverage the AI’s ability to improve based on experience and then, after refining the results, to implement enhancements in my main strategy. The second model simply implements what is learned to test in a simulated scenario whether the new strategy yields better results than my principal strategy.
Although the background and operations are quite complex, in practice, it boils down to determining if any fundamental event could impact the price of a stock, understanding the entire history of such events and their effects to gauge the potential impact they had, have, or might have. It also involves calculating formulas according to my strategy and the current exposure of the portfolio to decide whether to buy or sell stocks, at what price to do so, how much, and when to take profits or cut losses.
This will depend on both the technical knowledge and skills and the economic resources of each individual. Creating an AI from scratch and training it to be competitive against current options requires a technical and economic capacity that, initially, may not balance out for the intended purpose.
Whether we use an AI like LLama, GPT, Watson, etc., or choose to build something from scratch, the results will largely depend on the parameters (the input) with which we train it. The equivalent in ChatGPT (and conversational AIs) is the prompt; for example, Dall-E can create images and illustrations of all kinds, but instructing it to "create a logo" is not the same as specifying "Create a logo for my investment business named X, where navy blue predominates, using a classic font and a conservative style." The results will be completely different; in the first case, leveraging the "creativity" of the AI, and in the second, its "capability".
Instead of using traditional technical indicators, I directly calculate the relevant variables for my strategy based on historical price data. Rather than using Take Profit or Stop Loss, I measure the real-time impact of news, events, price action, volume, and the order book (and compare it with the historical data) to adjust the exit price. To determine which stocks to buy, I focus on two factors: the current price in relation to historical data and the events that have affected, are affecting, or may affect it positively or negatively. I also calculate the potential return it can generate and whether the risk is suitable for my portfolio.
In summary, I simply apply the rule of "buy low, sell high." The real key is knowing as accurately as possible when something is cheap and when it is expensive.
One detail is that I only take long positions and never short; this is optional and depends on one's risk tolerance. Another detail is that 85% of the positions do not remain open for more than four days. On average, I maintain a position for two days, and it is during this period that it generates the highest return.
From the total positions, sorted by profitability, the best performing trade was 75.41% in ALIT, followed by 61.96%, 55.28%, and 30.04% in BKKT, PLTN, and BNED respectively.
From the perspective of gaining even more profits, the issue I currently face is missing many opportunities due to the definitive determination of the entry price. In other words, I lose the chance to make more money (and save some losses) because of the buy limit price I set when opening a new position, which often the stock never reaches.
Although I currently have an improved version running in demo, comparing models to make a change requires time and patience. Backtesting is an excellent tool for testing and refining various strategies, but real accuracy is obtained by operating in the live market. Testing strategies in real-time means facing the necessary time to be exposed to an infinite number of market situations and periods, not just a particular action.
Another area for improvement is to assume a bit more risk and take larger positions. The most significant evidence of this arises when comparing the performance of my account over the period (+23%) against the performance for what was actually invested in the market (where ALIT, which yielded more than 73%, represented only 0.68% of the portfolio). If these 19 best-performing positions had had an equal volume (around $5k out of $100k), they would have yielded 23.61%, averaging ~$1k profit per position. Their current yield for my portfolio represented just over 5%, contributing ~$300 on average; the difference is stark, as 77% of the potential gain was lost due to poor weighting or low risk exposure.
Another important aspect is the fixed costs of running the artificial intelligence models and the limitations of the capital with which I operate, a ratio that becomes profitable as the account size increases and income is higher.
Keeping the AI models running, plus the costs of APIs that provide prices, fundamentals, news, etc., amounts to about ~$7,500 monthly (not accounting for human capital, since I am the one who develops and supervises the model to results).
Finally, there is money at stake; this translates into monitoring during the entire market hours (including pre-market and after-market), positions, decisions, and the operation of the Artificial Intelligence.
Along the way to achieving these results, many things have failed that have cost me money, a "learning cost"; from programming errors to unforeseen scenarios or situations (such as a failure in the pricing API), which require being alert to take immediate action. This involves being on duty 16 hours a day monitoring every movement and the state of all services dependent on the model; a task that I definitely am passionate about and enjoy doing.
Today my interventions are minimal, and while I continue to monitor operations while the market is open, I take the opportunity to work on improvements to the secondary models. Obviously, there are times when I am not available; in these cases, instead of making decisions, the AI notifies me, and I take manual action from my phone.
The primary advantage is the ability to train a model that constantly analyzes thousands of data points, performs calculations, and draws conclusions to make decisions in fractions of seconds. This surpasses any known human capability and provides an unprecedented competitive edge.
What motivated me to start trading 13 years ago was the idea that technology could someday surpass the best traders in the world. This idea came to me while I was programming a robot to play chess and I stumbled upon an article about Deep Blue vs. Kasparov.
In the financial market, AI has taken on both passive and active roles, ranging from advisory and prevention to the active management of billions of dollars.
Undoubtedly, there is still a long way to go, at least in my case. I began real account trading with the model last November, starting cautiously and gradually increasing exposure.
The current limitations create a significant barrier to entry for the general public, even for those with the necessary knowledge and technical ability, as the cost of resources that could further improve these results is very high.
At the end of the day, it's about making money, and the financial results I've achieved have far exceeded my expectations, although the main satisfaction comes from having established a solid strategy, capable of generating results in both bull and bear markets, completely independent of the circumstances.
If you are interested in implementing Artificial Intelligence in your operations and don't know where to start, I hope this post helps you understand the implications of doing so.
Thank you for reading about my experience. I would be delighted to hear your opinions or comments, or to answer any questions (even technical ones) you may have.
Joaquín.
My name is Joaquín, and for over 15 years, I’ve been working as a systems engineer in the financial sector. I run a software company where we develop technology primarily for banks, investment funds, brokers, etc., with a special focus on AI and Big Data.
In recent years, I’ve been developing an artificial intelligence platform for trading US stocks and I’d like to share my experience for those curious about how this technology works, its benefits and challenges, and to answer any questions you might have.
Implementing Artificial Intelligence in Trading
There are numerous ways to implement AI, and I’ll specifically discuss my own experience, which I've refined over the last three years through trial and error to achieve satisfactory results.Currently, I use an artificial intelligence model based on Meta's Llama-2, and as a "second opinion," I use OpenAI's GPT API.
I have pre-trained the AI model according to my strategy, and it operates directly through Interactive Brokers via an API. The core functions of the model include:
1. Real-time market monitoring
The model receives real-time updates on prices, ratios, and news and processes them according to the strategy to detect buying or selling opportunities and execute the corresponding orders. This allows me to detect and manage new positions or close existing ones, although there are additional steps involved to properly qualify a trade.
2. Monitoring portfolio exposure
The model continuously processes and calculates the portfolio’s exposure and risk, as well as the results obtained. This allows determining the appropriate size of a new position based on the risk and current portfolio composition and to manage open positions and their performance. Instead of using Take Profit or Stop Loss, the AI acts as a trailing stop, capturing gains or cutting losses based on the current context (e.g., holding a position upon positive news or closing it on negative news).
3. Calculating statistics, ratios, and prices
The AI constantly calculates market ratios and statistics. I apply various mathematical formulas to technically support the above fundamentals and precisely determine buying or selling prices, for example, measuring average trading volume over different periods to calculate the VWAP, estimating the average historical price variation of the asset, its relation to the indices, etc.
4. Training the model based on results
In parallel to the main model, I have two other AI models operating in demo mode. The first one learns in real-time about the positions taken by the main model and has the freedom to modify the strategy and make decisions. Training this model simultaneously allows me to leverage the AI’s ability to improve based on experience and then, after refining the results, to implement enhancements in my main strategy. The second model simply implements what is learned to test in a simulated scenario whether the new strategy yields better results than my principal strategy.
Although the background and operations are quite complex, in practice, it boils down to determining if any fundamental event could impact the price of a stock, understanding the entire history of such events and their effects to gauge the potential impact they had, have, or might have. It also involves calculating formulas according to my strategy and the current exposure of the portfolio to decide whether to buy or sell stocks, at what price to do so, how much, and when to take profits or cut losses.
Investment Strategy for Training an Artificial Intelligence Model
Without a doubt, I consider the investment strategy as the most critical part for a successful model. Artificial Intelligence models, in most cases, come generically trained (like ChatGPT, which is technically an LLM and is designed and optimized for conversations, not for trading or calculations).This will depend on both the technical knowledge and skills and the economic resources of each individual. Creating an AI from scratch and training it to be competitive against current options requires a technical and economic capacity that, initially, may not balance out for the intended purpose.
Whether we use an AI like LLama, GPT, Watson, etc., or choose to build something from scratch, the results will largely depend on the parameters (the input) with which we train it. The equivalent in ChatGPT (and conversational AIs) is the prompt; for example, Dall-E can create images and illustrations of all kinds, but instructing it to "create a logo" is not the same as specifying "Create a logo for my investment business named X, where navy blue predominates, using a classic font and a conservative style." The results will be completely different; in the first case, leveraging the "creativity" of the AI, and in the second, its "capability".
My investment strategy
Broadly speaking, my investment strategy encompasses all aspects mentioned in the implementation section (macro and micro fundamentals, price action, statistics), along with risk parameters and exposure suitable for my profile, in addition to some proprietary formulas I've developed over the years through trial and error.Instead of using traditional technical indicators, I directly calculate the relevant variables for my strategy based on historical price data. Rather than using Take Profit or Stop Loss, I measure the real-time impact of news, events, price action, volume, and the order book (and compare it with the historical data) to adjust the exit price. To determine which stocks to buy, I focus on two factors: the current price in relation to historical data and the events that have affected, are affecting, or may affect it positively or negatively. I also calculate the potential return it can generate and whether the risk is suitable for my portfolio.
In summary, I simply apply the rule of "buy low, sell high." The real key is knowing as accurately as possible when something is cheap and when it is expensive.
One detail is that I only take long positions and never short; this is optional and depends on one's risk tolerance. Another detail is that 85% of the positions do not remain open for more than four days. On average, I maintain a position for two days, and it is during this period that it generates the highest return.
Results and Statistics
Profitability
Over the last week (from Friday, May 3, 2024, to Friday, May 10, 2024), I achieved a net return of 14.86% on closed positions. Considering the positions that remain open, the return exceeds 23%. This profitability is measured in relation to a capital of $100,000 and not on the actual investment return, which is considerably higher. The S&P 500's performance for the same period was 1.85%.Trades and Profitability by Position
From the total positions, sorted by profitability, the best performing trade was 75.41% in ALIT, followed by 61.96%, 55.28%, and 30.04% in BKKT, PLTN, and BNED respectively.
Portfolio Ratios
- Sharpe Ratio: 17.5
- Sortino Ratio: 255.41
- Standard Deviation: 2.6%
- Downside Deviation: 0.18%
Areas for Improvement
A current weakness has little to do with the strategy or Artificial Intelligence itself, but rather with my own psychology and the fear of changing something that works well.From the perspective of gaining even more profits, the issue I currently face is missing many opportunities due to the definitive determination of the entry price. In other words, I lose the chance to make more money (and save some losses) because of the buy limit price I set when opening a new position, which often the stock never reaches.
Although I currently have an improved version running in demo, comparing models to make a change requires time and patience. Backtesting is an excellent tool for testing and refining various strategies, but real accuracy is obtained by operating in the live market. Testing strategies in real-time means facing the necessary time to be exposed to an infinite number of market situations and periods, not just a particular action.
Another area for improvement is to assume a bit more risk and take larger positions. The most significant evidence of this arises when comparing the performance of my account over the period (+23%) against the performance for what was actually invested in the market (where ALIT, which yielded more than 73%, represented only 0.68% of the portfolio). If these 19 best-performing positions had had an equal volume (around $5k out of $100k), they would have yielded 23.61%, averaging ~$1k profit per position. Their current yield for my portfolio represented just over 5%, contributing ~$300 on average; the difference is stark, as 77% of the potential gain was lost due to poor weighting or low risk exposure.
Another important aspect is the fixed costs of running the artificial intelligence models and the limitations of the capital with which I operate, a ratio that becomes profitable as the account size increases and income is higher.
Keeping the AI models running, plus the costs of APIs that provide prices, fundamentals, news, etc., amounts to about ~$7,500 monthly (not accounting for human capital, since I am the one who develops and supervises the model to results).
Finally, there is money at stake; this translates into monitoring during the entire market hours (including pre-market and after-market), positions, decisions, and the operation of the Artificial Intelligence.
Along the way to achieving these results, many things have failed that have cost me money, a "learning cost"; from programming errors to unforeseen scenarios or situations (such as a failure in the pricing API), which require being alert to take immediate action. This involves being on duty 16 hours a day monitoring every movement and the state of all services dependent on the model; a task that I definitely am passionate about and enjoy doing.
Today my interventions are minimal, and while I continue to monitor operations while the market is open, I take the opportunity to work on improvements to the secondary models. Obviously, there are times when I am not available; in these cases, instead of making decisions, the AI notifies me, and I take manual action from my phone.
The Advantages
Truly, the advantages of trading with Artificial Intelligence are almost limitless, and the challenges I face are more related to my own human nature than to the results.The primary advantage is the ability to train a model that constantly analyzes thousands of data points, performs calculations, and draws conclusions to make decisions in fractions of seconds. This surpasses any known human capability and provides an unprecedented competitive edge.
What motivated me to start trading 13 years ago was the idea that technology could someday surpass the best traders in the world. This idea came to me while I was programming a robot to play chess and I stumbled upon an article about Deep Blue vs. Kasparov.
The future of trading with Artificial Intelligence
From my perspective, AI will completely replace most human specialties, and it will happen much sooner than we imagine. Doctors, lawyers, scientists, engineers, and designers will rely on specialized artificial intelligence to perform their daily tasks. Every month, hundreds of new scientific articles with research and advancements in various fields are published, and staying at the forefront would require superhuman abilities. It would take AI only minutes to process and understand all the new information available.In the financial market, AI has taken on both passive and active roles, ranging from advisory and prevention to the active management of billions of dollars.
Final conclusion
The results of trading with Artificial Intelligence speak for themselves; the advantages and capabilities compared to trading on my own are decisive.Undoubtedly, there is still a long way to go, at least in my case. I began real account trading with the model last November, starting cautiously and gradually increasing exposure.
The current limitations create a significant barrier to entry for the general public, even for those with the necessary knowledge and technical ability, as the cost of resources that could further improve these results is very high.
At the end of the day, it's about making money, and the financial results I've achieved have far exceeded my expectations, although the main satisfaction comes from having established a solid strategy, capable of generating results in both bull and bear markets, completely independent of the circumstances.
If you are interested in implementing Artificial Intelligence in your operations and don't know where to start, I hope this post helps you understand the implications of doing so.
Thank you for reading about my experience. I would be delighted to hear your opinions or comments, or to answer any questions (even technical ones) you may have.
Joaquín.