XBTUSD Regression 1 (Machine learning to obtain Decision Trees )

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #51470 quote
    Degardin Arnaud
    Participant
    Junior

    Hi,

    I would like to share some research with PRC community. I’m trying to obtain better Equation for price prediction using different kind of indicators. This is an example obtained by multiple factors linear regression in R, but it is also possibile using Machine learning to obtain Decision Trees logics to convert in PRT code with “if.then” .

    The regression coefficient are not so good because I think it is difficult to predict future price analysis past bars, but if someone would like make some trials with some indicators or periods, I could analyse the best factors in R with historical data.

    Also it is possible to use neural network but regression results I found some the moment are not so different from linear regression…

    Thanks for your comments and suggestions

    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
    
    RSI5 =RSI[5](close)
    RSI52 =RSI5[2]
    
    PEMA5 = Close/ExponentialAverage[5](close)
    
    PEMA54 = PEMA5[4]
    
    MACDI = MACD[12,26,9](close)
    
    stoc = Stochastic[14,3](close)
    stoc4 =stoc[4]
    per=200
    bbfact=1
    equa=average[5](-0.1723115730202-0.0000004812401*RSI52+0.1724972202839*PEMA54-0.0003557490946*stoc4+0.0013032691813*MACDI)
    
    BBUP=average[per](equa)+bbfact*std[per](equa)
    BBDOWN=average[per](equa)-bbfact*std[per](equa)
    //MEAN=average[50](equa)
    
    TOSELL= (equa CROSSES UNDER BBUP) OR (ONMARKET AND equa CROSSES OVER BBUP)
    
    TOBUY= (equa CROSSES OVER BBDOWN) OR (ONMARKET AND equa CROSSES UNDER BBDOWN)
    
    IF TOSELL THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    IF TOBUY THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    //GRAPH equa
    //GRAPH average[per](equa)+std[per](equa)
    //GRAPH average[per](equa)-std[per](equa)
    stefou102 and juanj thanked this post
    photo-1509805072pc8l4.jpg photo-1509805072pc8l4.jpg
    #51503 quote
    Jesús
    Participant
    Veteran

    Hello, congratulations for your work and thanks for sharing. The backtest shows very good results, but I do not know if you have taken into account the cost of the Bitcoin operation, given that the spread is 10 points.
    Best regards.

    #51547 quote
    stefou102
    Participant
    Veteran

    Hello, unfortunately your regression is overfitted on short term data, 200k bar backtest is flat until 15 september.

    #51556 quote
    Degardin Arnaud
    Participant
    Junior

    Hi, thanks for your answers! I know that this precise model is not profitable or have some defects

    I’m searching some people who have basis notions in R programming and machine learning to try a lot of models that it is possibile to obtain from it and try it in PRT.

    1. Converting linear regression models in equation or
    2. Decision trees in IF, THEN logics.
    3. Neural Network tree in weighted equations

    If you have some knowledge in R programming I should send to you my R codes for historical data extraction, model training / regression.

    Note that a lot of those results will be “overfitted” by nature of the use of machine learning training.

    But I think that it’s possibile also to create some auto-adaptative models or equity slope change alerts…

    Thanks!

    #51558 quote
    Nicolas
    Keymaster
    Master

    Hi Arnaud, thanks for your sharing and to propose different approach. I know quite well R language, and even if I do not have a lot of time to invest in all the good discussions around here (and at the same time OMG .. 😉 ), I can have a look on your machine learning code, as long as discussions remain public in this topic for the benefit of everyone.

    #51560 quote
    Degardin Arnaud
    Participant
    Junior

    Hi Nicolas, ok no problem! sharing with community could only improve the possibilities and the code…

    Let me write an explanation text before.

    Also how can I share “.R” or “CSV” type files  on the platform? (it gives me an error)

    Thanks

    #51563 quote
    Degardin Arnaud
    Participant
    Junior

     

    R code for decision trees models uses “caret” package. Neural network uses “neuralnet” package. Standard trading indicators are calculated using “TTR” package.

     

    Note: You will find the original code sources for each techniques as references, but all code has been modified and can’t give any guarantee of success for trading.

     

    1.Process of data Analysis:

    1. Data extraction: I used MT4 platform to export historical data in CSV format at prefered timeframe. The path to csv file must be indicated in the code.  
    2. Determination of future price movement by shifting values to 5 periods in the future
    3. Calculation of custom and standard indicators (TTR)
    4. Training of the model (classification, neural network or regression)
    5. Printing / analysis of results

     

    2.CLASSIFICATION MODEL for NON-PARAMETRIC PREDICTION

     

    Filename: “Predictive RPART Price Modeling v3.0.R”

     

    (code reference: https://www.quantinsti.com/blog/predictive-modeling-algorithmic-trading/)

     

    The price value is transformed to non-parametric “class” of movement: UP, DOWN or NOTHING (possibile actions to BUY, SELL or NOTHING).

    The file uses rpart training method to obtain decision trees, without pre processing to maintained values scales of each indicators.

     

    PRO: rpart used directly is very fast. Random forest features selection skipped because too slow..

    CONS: I omit to test the model on real data after training: I prefer to make it directly in “backtest” with  trading code like Prorealcode or MQL4

     

    3.NEURAL NETWORK AND REGRESSION MODEL for PARAMETRIC PREDICTION

     

    Filename “neuralnetR for PRT v1.2.R”

     

    (code reference: https://www.r-bloggers.com/fitting-a-neural-network-in-r-neuralnet-package/)

     

    It use parametric values of price changes from now to 5 periods in the future.

    The file uses neural network compared to multiple linear regression.

     

    PRO: regression is faster but works for parametric features (how to choose it?)

    Easier to classification because there is no need to transform values in “classes”.

    CONS: neural network difficult to code in trading system. Features must be reduced at the minimum.

    I create a repository here : https://github.com/adegard/PRT

    You will find source code and csv historical data for example.

    Thanks for you comments

    #51567 quote
    Nicolas
    Keymaster
    Master

    Thanks, I’ll try to give a look this week.

    #51707 quote
    Degardin Arnaud
    Participant
    Junior

    here i.e. another multiple regression optimized on the long side…

    I don’t know how to use neural network “as equation” in PRT?

    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
    
    RSI5 =RSI[5](close)
    
    ATR5 = AverageTrueRange[5](close)
    ATR20 = AverageTrueRange[20](close)
    RatioATR=ATR5/ATR20
    
    PEMA5 = Close/ExponentialAverage[5](close)
    //PEMA51 = PEMA5[1]
    //PEMA52 = PEMA5[2]
    PEMA54 = PEMA5[4]
    EMA520= ExponentialAverage[5](close)/ExponentialAverage[20](close)
    //bb5 = CALL "%BB5"
    
    MACDI = MACD[12,26,9](close)
    
    Gain=(close-open)/open
    
    Ratio1=close[1]/Open[1]
    Myhour=hour
    
    
    equa=average[2](-215.46885204  +RSI5     *     -0.01918558    +Myhour     *    0.11298629    +RatioATR  *     5.23214250    +PEMA54    *   -40.92819460   +EMA520    *   291.14623016  +Ratio1   *    -38.69161992   +MACDI    *     -2.48368221    +Gain    *     -23.04766049      )
    
    per=200
    bbfact=1
    BBUP=average[per](equa)+bbfact*std[per](equa)
    BBDOWN=average[per](equa)-bbfact*std[per](equa)
    //MEAN=average[50](equa)
    
    TOSELL= (equa  CROSSES UNDER BBDOWN) //OR (ONMARKET AND equa CROSSES OVER BBUP)
    TOBUY= (equa  CROSSES OVER BBUP)// OR (ONMARKET AND equa CROSSES UNDER BBDOWN)
    
    IF TOSELL THEN
    //SELLSHORT 0.1 CONTRACT AT MARKET
    ENDIF
    IF TOBUY THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    //IF SHORTONMARKET and equa CROSSES UNDER 0 THEN
    //EXITSHORT AT MARKET
    //ENDIF
    IF LONGONMARKET and TOSELL THEN
    SELL AT MARKET
    ENDIF
    
    
    GRAPH equa
    GRAPH BBUP
    GRAPH BBDOWN
    
    photo_2017-05-21_22-04-46.jpg photo_2017-05-21_22-04-46.jpg
    #51770 quote
    Degardin Arnaud
    Participant
    Junior

    Coding a Decision tree could be a little tricky in PRT… here I give an example of Caret-Rpart results (in R) convert to PRT code for EURUSD 30Minutes… Results are not so good,  because accuracy of model depends so much about the choice of factors…

    eurusd30tree.jpeg eurusd30tree.jpeg EURUSD-v10.itf photo_2017-05-21_22-04-46-1.jpg photo_2017-05-21_22-04-46-1.jpg
    #51817 quote
    Nicolas
    Keymaster
    Master

    Tricky but seems like you made it 🙂 Do the settings are over-fit by the training model or did you make some validations somehow?

    #51842 quote
    Degardin Arnaud
    Participant
    Junior

    Hi Nicolas, yes, it is possibile in R to test models by using some real data (typically 20%) and also to plot the equity line… but for some reasons, the backtests in R and on other platforms (PRT or metatrader) doesn’t give the same results.

    The best way should be to find machine learning directly integrated in trading platform which find automatically models using indicators and historical data from the platform itself. I hope those new “features” could be accessibles for all of us.

    In fact intuitive methods of writing strategies are “old” method of trading and we need new tools to fastered strategy creation (take a look of the attached image from hiHedge, a new generattion of AI traders from Singapor. ) Not at the same level… but it could be nice to use Neural Network or Deep learning for “common” people trading… 😉

    juanj thanked this post
    d9fb42_4eb1f89eeaaf438f8e2e96f3642c0a81-mv2.png d9fb42_4eb1f89eeaaf438f8e2e96f3642c0a81-mv2.png
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

XBTUSD Regression 1 (Machine learning to obtain Decision Trees )


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 11 replies,
has 4 voices, and was last updated by Degardin Arnaud
8 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/04/2017
Status: Active
Attachments: 6 files
Logo Logo
Loading...