Today we continue the course on becoming a quantitative expert in 30 days. How to write custom strategies?

The answer is simple: AI can use ChatGPT or DeeKSeek to help you write strategies and continuously optimize, so even if you don't know any code, it's okay; you just need to know ctrl+c and ctrl+v.

Introduction to Basic Strategies

1. Trend Following Strategy

Strategy Principle:

"Follow the trend." Assuming there is a trend in the market, once the price starts to rise or fall, it may continue for a period, so you follow the trend.

For example:

Assume you are trading Bitcoin (BTC):

You set a 20-day moving average line (MA20).

When the Bitcoin price breaks above MA20, it indicates a possible upward trend, so you buy in.

If the price falls below MA20, you think the trend is weakening, so you sell or short.

Real-life example:

The famous "Turtle Trading Rules" is a classic trend-following system that buys on a breakout of the 20-day or 55-day high and stops out on a drop below the 10-day low.

Practical Backtest

You directly tell your needs to the AI, and the AI can help you generate strategies and also tell you where to place them.

图片

Actual test results
From January 1, 2022, to now, the simulated backtest has shown a loss of 26%, with a total of 71 trades.

图片

2. Mean Reversion Strategy

Strategy Principle:

"Extreme situations lead to opposite outcomes." Although certain asset prices may fluctuate, they typically oscillate around a certain "mean" — if prices deviate too far, they will eventually revert to normal levels.

For example:

You are observing a particular stock, such as Apple (AAPL):

The average price of AAPL over the past 30 days is $150.

Today, it suddenly dropped to $135, and you think it has "dropped too much" and is likely to rebound, so you buy in.

When it returns to around $150, you sell to profit from the difference.

Derivative Strategy:

Common methods include using Bollinger Bands or Z-score standard scores to judge whether prices have deviated from the mean.

Practical Backtest

图片图片

3. Arbitrage Strategy

Strategy Principle:

"Buy low and sell high, zero-risk arbitrage." Arbitrage is taking advantage of price differences between markets by simultaneously buying and selling the same or related assets in different markets to earn profits with very low risk.

For example 1: Cross-Market Arbitrage

You discover:

The price of BTC on Binance is $30,000.

The price of BTC on Huobi is $30,100.

You immediately buy BTC on Binance while selling BTC on Huobi, making a risk-free profit of $100 from the price difference (after deducting fees).

For example 2: Statistical Arbitrage

You observe two highly correlated stocks, such as Coca-Cola (KO) and Pepsi (PEP):

Historically, their price difference usually stays within ±$2.

One day, the price difference becomes $5, and you judge this to be abnormal.

So you sell the high-priced ones and buy the low-priced ones, waiting for the price difference to revert to normal before closing for profit.

Practical Backtest
I did not pursue this because it is a real simulation and many people are doing it. The returns are actually quite average and not guaranteed to be profitable.

4. Subsequent Optimization

Simple strategies are hard to make money, and to continue optimizing, you need to constantly test and adjust, but you just need to tell AI. For example, below, I asked AI to help me continuously optimize the strategy: I told him the results and asked him to help me improve the win rate, using the strategy of the previous simple Bollinger Bands.

图片

AI will first analyze your results and then help you adjust the strategy. For example, based on this result, it said the stop-loss mechanism was too strict. For instance, when entering the lower Bollinger Band, but due to the continued decline in the market, you set a 10% stop-loss, resulting in a closure before the candlestick rebounds above the Bollinger Band, so he updated the exit mechanism.

图片

And he also provided other technical indicators to enhance the stability of the strategy, as shown in the picture below.

图片

And he also explained to you why to include these indicators.

图片图片

Then, after looking at the backtest results improved by AI, the return became -4%, which indeed reduced the loss significantly, but the number of trades also decreased from the original 140 to 29. Although the win rate increased to 40%, it still resulted in a loss.

图片

Then continue to optimize; I pointed out that although the win rate increased, the trading volume decreased, and the returns were still losses, so I hope to continue improving.

图片

After AI's improvements, I backtested again, and the results showed no data, indicating that the conditions were too strict and there were no conditions triggering a buy, so continuous optimization is needed.

图片


Subsequently, I continued to optimize many steps, including configuration information in the config file, but still did not achieve good results, so it is necessary to continue optimizing based on specific trading details. The specific trading details are in the directory: \user_data\backtest_results, where you can see the specific trading details. In most cases, stop-loss signals were still triggered because many times "false" signals occur, such as in the dual moving average strategy, when it just breaks through and then falls, leading to a stop-loss signal.

图片

So, currently, the best method is to layer multiple strategies and then continuously optimize based on specific trading details!