How To Use Regression Splines In Trading Binary Options?

Algorithmic trading is becoming the norm now a days. Today more than 60% of the trades at Wall Street are being placed by algorithmic trading systems. Did you read the post on a 30 minute binary options trading strategy with 90% winrate? In this post we discuss how we can use regression splines in predicting the price after n minutes and then use that information to trade binary options. If you are not sure what are regression splines, you can watch the video tutorial below before you continue reading the post!

Above is a very good detailed tutorial on multiple variable adaptive regression splines also know as MARS. We will be using MDA R pacakge that implements the MARS algorithm. The concept of Hinge is very important in MARS algorithm. In linear regression, we fit a straight line to the data. In MARS we use a hinge to change the direction of the straight line so that we get a new line that is joined to the old line at the hinge. Now we don’t need to worry how to calculate these hinge points, MARS algorithm will do it automatically for you. We will implement MARS using R. So you should have R installed alongwith RStudio. We will try to predict EURUSD price after 5 minutes. If we can do that with 90% accuracy we have a very good system that can make 10 trades in each hour. So let’s start. Below is the R code for this Regression Splines Binary Options Trading Strategy.

> #regression splines
> ###Binary Options Trading System###
> #import the data
> 
> data <- read.csv("E:/MarketData/EURUSD1.csv", header = FALSE)
> 
> 
> 
> colnames(data) <- c("Date", "Time", "Open", "High",
+                     "Low", "Close", "Volume")
> 
> 
> x1 <- nrow(data)
> 
> library("quantmod")
> data2 <- as.xts(data[,-(1:2)], as.POSIXct(paste(data[,1],data[,2]),
+                                           format='%Y.%m.%d %H:%M'))
> 
> 
> 
> data2$rsi <- RSI(data2$Close)
> data2$MACD <- MACD(data2$Close)
> data2$will <- williamsAD(data2[,2:4])
> data2$cci <-  CCI(data2[,2:4])
> data2$STOCH <- stoch(data2[,2:4])
> data2$Aroon <- aroon(data2[, 2:3])
> data2$ATR <- ATR(data2[, 2:4])
> 
> 
> #convert this data to n timeframe
> 
> n=5
> 
> #define lookback
> 
> lb=500
> 
> #define the minimum pips
> 
> pip <- 2
> 
> #define a new data frame
> 
> data1 <-data.frame(matrix(0, ncol=57, nrow=500))
> 
> colnames(data1) <- c("Date", "Time", "Open", "High",
+                      "Low", "Close", "O1", "H1", "L1", "C1", "V1",
+                      "O2", "H2", "L2", "C2", "V2",
+                      "O3", "H3", "L3", "C3", "V3",
+                      "O4", "H4", "L4", "C4", "V4",
+                      "O5", "H5", "L5", "C5", "V5", 
+                      "T1", "T2", "T3", "T4", "T5",
+                      "T6", "T7", "T8", "T9", "T10",
+                      "T11", "T12", "T13", "T14", "T15",
+                      "T16", "T17", "T18", "T19", "T20", 
+                      "T21", "T22", "T23", "T24", "T25",
+                      "Pip")
> 
> # run the sequence to convert to a new timeframe
> 
> for ( k in (1:lb))
+ {
+   data1[k,1] <- as.character(data[x1-lb*n+n*k-1,1])
+   data1[k,2] <- as.character(data[x1-lb*n+n*k-1,2])
+   data1[k,3] <- data[x1-lb*n+n*(k-1),3]
+   data1[k,6] <- data[x1-lb*n+n*k-1,6]
+   data1[k,4] <- max(data[(x1-lb*n+n*(k-1)):(x1-lb*n+k*n-1), 4:5])
+   data1[k,5] <- min(data[(x1-lb*n+n*(k-1)):(x1-lb*n+k*n-1), 4:5])
+   
+   for (i in (1:n))
+   {
+     data1[k, 6+i] <- data[x1-lb*n+n*(k-1), 2+i]
+     data1[k, 11+i] <- data[x1-lb*n+n*(k-1)+1,2+i]
+     data1[k, 16+i] <- data[x1-lb*n+n*(k-1)+2,2+i]
+     data1[k, 21+i] <- data[x1-lb*n+n*(k-1)+3,2+i]
+     data1[k, 26+i] <- data[x1-lb*n+n*(k-1)+4,2+i]
+     
+     #add the technical indicators  
+     
+     data1[k, 31+i] <- data2[x1-lb*n+n*(k-1), 5+i]
+     data1[k, 36+i] <- data2[x1-lb*n+n*(k-1)+1,6+i]
+     data1[k, 41+i] <- data2[x1-lb*n+n*(k-1)+2,7+i]
+     data1[k, 46+i] <- data2[x1-lb*n+n*(k-1)+3,8+i]
+     data1[k, 51+i] <- data2[x1-lb*n+n*(k-1)+4,9+i]
+   }
+ }
> 
> 
> 
> 
> for (i in (1:(lb-1)))
+ {
+   data1[i+1, 57] <- 10000*(data1[i+1, 6]-data1[i,6])
+   data1[i, 57] <- data1[i+1, 57] 
+   
+   
+ }
> 
> nn <- ncol(data1)
> 
> library(mda)
> m <- mars(data1[3:(lb-1),3:(nn-1)], data1[3:(lb-1),nn])
> m.preds <- predict(m,data1[lb, 3:(nn-1)])
> m.preds
          [,1]
[1,] 0.1929497

In the above code, we tried to predict price after 5 minutes. First we calculated the usual technical indicators like the RSI, MACD, Stochastic etc. Then we made a data frame that included the data. After that we applied the MARS algorithm to the data. The model predicted that price after 5 minutes will only be 0.192 pips above the present price.

> data1[lb,2]
[1] "16:33"
> data1[lb,6]
[1] 1.06495

In the above code you can see price was 1.06495 and the predicted price after 5 minutes will be:

> 0.1929497/10000+1.06495
[1] 1.064969

We don’t need to make the above calculation. We know that price will only be 0.19 pip above the present price after 5 minutes. So we need a rule that tells us when to open a binary options trade. We will open a binary options trade if price will be 2 pips above or below the present price after 5 minute. If the model predicts that price will be 3 pips above the present price we will buy a 5 minute expiry call option. On the other hand if the model predicts price will be 2 pips below the present price, we will buy a 5 minute expiry put option.

We can change the time of prediction to whatever time period we want in the above code. Now the MDA R package is very fast and does all the calculations in less than 2-3 seconds. This means you have the prediction about the price in just 2-3 seconds which is very good. Once you have the prediction, you can enter into a call/put trade as the case maybe. So this was the Regression Splines Binary Options Trading Strategy. In the next post we are going to backtest this trading strategy and check how much accurate this binary options trading strategy. Did you read the post on the 3 EMA Rainbow Binary Options Trading Strategy?

Now there are many binary options traders who are killing it with 1 minute expiry options. 1 minute expiry options are pretty fast. Did you read the post on a 1 minute binary options strategy? 5 minute expiry options are much better as you have some time to make the predictions and enter the trade in the right direction.