XBTUSD Regression 1 (Machine learning to obtain Decision Trees )
Forums › ProRealTime English forum › ProOrder support › XBTUSD Regression 1 (Machine learning to obtain Decision Trees )
- This topic has 11 replies, 4 voices, and was last updated 7 years ago by Degardin Arnaud.
-
-
11/04/2017 at 5:11 PM #51470
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
12345678910111213141516171819202122232425262728293031323334353637// Definizione dei parametri del codiceDEFPARAM CumulateOrders = False // Posizioni cumulate disattivateRSI5 =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=200bbfact=1equa=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 THENSELLSHORT 1 CONTRACT AT MARKETENDIFIF TOBUY THENBUY 1 CONTRACT AT MARKETENDIF//GRAPH equa//GRAPH average[per](equa)+std[per](equa)//GRAPH average[per](equa)-std[per](equa)11/04/2017 at 8:26 PM #51503Hello, 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.11/05/2017 at 1:10 AM #5154711/05/2017 at 11:36 AM #51556Hi, 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.
- Converting linear regression models in equation or
- Decision trees in IF, THEN logics.
- 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!
11/05/2017 at 1:44 PM #51558Hi 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.
11/05/2017 at 2:31 PM #51560Hi 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
11/05/2017 at 3:25 PM #51563R 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:
- 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.
- Determination of future price movement by shifting values to 5 periods in the future
- Calculation of custom and standard indicators (TTR)
- Training of the model (classification, neural network or regression)
- 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
11/05/2017 at 5:26 PM #5156711/06/2017 at 5:21 PM #51707here i.e. another multiple regression optimized on the long side…
I don’t know how to use neural network “as equation” in PRT?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253// Definizione dei parametri del codiceDEFPARAM CumulateOrders = False // Posizioni cumulate disattivateRSI5 =RSI[5](close)ATR5 = AverageTrueRange[5](close)ATR20 = AverageTrueRange[20](close)RatioATR=ATR5/ATR20PEMA5 = 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)/openRatio1=close[1]/Open[1]Myhour=hourequa=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=200bbfact=1BBUP=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 MARKETENDIFIF TOBUY THENBUY 1 CONTRACT AT MARKETENDIF//IF SHORTONMARKET and equa CROSSES UNDER 0 THEN//EXITSHORT AT MARKET//ENDIFIF LONGONMARKET and TOSELL THENSELL AT MARKETENDIFGRAPH equaGRAPH BBUPGRAPH BBDOWN11/07/2017 at 10:46 AM #51770Coding 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…
11/07/2017 at 2:28 PM #5181711/07/2017 at 4:52 PM #51842Hi 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… 😉
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on