/trading-rules-using-machine-learning

This is my financial trading system using ML (Random forest & LSTM). Most of the methods are based on 'Advances in Financial Machine Learning' by Lopez de Prado.

Primary LanguageJupyter Notebook

Trading rules using machine learning

by jojothepizza

Version 1.6, 1.7

  • This is my financial trading system using ML.

  • I'm still working on this project. If you're interested, feel free to contact me.

Experiments

  • This is the results of my trading strategies (there's full code in Notebooks).
  • The trading rule is based on Triple-Barrier Method introduced in Lopez De Prado (2018).

Data

  • BTC-USD (30 minutes data) close_price

First model 1 (get trend signals and position entries)

SMA

  • long when 10-days-SMA > 30-days-SMA smaf

Force Index

  • long when FI>0 fi_f

RSI

  • long when RSI>50 rsi_f

CUSUM Filter

  • detect structural change using cumsum of volatility
  • filter out entry points cusum

Combined filter

entries

First model 2 (set up target rates of each position and exit of it)

  • Triple-Barrier method

Results of the first model

return_of_1stmodel cm1 metalabel

Second model

  • It is a model that predicts whether the outcome of each bet is profit or loss.
  • It corrects bets of the first trading strategy.

Features

  • Technical indicators and price history
  • Use MinMaxizer scaler and PCA pcacorr

Results of second model (Random forest classification)

cm2 cvroc betpred

Bet sizing

  • Decide how much to buy
  • Bet sizing based on Sharpe ratio & Gaussian distribution (Lopez de Prado, 2018)
  • Use probabilities of Random forest classification predicted probabilities
  • Scale with minmaxizer

Prob betsize

Results

  • Here are Annualized Sharpe Ratio and Cumulative Returns of three strategies (only long strategy which excludes short selling):
  1. First trading Strategy: This is a primary model using only technical analysis. (predict when to buy)
  2. Second Meta-Label: This is a secondary model using ML algorithm on the trading strategy. (predict whether its bet is profit or loss/ correct bets of the trading strategy) /I used Random Forest and LSTM here.
  3. Bet Sizing: This is a sizing model using predict probabilities of ML algorithm used in Meta-Labeling ()
  4. Buy and hold: Buy-and-hold for an entire period.

And those strategies were introduced in Lopez de Prado, Advances in Financial Machine Learning.

BTCUSD Annualized Sharpe Ratio cumret

Other assets results

Samsung Electronics (Daily data)

SE Annualized Sharpe Ratio SE cumret

SK Hynix (Daily data)

SK하이닉스 Annualized Sharpe Ratio SK하이닉스 cumret

LG Chemicals (Daily data)

LG화학 Annualized Sharpe Ratio LG화학 cumret

Hyundai Cars (Daily data)

현대차 Annualized Sharpe Ratio 현대차 cumret

Naver (Daily data)

네이버 Annualized Sharpe Ratio 네이버 cumret

With LSTM

BTC-USD (30 minutes data)

BTCUSD LSTM Annualized Sharpe Ratio BTCUSD LSTM cumret

Samsung Electronics (Daily data)

SE LSTM Annualized Sharpe Ratio SE LSTM Cumret

References: