from data to backtest

Developing a profitable trading strategy is a task that requires careful data analysis and understanding of market patterns. To simplify data collection, I used Hydra is perhaps the best free tool for downloading market data.

I downloaded the BTCUSDT minute data for 2024, which was approximately 25 MB, and uploaded it to a CSV file.

Hydra also has its own analytics, but further you will see how much all this remains of the capabilities of AI, where you don’t even need to write the code yourself:

However, the main stage of my work was not collecting data, but analyzing it and searching for ideas for strategy. Instead of manually searching for approaches, I decided to trust the AI ​​to see what strategies it would suggest, what patterns and inefficiencies it could identify in the data, and how to optimize parameters for testing. By using ChatGPT I was able to not only conduct a detailed analysis, but also conduct a backtest of the strategy on the data.

Data preparation

Having received the minute data, I loaded it into Python (the code was written by the AI ​​itself, I just typed in text what I required from it) and began with preprocessing. This included assigning names to each column and combining date and time into a single column to make time series analysis easier.

Example data structure in a CSV file:

Дата;Время;Открытие;Максимум;Минимум;Закрытие;Объем 2023-12-31;21:01:00;42613.1;42629.2;42610.1;42625.7;64.946

Finding inefficiencies using AI

After pre-processing the data, I decided to ask the AI ​​about possible inefficiencies and patterns that could be useful for developing a strategy. ChatGPT has proposed several approaches:

  1. Volatility Clusters —High volatility hours might be suitable for a momentum strategy.

  2. Tendency to revert to the mean — When the price deviates from the average level, you can use the mean reversion strategy.

  3. Impulse patterns — At certain hours there was a steady price movement, which could be a signal for a trend strategy.

Strategy development

Based on the AI's suggestions, I chose two strategies to test:

  1. Mean Reversion: Opening a short position when the price deviates strongly upward from the average value and a long position when the price deviates downward. Closing a position when the price returns to the average.

  2. Impulse strategy (Momentum): Opening a position in the direction of the trend at times of increased volatility. If the yield is positive and above the threshold, the position is opened to buy, and if it is negative and below the threshold, the position is opened to sell.

Each strategy had basic entry and exit rules, as well as stop losses to manage risks.

Backtesting strategies

Using ChatGPT, I was also able to backtest both strategies to see how they would perform on historical data. The test results showed a return curve for the mean reversion strategy (see chart below).

The graph shows how the portfolio capitalization could change if the strategy were followed. It can be noted that the strategy demonstrated stable growth during certain periods, but there were also moments of drawdown. This reinforces the importance of setting parameters and using risk management.

Claude.ai

While working I also tried to use Claude Sonnet from Anthropic, which recently announced its big data analytics functionality (read more Here). The idea seemed promising: upload a 25MB file so Claude could help with the analysis.

However, I encountered a number of difficulties. Unfortunately, the function turned out to be crude and unfinished – my file did not even load. I ended up cutting it into small pieces, but due to previous mistakes I quickly reached my request limit. All I got was an error when trying to plot the graph.

Although I love working with Claude, I hope that the project engineers will improve this feature and significantly expand the window for loading data. This will allow you to more efficiently analyze large files and open up new opportunities for working with large volumes of information.

Conclusion

Using ChatGPT allowed me to not only analyze the data, but also ask the AI ​​questions about appropriate strategy creation methods. This approach not only generated new insights, but also helped quickly test hypotheses and generate recommendations that might have gone unnoticed with a conventional approach. I understand perfectly well that this is just a tool, and it will not replace human analysis. But the approach in which AI helps to find ideas and strategy parameters opens up new opportunities for flexible and adaptive development of trading strategies.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *