Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long term prediction using Artificial Neural Network

I am working on a project to predict stock price using ANN . I have trained the system using previous 7 years data and it works fine to predict data for one day . Now I want to predict stock price for next seven days .

My Idea is to predict day 2 data using day 1 , day 3 data using predicted data of day 2 and day 1 and so on. But it's not working properly .

I have trained ANN to predict closing price using opening price , maximum and minimum price of a day .

What is the idea to predict data of next seven days ??

like image 968
Quazi Marufur Rahman Avatar asked May 29 '12 10:05

Quazi Marufur Rahman


2 Answers

Maruf, if you have a reliable ANN predictor for 1 day ahead, please contact me to discuss further! LOL

Joking aside. Neural Networks and other non-linear predictors are just that - predictors. The data you are dealing with (stock price data) is largely random. If you don't believe me, try to generate a random walk using the following psuedo-code and plotting it on the screen:

let min = -0.5
let max = +0.5
let bias = 0.01
let random = rand(min, max)
y[i] = y[i-1] + random + bias

Adjust bias slightly (from -0.01 to 0.01) and you end up with series which looks a LOT like a trending stock price. The reason for this is in any underlying trend there are people that are making decisions no better than a coin flip. Did you know the average trader is right 55% of the time? That's all he needs...

Now, if the data is largely random then it becomes very hard to predict. You are looking for a signal in a large amount of noise. Every day ahead you try to predict your prediction becomes less accurate.

May I ask - what inputs have you put into the ANN to get a 1-day ahead prediction? If for instance you are using a daily stock prices plus other derived factors (such as rate of change, volumes, divergences etc...) to get an accurate 1-day prediction, you might find you can get an accurate 1 week prediction by substituting all the above with weekly stock data.

Edit:

Secondly, what are you doing to test accuracy of the predictor? To augment mikera's answer I would suggest a strategy such as the following.

Given a data window of 1000 days, take 800 of these and train your ANN. Now predict one day int he future. Compare the predicted direction (Up, Down) with the predicted closing price (% difference) to gauge accuracy for that result. Now slide the window 1 day to the right. Re-train the ANN and perform a 1 day prediction, noting results.

If you continue this for the remaining 200 days, what proportion of results got the correct direction (up, down)? What proportion of results were within 10% of the actual predicted closing price? If your ANN was placing orders at close of business of each day and closing them at the end of the next day, how much money would it have made? Accounting for slippage and trading fees of course ...

This will give you an idea of just how accurate and worthwhile the system is.

like image 199
Dr. Andrew Burnett-Thompson Avatar answered Oct 27 '22 00:10

Dr. Andrew Burnett-Thompson


You've done very well if you can predict even one day ahead effectively - the usual issues are:

  • Are you sure you are not overfitting, e.g. learning to replicate the features of your training data exactly? If you haven't tried it yet then I'd strongly recommend testing your ANN on 20% of your data after training it with the other 80% to be sure of this.
  • Also are you learning to predict absolute price values or deltas? if the former, then you are probably just getting a good fit from the fact that by far the best predictor of the next day's closing price is today's closing price (because the data has so much serial correlation). It's not uncommon to get 99%+ R-squared fits by making this mistake....

Assuming you haven't fallen into one of the above traps, then the way to do multiple days of prediction is to simply have separate predicted variables for each of the future days independently. There isn't much additional value in feeding the next day predictions into the 2nd day etc. (since you don't have any new information in your input data), but you can try it if you like (can't do any harm, might speed up learning by providing a useful feature detector etc.).

Also you would expect uncertainly / variation on the further-out predictions to be greater (because there are more days of uncertain stock price movements between now and then). It's worth trying to predict the variance of your statistics as well as the mean for this reason.

like image 38
mikera Avatar answered Oct 26 '22 23:10

mikera