R Neural Network example - Matlab, R project and Python | futures io social day trading

R Neural Network example
 Updated: December 14th, 2015 (10:03 AM) Views / Replies: 2,945 / 13 Created: August 7th, 2014 (07:02 PM) by Big Mike Attachments: 0

 Welcome to futures io.

# R Neural Network example

Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500

Posts: 46,336 since Jun 2009

R Neural Network example

Inovance Blog - Using a Neural Network to Model the S&P 500

Code
 ```install.packages("quantmod") library("quantmod") #Allows us to import the market data and indicators we need install.packages(“neuralnet”) library(“neuralnet”) #Provides the artificial neural network algorithm (there are a variety of R packages that allow you build ANNs, however neuralnet allows us to easily plot the network and has all the functionality we need for this example) startDate<-as.Date('2009-01-01') endDate<-as.Date('2014-01-01') getSymbols("^GSPC",src="yahoo",from=startDate,to=endDate) #Retrieve the data we need RSI3<-RSI(Op(GSPC),n=3) #Calculate a 3-period RSI EMA5<-EMA(Op(GSPC),n=5) EMAcross<-Op(GSPC)-EMA5 #Look at the difference between the open price and a 5-period EMA MACD<-MACD(Op(GSPC),fast = 12, slow = 26, signal = 9) MACDsignal<-MACD[,2] #Grab the signal line of the MACD BB<-BBands(Op(GSPC),n=20,sd=2) BBp<-BB[,4] #We will use the Bollinger Band %B, which measures the price relative to the upper and lower Bollinger Bands Price<-Cl(GSPC)-Op(GSPC) #For this example we will be looking to predict the numeric change in price DataSet<-data.frame(RSI3,EMAcross,MACDsignal,BBp,Price) DataSet<-DataSet[-c(1:33),] colnames(DataSet)<-c("RSI3","EMAcross","MACDsignal","BollingerB","Price") #Create our data set, remove the data where the indicator values are being calculated, and name our columns```

Code
 ```Then normalize our data. Normalized <-function(x) {(x-min(x))/(max(x)-min(x))} NormalizedData<-as.data.frame(lapply(DataSet,Normalized)) #We are normalizing our data to be bound between 0 and 1 And create our training and test sets: TrainingSet<-NormalizedData[1:816,] TestSet<-NormalizedData[817:1225 ,] Now let’s actually build our artificial neural network. nn1<-neuralnet(Price~RSI3+EMAcross+MACDsignal+BollingerB,data=TrainingSet, hidden=3, learningrate=.001,algorithm="backprop") #We are using our indicators to predict the price over the training set, and a learning rate of .001 with a backpropagation algorithm```
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Mike

 The following 4 users say Thank You to Big Mike for this post:

 August 7th, 2014, 07:02 PM #2 (permalink) Quick Summary Quick Summary Post Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

Austin TX

Broker/Data: RJO

Posts: 318 since Sep 2013

Big Mike
Inovance Blog - Using a Neural Network to Model the S&P 500

Code
 ```install.packages("quantmod") library("quantmod") #Allows us to import the market data and indicators we need install.packages(“neuralnet”) library(“neuralnet”) #Provides the artificial neural network algorithm (there are a variety of R packages that allow you build ANNs, however neuralnet allows us to easily plot the network and has all the functionality we need for this example) startDate<-as.Date('2009-01-01') endDate<-as.Date('2014-01-01') getSymbols("^GSPC",src="yahoo",from=startDate,to=endDate) #Retrieve the data we need RSI3<-RSI(Op(GSPC),n=3) #Calculate a 3-period RSI EMA5<-EMA(Op(GSPC),n=5) EMAcross<-Op(GSPC)-EMA5 #Look at the difference between the open price and a 5-period EMA MACD<-MACD(Op(GSPC),fast = 12, slow = 26, signal = 9) MACDsignal<-MACD[,2] #Grab the signal line of the MACD BB<-BBands(Op(GSPC),n=20,sd=2) BBp<-BB[,4] #We will use the Bollinger Band %B, which measures the price relative to the upper and lower Bollinger Bands Price<-Cl(GSPC)-Op(GSPC) #For this example we will be looking to predict the numeric change in price DataSet<-data.frame(RSI3,EMAcross,MACDsignal,BBp,Price) DataSet<-DataSet[-c(1:33),] colnames(DataSet)<-c("RSI3","EMAcross","MACDsignal","BollingerB","Price") #Create our data set, remove the data where the indicator values are being calculated, and name our columns```

Code
 ```Then normalize our data. Normalized <-function(x) {(x-min(x))/(max(x)-min(x))} NormalizedData<-as.data.frame(lapply(DataSet,Normalized)) #We are normalizing our data to be bound between 0 and 1 And create our training and test sets: TrainingSet<-NormalizedData[1:816,] TestSet<-NormalizedData[817:1225 ,] Now let’s actually build our artificial neural network. nn1<-neuralnet(Price~RSI3+EMAcross+MACDsignal+BollingerB,data=TrainingSet, hidden=3, learningrate=.001,algorithm="backprop") #We are using our indicators to predict the price over the training set, and a learning rate of .001 with a backpropagation algorithm```
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Mike

You forgot the package MASS to run NN

Code
 `library(MASS)`
somewhere at the top

Sody

 "The great Traders have always been humbled by the market early on in their careers creating a deep respect for the market. Until one has this respect indelibly engraved in their makeup, the concept of money management and discipline will never be treated seriously."
 The following user says Thank You to SodyTexas for this post:

Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500

Posts: 46,336 since Jun 2009

Not much discussion in this direction, took a year to catch the error

Mike

 The following user says Thank You to Big Mike for this post:

Market Wizard
Houston, TX

Favorite Futures: Energy

Posts: 2,388 since Dec 2013
Forum Reputation: Legendary

Big Mike
 Not much discussion in this direction, took a year to catch the error

My Machine Learning education has been coming a long a little slower than I wanted. I've been doing a lot of work in the last few weeks with Random Forests for the Kaggle Titanic Competition which I have found extremely interesting, but probably not relevant to my trading. SVM's and NN's always seem to be the thing I want to tackle next™

 The following user says Thank You to SMCJB for this post:

Austin TX

Broker/Data: RJO

Posts: 318 since Sep 2013

SMCJB
 My Machine Learning education has been coming a long a little slower than I wanted. I've been doing a lot of work in the last few weeks with Random Forests for the Kaggle Titanic Competition which I have found extremely interesting, but probably not relevant to my trading. SVM's and NN's always seem to be the thing I want to tackle next™

I learned ML from UDEMY for both Python and R. Might be worth looking at.

Sody

 "The great Traders have always been humbled by the market early on in their careers creating a deep respect for the market. Until one has this respect indelibly engraved in their makeup, the concept of money management and discipline will never be treated seriously."
 The following 2 users say Thank You to SodyTexas for this post:

 December 9th, 2015, 02:44 PM #7 (permalink) Market Wizard Houston, TX   Futures Experience: Advanced Platform: XTrader Broker/Data: Advantage Futures Favorite Futures: Energy   Posts: 2,388 since Dec 2013 Thanks: 1,931 given, 4,012 received Forum Reputation: Legendary I have one of their courses open in my browser as we speak. Their stuff looks interesting but I havent taken any actual courses yet. I did do the coursera.org machine learning course 18 months ago which I thought was very good. Wish it had been in R rather than Octave though. Also a little surprised they didnt cover CART and Random Forest's, one of the reasons I've been looking at them the last two months.

Elite Member
glostrup, denmark

Platform: Custom platform
Broker/Data: CQG
Favorite Futures: Futures, Options, Stocks

Posts: 249 since Aug 2011

SMCJB
 My Machine Learning education has been coming a long a little slower than I wanted. I've been doing a lot of work in the last few weeks with Random Forests for the Kaggle Titanic Competition which I have found extremely interesting, but probably not relevant to my trading. SVM's and NN's always seem to be the thing I want to tackle next™

Good luck with the survivor-classification

And using random forests for classification can definitely be applied for use in trading, so time well spent

 The following user says Thank You to ktrader for this post:

Austin TX

Broker/Data: RJO

Posts: 318 since Sep 2013

SMCJB
 I have one of their courses open in my browser as we speak. Their stuff looks interesting but I havent taken any actual courses yet. I did do the coursera.org machine learning course 18 months ago which I thought was very good. Wish it had been in R rather than Octave though. Also a little surprised they didnt cover CART and Random Forest's, one of the reasons I've been looking at them the last two months.

They been offering \$15 dollar sales on most of there classes. CART and Random Forest is covered in the link I posted.

 "The great Traders have always been humbled by the market early on in their careers creating a deep respect for the market. Until one has this respect indelibly engraved in their makeup, the concept of money management and discipline will never be treated seriously."
 The following user says Thank You to SodyTexas for this post:

Market Wizard
Houston, TX

Favorite Futures: Energy

Posts: 2,388 since Dec 2013
Forum Reputation: Legendary

 Good luck with the survivor-classification And using random forests for classification can definitely be applied for use in trading, so time well spent --ktrader

Yes i've found the whole concept of random forests very very interesting and had a lot of fun investigating/optimizing with leaf sizes and mtry settings. Specific to the Kaggle Titanic problem though I've found that my models are overfitting the data and out of sample scores are lower, which wasnt as much the case when i was doing Logistic regression (before I knew about Forests). I have thought of some potential trading applications but it'll probably be months before I start investigating them. I don't have anything to base this on, but I was expecting SVM and NN to be better for trading.

SodyTexas
 They been offering \$15 dollar sales on most of there classes. CART and Random Forest is covered in the link I posted.

Thanks Sody I'll definitely take a look. I like watching video's like that during the trading day when things get quiet. I assume if you buy the course you can go back and rewatch the video's as much as you like?

 futures io > R Neural Network example

Upcoming Webinars and Events (4:30PM ET unless noted)

Elite only

## Digging into the Details of iSystems w/Stage 5 & iSystems

Jun 5

 Similar Threads Thread Thread Starter Forum Replies Last Post zacharydw00 EasyLanguage Programming 67 July 19th, 2014 05:02 PM bnichols NinjaTrader Programming 28 December 24th, 2012 02:20 PM emini_Holy_Grail Trading Reviews and Vendors 4 October 30th, 2010 08:55 AM gabga100 Platforms and Indicators 3 December 10th, 2009 02:38 AM

All times are GMT -4. The time now is 11:54 AM.

 Copyright © 2018 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io All information is for educational use only and is not investment advice.There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2018-05-26 in 0.13 seconds with 19 queries on phoenix via your IP 54.167.216.239