Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a full code for Algorithmic Trading in R language for one stock using Neural Network package in R: Price prediction - based trading. Build

write a full code for Algorithmic Trading in R language for one stock using Neural Network package in R:
Price prediction-based trading. Build a model to predicting the price for the coming day. This could include various key factors from previous days such as opening price, closing price, high price, low price, volume, Relative Strength Index (RSI), Exponential Moving Average (EMA) etc, or just values from the previous days trading. On top of this prediction you would then build a trading rule which would choose to buy/sell/hold based on the current and predicted values (for example).
Key Components
With the above you will need to train a model of some sort ( NN) so will need some notion of fitness or performance. This is obviously problem-dependent but at some point will need to evaluate profit: for whichever trading rule you are developing you will need to iterate through the training data and calculate your earnings (through returns or sales) on some notional amount of investment (let's say 10,000) if your trading rule was to be invoked.
You will also need to keep some data in reserve for back-testing: i.e. keep some unseen historical data in reserve on which to evaluate the profitability of your final rule.
Also, as with forecasting and prediction, you will be working with time series data, so the size of the window needs to be considered (this will depend upon the characteristics of the data you are using).
Some Useful Resources
A useful package to assist in doing this is quantmod - designed to support the rapid development and evaluation of trading models. As you will have seen, amongst other things it makes getting hold of data very straightforward and also provides functions for the opening and closing prices, high and low values, volume etc. - just take a look at some of the examples.
Another value package is TTR, which again provides a myriad of functions for building trading rules, but in particular ones for RSI and EMA. If you use quantmod then TTR will be installed by default as quantmod depends on it.
A couple of hints on handling the data...
When using the quantmod package the data is in a time series structure called "xts". You can check this as follows (for example):
getSymbols("GOOG",src="yahoo")
str(GOOG) # this will give you the structure
head(GOOG) #will give you the first few lines of the data
This means it has to be extracted for use within the fitness function. There are several ways to doing this but one fairly simple one is to use the coredata() function. e.g.
gdat <-coredata(GOOG) # Create a 2-d array of all the data. Or...
gdatfr <- data.frame(date=index(GOOG), coredata(GOOG)) # Create a data frame with the data and (optionally) maintain the date as an index
We could then a vector of the opening prices using one of the following:
opdat <- gdat[,1] # or...
opdat <- gdatfr$GOOG.Open
Also, one of the other things you might find is that the volume values are too high for a GP to handle without losing accuracy so you could try scaling these down by several orders of magnitude.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

4. I give a fair hearing to fellow members ideas.

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago