jinglescode / time-series-forecasting-pytorch

Acquiring data from Alpha Vantage and predicting stock prices with PyTorch's LSTM

Home Page:https://www.alphavantage.co/academy/#lstm-for-finance

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

It seems like predicted price is off 1 day on IBM or maybe i missunderstood something

deriklogov opened this issue · comments

Hi,
I was very impressed with the result of prediction graph of IBM but than i noticed that actual prediction is going after next day of actual data, so i decide to print out some piece of data with this :

print("Actual/Predicted prices:") for i in range(len(data_close_price)): print(str(data_close_price[i]) + '\t ' + str(to_plot_data_y_train_pred[i]) + '\t' + str(to_plot_data_y_val_pred[i]))

and here is a piece of output ( i grabbed a piece where the stock went up to make it clear):
data_close_price to_plot_data_y_train_pred to_plot_data_y_val_pred
61.5541637158 62.48051591375582 None
63.1859297539 61.81105258680695 None
65.5087283847 63.22269362984531 None
65.2532205353 65.42579108472087 None
70.2646585813 65.24432286147622 None
69.5387840091 70.2044966634442 None

lets check 2nd row, date_close_price showing 63.1859 while prediction price is 61.8110
and then on next day data_close_price 65.508 and prediction 63.222 ,
so it seems that prediction price is one day behind ???
Please advice, maybe i dont understand it

to be clear, to me it looks like next day prediction price is very close to previous day actual price

Same problem. I don't get it.
Figure_4

I am just leaving a comment here to catch your solution. I am also working on this problem right now.

how did you go with this? I am looking at the same problem.

Ok, my idea is that the machine is cheating. It gives you back a value very close to the previous day, since it should be the closest one to the real value without doing prediction.
I used different networks and the result was usually the same. Doublechecked every variable, label, etc. That wasnt the problem.

Perhaps a little late, but...
Making price predictions based on past prices is a poorly feasible task (I think generally impossible). The first thing that stands out is that the predictions are perfect (but "shifted"). The data link is not good enough for the model to make such good predictions.
If you want at least some predictions based on previous courses, you can try the step not for a day, but for a week or a month. In such a case, a stable market can have a normal result (when was the market last stable?).
If you still want to analyse (whether for a day or for a week does not matter), then add at least a hundred economic parameters to the model. The problem with learning is not writing code (with libraries like PyTorch or TensorFlow it is not very difficult), but preparing the data. Alphavintage offers a handy API, but you need data, for example, from any statistical bureau. Be sure to watch all reports and the US economy (there are economic calendars, although APIs are paid for historical data almost everywhere), a little for China, Japan and the EU.
In general, machine learning is not a panacea. If you have several trillion parameters, then maybe it will. Right now you can add a hundred parameters and see if there is a prediction (it does not matter if it is inaccurate). I have not tried it, but you can use fingpt, for example, to analyze non-numeric data. Then give it your predicted numbers and listen to the advice for the next day.
UPD. Forgot to say. Do not analyze absolute values (even normalized ones). That is completely useless, in my opinion. Analyze the change in magnitude. For example: value_rel = (value_cur - value_prev)/value_prev