data preparation and format for NARX

7 views (last 30 days)
Hello everybody,
I am trying to use arx in order to predict the stock price movement a day ahead.
I have two vectors: dailyReturns that contain returns of each day. the first index of the vector contains the return of the closest date (ex: today) and the last index of the vector contains the return of the latest date (ex: two years ago).
****************************************
Here are the vectors:
DailyReturns = [return(day1) return(day2) return(day3) ... return(dayN)];
positive=find(DailyReturns>0); spotTrend(positive)=1;
negative=find(DailyReturns<0); spotTrend(negative)=(-1);
spotTrend is something like that = [-1 1 1 1 -1 1 -1 -1 ...]
moreover the size of the two vectors are identical.
******************************************
So let say I would like to use ARX: input data is DailyReturns. target data is spotTrend.
The questions are the following:
1- can I use directly these two vectors for ARX. or do I have to shift my target data so that the index number 1 of input vector is linked to the index number 2 of target vector (because I want to predict the sign of the return a day ahead).
2- my input data must be in an increasing temporal order or a decreasing temporal order? Does it matter? i.e do I have to feed my neural networks with DailyReturns = [return(dayN) return(day N-1) return(dayN-2) ... return(day 1)];
or like this
DailyReturns = [return(day1) return(day2) return(day3) ... return(dayN)];
thank you a lot for your answer. I do not find a matlab tutorial of how to prepare the data for nnet.
thanks

Accepted Answer

Greg Heath
Greg Heath on 5 Feb 2013
Vector indices increase with time. Plot the target series
t(i) = (price(i)-price(i-1))/price(i-1) % Relative price change for i>=2
Calculate the autocorrelation function and determine the statistically significant lags
You have decided to predict 1 day ahead.
Look at the sig lags of the acf to determine how many delays (= No. of past day prices) to use in narnet.
help narnet
doc narnet
help preparets
doc preparets
help configure
doc configure
help nndata %Find more data and demos for narnet
When you run the examples in the documentation, remove the ending semicolons so that you can understand what each command does.
Also search the NEWSGROUP and ANSWERS posts separately using those three as search words.
Use as many defaults as possible. However, Do not use the default divideFcn = 'dividerand'. It destroys correlations . I prefer 'divideblock'.
Hope this helps.
Thank you for formally accepting my answer.
Greg

More Answers (4)

Shashank Prasanna
Shashank Prasanna on 3 Feb 2013
PREPARETS will do it for you:
Take look at the NARX example below.
  1 Comment
allline
allline on 5 Feb 2013
Hello,
Thank you for your answers. I appreciate a lot. Unfortunately, I do not really understand how the function PREPARETS works.
I want to be sure about the inputs and targets I have to use. Let's say I have four inputs (day 1 to day 4) and I want to predict the stock price movement of days (day 2 to day 5).
When I was using the pattern recognition tool (nprTool) and I was trying to predict an increase (+1) or decrease(-1) of stock price of the NEXT day, I was using this scheme:
inputs_solution1 = [StockReturn(day 1) StockReturn(day 2) StockReturn(day 3) StockReturn(day 4)]; targets_solution1 = [StockPriceMovement(day 2) StockPriceMovement(day 3) StockPriceMovement(day 4) StockPriceMovement(day 5)];
with StockPriceMovement = +1 or -1
*my question is the following: *
*Do I have to use the INPUTS_SOLUTION_1 and TARGETS_SOLUTION_1 in the function PREPARETS ?
Or do I have to use the following INPUTS_SOLUTION_2 and TARGETS_SOLUTION_2, and PREPARETS will take care to link [StockReturn(day J)] to [StockPriceMovement(day J+1)]*
inputs_solution2 = [StockReturn(day 1) StockReturn(day 2) StockReturn(day 3) StockReturn(day 4)];
targets_solution2 = [StockPriceMovement(day 1) StockPriceMovement(day 2) StockPriceMovement(day 3) StockPriceMovement(day 4)];
thank you.

Sign in to comment.


Greg Heath
Greg Heath on 4 Feb 2013
I don't think your approach will work anywhere near as well as one that defines a trend in terms of a positive or negative slope over a specified time interval.
In addition, you should be looking for relative (e.g., %) changes in value, not the values themselves.
Hope this helps.
Greg
  1 Comment
allline
allline on 5 Feb 2013
Hi Greg,
Thank you for your comment.
How would you model the problem?
about your comment on relative change of stock price. Could you give me more details, because I think it is already done in my model.
What I am currently trying to do is: [return(day 1) : return(day 4)] --- predicts --> sign(return(day5))
thanks

Sign in to comment.


allline
allline on 6 Feb 2013
Hey Greg, thanks again for your answers. But I still don't understand how to tell to my narx that I want to predict a time serie one step ahead.
Here I extract and create my data:
price=load_stock_price; %price dimension 1xN
input(i) = (price(i)-price(i-1))/price(i-1); %input dimension 1x(N-1)
target(i) = sign (input(i)); %target dimension 1x(N-1)
let's say I need stock return of today and yesterday in order to predict the sign of tomorrow's stock return ==> target(i+1) = function( input(i) , input(i-1) )
do I have to do sthg like this: (I try to do as it is explained in a matlab doc)
ftdnn_net = timedelaynet([1:2],10);
ftdnn_net.divideFcn = 'divideblock';
p = input(3:end);
t = target(3:end);
Pi= input(1:2);
ftdnn_net = train(ftdnn_net,p,t,Pi);
Please, could you tell me if I created the right p, t and Pi in order to predict a step ahead ?
or do I have to do this:
p = input(3:end-1);
t = target(4:end);
Pi= input(1:2);
so that input(i) is linked to target(i+1)
last question: what is the difference if I set
ftdnn_net = timedelaynet([*0*:2],10);
instead of this
ftdnn_net = timedelaynet([*1*:2],10);
thank you.

Greg Heath
Greg Heath on 7 Feb 2013
I think you are making the problem more complicated than it is. Price is always positive. So what does
negative=find(DailyReturns<0); spotTrend(negative)=1;
mean? if return ~= price, then how is it defined?
You only have one series. Therfore you can use narnet, not narxnet to predict future values, future changes in value, or future changes in relative value.
If you cannot understand the preparets documentation, run the narx (not nar) example with ending semicolons omitted. Then type
whos
to understand how input dimensions are changed.
If you still don't understand, post your preparets questions with explanatory excerpts of your code and results.
Hope this helps.
Greg

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!