The Chart

Here’s the chart I’m currently trading. ADAUSDT on Binance, 6 hourly candles, with 15 bar and 60 bar moving averages added to help spot a crossover as soon as it happens. When short crosses long from below a trade could be on, depending on the prediction of future return made by the XGBoost model. Exit strategy is 2% take profit or stop loss. Only about 1 trade per month with this setup, but backtesting did show significant profit over the past 18 months. However, previous backtesting looked good for my stat arb strategy too, and that didn’t work out so well in the long run. I’m not going to over commit again.

I’ve done some testing using other values than the 15/60 bars that I’ve used here for the two moving averages, and the results are very different. Seems like my initial guesses are right on the sweet spot, at least for this trading pair. I wonder how brittle it is though. Perhaps it’s just chance that gives me good results now, but maybe in a couple of months that won’t be the case. It doesn’t take much of a change to wipe out the profit completely, even produce a loss. I don’t really trust backtesting much, given my past experience.

A Win?

Backtest results for approx 3 years of ADA/USDT, ended with 24% of initial capital, committing all of current balance to each trade. Looks pretty bad, so I checked the actual prices over the period and ADAUSDT went form 2.1820 at the start of the period to 0.3818 at the end, i.e. ended at 17.25% of initial value. So I think I can call that a win for my strategy. I lost less money than with a buy and hold strategy.

I think I need to refine my signal a bit. Perhaps look for gain over a shorter timeframe. And maybe actually a 2% gain and not a 1% gain. Of course with a more than 80% drop over the period of the backtest, perhaps a long-only strategy is not the way to go. I’m looking at that because it’s much easier to implement, just trade in a Binance Spot Wallet with OCO orders. Have I mentioned my dissatisfaction with the ban on margin trading by Australian citizens? What party do I vote for to get that reversed?

If the crypto market generally goes up over the next couple of years this isn’t a problem, but my optimism from the start of the year has significantly declined. The approval of BTC spot ETFs by the US SEC at the start of the year presaged a large inflow of capital to the crypto market, but that hasn’t happened. The ‘legitimizing’ of crypto as an asset class, the ease of onboarding due to ETFs rather than holding crypto, the increasing scarcity of BTC particularly, all these have made no difference. The fact that there is a wealth transfer from my generation to younger people as we die off, and younger people are more comfortable with digital assets, has also made no difference yet. Perhaps it will all happen after I’m dead.

UPDATE:

I’ve backtested only more recent data here, and added an extra condition before entering a trade – that the average return over the past 60 bars (15 days) be positive. Another parameter to optimize, but at least I’m getting some profit at last.

AFTERTHOUGHT

The pair of conditions (positive MA and positive ML prediction) give a better outcome than either one alone. Perhaps instead of just using a positive moving average as an entry condition I could use something a little more sophisticated such as a moving average crossover. In this case the XGBoost model is providing the meta-labelling to a traditional trading strategy. Not sure where RL fits into all this, but it might be a while before I’m confident with that anyway. However it does mean that I can roll some of the features that I was planning to use in the RL model into the XGB model, such as general crypto index, SPY, Fear and Greed, etc. No harm in trying I guess. This whole thing is definitely a Work in Progress.

🙂

Backtesting XGBoost

I need to set some starting parameters for this exercise. First are the trading rules. So I open a trade on a positive prediction of increase over the coming seven days. Fixed position or cumulative? I think I’ll go for cumulative this time. Put in my entire account balance (as much as I’m committing to this exercise anyway) and just continue with whatever the account holds at the time. This is more doable if I’m setting stops at 2% loss as it should prevent large drawdowns.

Exit strategy? I think I’ll go with 2% take profit or 2% stop loss for the moment. I might need to optimize these numbers, but I need a starting point. What about exiting after a set number of days? I guess if the price isn’t moving much either way there’s not much to be gained by doing this.

I need a trained model to produce signals, but can’t backtest on the data used to train the model. I’ve got about six years of data, so maybe train the model on four years of data, and then start backtesting from that point on. I could retrain the model before each trade to include all the data up ’til that point. I’ll see how that works out.

So what could I optimize here? Currently my go/no go signal is determined by whether or not the price increases by more than 1% at any time in the following seven days. I could change the percent, or the number of days. I’ve basically made it a binary classification problem. Maybe that’s not the best approach, but at the moment it seems pretty good to me. Of course the stop loss/take profit percentages might not produce the best results. I’ll play around with those numbers to see what works best on the historical data. Something that I could consider in the future is to increase the number of trading pairs I’m looking at. Or maybe to include some extra input features. For the moment I’ll go with what I’ve got.

Maybe

A week ago I entered a trade, shown by the bottom yellow line. Prediction was that the price would increase by more than 1% over the next seven days, and I set a limit order to take profit at the level of the top yellow line. However it was all downhill from there and I’m wondering whether to close the trade and take a substantial loss, or wait for it to recover.

My XGBoost model is showing an 87% precision using the last 10% of data as a test set, with the model trained on the first 90% of data (about 10,000 6 hour OHLCV bars). So, 13% of positive predictions are false positives, as has happened here. But 87% precision is pretty good, a lot better than I expected. If I had implemented basic risk management, such as setting a stop loss at 2% loss, my current unrealized loss would have been a much smaller realized loss, and I’d now be in a position to buy in at a much lower price and end up in a lot better position than I will be.

So I haven’t really fully implemented the RL model that I plan to use to ‘supervise’ the trading of the XGBoost model, and indeed I’m waiting for a book by Yves Hilpisch on the subject to be released in December. However if I do some basic backtesting just using the XGBoost model, to determine the best levels for take profit and stop loss I think there’s an excellent chance that I can produce a profitable strategy without such an additional input. 87% precision really is pretty good. I should make the most of it.