Disconnect

Train Accuracy: 99.42%
Test Accuracy: 85.93%
              precision    recall  f1-score   support

         0.0       0.88      0.93      0.90       545
         1.0       0.80      0.72      0.76       375
         2.0       0.88      0.89      0.88       416

    accuracy                           0.86      1336
   macro avg       0.85      0.85      0.85      1336
weighted avg       0.86      0.86      0.86      1336

These are pretty decent results for my current version of the model, using 4 hr. data. However despite getting buy signals for the past couple of days (that’s 6 buy signals per day) my current trade is in drawdown and would have hit the stop loss if I had actually set one. Of course the predictions cover a five day horizon, so still time to recover. But not very encouraging. The prediction is that price will go up and that it will not go down too far during the period, which is already invalidated.

I can’t see myself making any improvement on the above results, which are already hard to believe for this context. I must surely have some logic error somewhere. Anyway, time to go back to developing the RL model, with the intent of using them both in an ensemble. Meanwhile I must find a new place to live, work on this project will suffer.

Timeframe

I finally got around to changing from the 6 hour timeframe to the 4 hour timeframe. This gives me 50% more data to work with! Made a couple of minor adjustments but processing essentially unchanged. Target is still whether or not price reaches 2% take profit without hitting -2% stop loss, in the following 5 days. Testing the XGBoost model gave improved accuracy and precision, and backtesting over the past year (not counting moving averages or anything else) gave a slightly better return than previously. All in all a good move, and I don’t have to wait so long during the day for an update.

Shortin’

Just completed the first profitable trade using my new strategy, with a 2% profit. I’ve made a couple of other trades but basically opened and closed at same price due to changing signals from the strategy. This recent trade was a short, borrowed ETH on AAVE and sold it on Binance. Price dropped overnight and my OCO order was filled to cover. The way ETH is going against BTC lately I think all my profitable trades will be shorts. I’m going for 2% take profit, 2% stop loss. Not since my earliest days in trading have I used stop losses consistently. Maybe that’s why I always lost money.

UPDATE

Just lost it again. My model said the price would recover, but it didn’t. In fact it dropped a further 2% and my stop on the new long got hit. Win some, lose some.

Coming Together

It’s been a bit of a struggle, but I feel that my understanding of machine learning, and especially neural networks, is coming together. The books I’m currently reading, Artificial Intelligence in Finance, by Yves Hilpisch, and Deep Learning with Python by Francois Chollet, are fairly easy reading. I’ve accepted that I’ll have to work with Keras/Tensorflow and it’s really not that different from PyTorch. It’s all just getting a bit easier.

Meanwhile I’ve got my trading strategy up and running, but not going anywhere at the moment. Still early days. It’s not actually using a neural network yet, but that will come too eventually. Ensemble methods seem the way to go for good results and I’m hoping that combining several different algorithms will eventually get me good results.

Reference Point

Train Accuracy: 99.94%
Test Accuracy: 77.88%
              precision    recall  f1-score   support

         0.0       0.79      0.87      0.83       362
         1.0       0.70      0.63      0.67       243
         2.0       0.83      0.79      0.81       281

    accuracy                           0.78       886
   macro avg       0.77      0.76      0.77       886
weighted avg       0.78      0.78      0.78       886

The above results are what I am currently getting with my XGBoost model, using a test size of 10%. As previously mentioned, the classes are

  • 0 – Sell
  • 1 – Do nothing
  • 2 – Buy

Those scores aren’t too bad, but I’ll work on improving them. I’m posting here for the record. One think I might try is to use log returns instead of returns. Finance people seem to prefer those. Apparently they are more normally distributed than regular returns, which is considered a good thing.

Whiplash!

[0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 1 2 0]

These numbers are the latest predictions for my ML model, with 0 being sell, 1 being hold, or do nothing, and 2 being buy. One number is generated every 6 hours. So over the past day it has advised to sell, then hold, then buy, then sell again. I’ve actually sold and bought ETH twice in the past couple of days, both times with close to no change in total balance, except for some transaction fees. I might have to rethink this strategy a bit. Fees on Binance are 0.15% per trade, but that can add up over time.

Getting Help

I usually search Google for help with problems I run into while coding, but sometimes that doesn’t work. Usually that’s because I find it hard to frame a question that gives relevant results. Then, as a last resort, there’s StackOverflow. My history with them has been rather chequered. I was chided for asking one question (no idea why) and banned for a week. On another question I got a very helpful answer from one user just before a moderator stepped in and said the kind of question I had asked was not permitted. Luckily I already had an answer. What will happen this time?

Problem is I opened a Jupyter Notebook directly from Yves Hilpisch’s GitHub repo in Google Colab. Two cells in the notebook attempt to open another file, one to run a .py file, and the other to load a .csv file. Both cells gave ‘file not found’ error even though the files exist in the correct places. Since nearly every Jupyter Notebook under the sun loads a csv file at least, what is the point of Google Colab providing the option to open a notebook directly from a GitHub repo if it can’t load such a file? I’m clearly missing something.

Of course there’s a workaround. I can download the repo to my local machine and then upload it to my Google Drive. In fact I seem to remember that it’s possible to transfer a GitHub repo directly to Google Drive without the download. Then run the notebook from Drive, and that should have no problem accessing the data files. But still, what is the point of suggesting it’s even possible to run a notebook directly from GitHub? Just a source of frustration. As if I don’t have enough of that in my life.

AFTERTHOUGHT

As a former teacher of programming, it has occurred to me that Google Colab/GitHub is an ideal combination for teaching. A teacher could upload example code to GitHub, students could open the files from Google Colab, all without the students or the institution having to concern themselves with installation and maintenance of a Python environment. Also maybe data files could be accessed via http request rather than from a drive. I must check that (the http request) out as it would answer my basic question of how would this be generally useful.

On the Road Again

Just made first trade under new strategy. I had some logic errors in my data preparation code, which I fixed, and then the predictions were that I should sell ETH for BTC. Previously all the recent signals were to do nothing, but after the fix the last dozen or so signals have been sell.

So I borrowed some ETH (not too much) on AAVE and transferred it to Binance, and traded it for BTC. So I guess the idea now is that I buy back that amount of ETH when the price falls and repay the debt. With a little BTC profit remaining, after transaction fees. Hopefully. Anyway, that’s the plan.

New Day, New Plan

Here’s the latest plan. Trade ETH for BTC. I have some BTC on Binance. Without any need for shorting if ETH goes up against BTC I can simply trade BTC for ETH on the spot market at 0.15% fee. And when it goes down against BTC I can trade back the other way. Unfortunately ETH has been falling against BTC for quite a while now and it might be some time before I get to put my first trade on using this strategy.

I’ve backtested this plan, and it gives a decent return, about 50% profit in the past year. Significantly better result using XGBoost with the MA crossover than when not using it. Of course those backtest results never work out in practice, often quite the opposite. I guess it’s a matter of how much I actually commit to trading this strategy. It definitely makes the whole business simpler though, and that’s a good thing.

UPDATE:

I’ve just backtested using the XGBoost alone, and that gives me the best result on this pair so far. And as for waiting for ETH to go up against BTC, I could just borrow some ETH on AAVE and transfer to Binance…

The Best Laid Plans…

Facepalm moment. The MA cross is approaching, and I discover that I can’t borrow ADA on AAVE. I’m not actually looking to borrow at the moment, because the indicated trade is a long not a short, but I wan’t to be able to borrow and I can’t. Why has it taken me so long to realize this? Actually xgboost is giving me a long string of no-go signals, so perhaps I wouldn’t have traded the crossover anyway, but still doesn’t solve my fundamental problem.

I’ve been looking for other liquidity pools that do offer borrowing ADA. There are a few but they all seem to be fairly new projects. Security is important in crypto generally, and I was happy to go with AAVE because it is a big project that has been around for a while and has a good reputation, and was recommended to me by someone who knows a lot more about DeFi than I do. Not so these other pools. So what to do?

AAVE does offer borrowing ETH, of course. I think it’s time to investigate the long term prospects of trading ETH. At least it will be doable. One reason I went with ADA is that it seems pretty undervalued at the moment, which is a fundamental consideration, but fundamentals really shouldn’t be an issue with this strategy anyway. I won’t be buying to hold, after all.

UPDATE

Testing the strategy with ETHUSDT instead of ADAUSDT shows a small profit, bigger with XGBoost than without, but still small. Lots of work to do. Tweaking the lookback periods might help, but perhaps I should use some base strategy other than Moving Average Crossover. There are plenty of indicators to try after all.

Double or Nothing

I’ve rejigged my XGBoost enhanced ADAUSDT MA Crossover trading strategy for both long and short positions, and backtesting shows a better result than long only. The backtesting result for the past year is about the same as BTC has gone up in the past year. So, do I leave all my capital in BTC, or put some of it into trading ADA?

My main reason for spending so much time exploring trading strategies is that buy and hold only works if prices go up. Trading can work in all markets, if done right, but doing it right is the hard part. I could lose the lot if not careful.

So what does the future hold, crypto-wise? One analyst has said it’s unlikely to go up anytime soon because no one has got any money to invest. Certainly the hope of greater adoption by regular people with the ‘new’ BTC ETFs has proven illusory. I’m sure it will go up eventually, but I might not live to see it! At least the trading keeps me occupied, so I’ll close my BTC margin position at least and put the collateral to use trading ADA on a DeFi exchange. And according to the chart there should be an MA Crossover in the next day or two. Hoping XGBoost gives me the green light on that. At the moment it’s No, No, No.

Full Circle

The first strategy one learns about, when using indicators, is the Moving Average Crossover. It’s generally not a very successful strategy but it’s easy to explain and implement. Very easy in TradingView because one can just add the two moving averages to a chart and set the lookback periods to one’s liking. After years of trying far more complex strategies, such as statistical arbitrage, coming back to the Moving Average Crossover feels surreal. Sure, I’m ‘supervising’ it with an ML algorithm, in the sense that the algo gives the green light to trade (or not) based on it’s own assessment of the chances of profit, but that doesn’t make a big difference to the overall result. Picking the right values for the lookback periods has far greater impact. Or so it seems.