Time series analysis



Hi all,

I have started a new project that is based on time series forecasting in which I am trying to use this methods:

But, while working on it I found couple of errors:

  1. While writing the ARIMA code as follows and I found the following error:
    y_hat_avg = test.copy()
    fit1 = sm.tsa.statespace.SARIMAX(train1[‘Adj Close’], order=(2, 1, 4),seasonal_order=(0,1,1,7)).fit()
    y_hat_avg[‘SARIMA’] = fit1.predict(start = “2018-04-03”, end = “2018-06-08”, dynamic=True)
    plt.plot(train1[‘Adj Close’], label=‘Train’)
    plt.plot(test[‘Adj Close’], label=‘Test’)
    plt.plot(y_hat_avg[‘SARIMA’], label=‘SARIMA’)

KeyError: 'Thestartargument could not be matched to a location related to the index of the data.'

Please have a look at this and let me know how to solve this error.



Hi @vatsy61,

It seems like the start date is not correct. Either the format of the date is not correct or you have to change the start date. Can you please share your dataset so that i can look into it and help you in a better way?


Hi @vatsy61,

If you have trained your model on the hourly data, you start and end date should be in the form 2014-09-26 00:00:00 and 2015-04-26 23:00:00


Hi PulkitS,

Thanks for the prompt reply. I tried with the format but still it did not work.
Attached here is the data set.

MS.zip (24.5 KB)


Hi AishwaryaSingh,

Thanks for the prompt reply, but the thing is that I am not training my model on an hourly basis but rather I am training it on a daily basis, still it is erroring out.
Attached is the dataset

MS.zip (24.5 KB)


Thank you for sharing the file. I will work on it and update you with the same.


Thanks a lot!
Another question though, is there any way where I can predict the future prices like ahead of the dataset (say for example. my data set is till 8/2018. So, I wanna predict/forecast for the month of 9/2018) using the techniques that are mentioned in the link above.?
If there is anything let me know.


Yes you can predict future values. You can use predict function and mention the start and end dates.



If you can show me a sample in the notebook that would be great.



Hello I am facing the same error:
“KeyError: ‘The start argument could not be matched to a location related to the index of the data.’”
Were you able to solve this issue? @vatsy61


Not yet! Are you able to solve?



Any updates?



Hi, for the start and end dates, you don’t need to provide them in the string or datetime format,
If you trained your model on 1000 records, and want to predict next 200 records. Then use:
start = 999, end=1200
start = 1000, end=1200
or start = 1001, end = 1200

Check whatever works for you!


Thanks @srafay
It worked! Appreciate the help!



I find out that if the start and end time period does not overlap with your training index( series you used to fit model), then it works just fine. I personally input only end date without start date to avoid such problem. If you can calculate intervals like @srafay , you can also start with 0 predict(start = 0, end = intervals).


Hi @xueswang
Thanks! Appreciate it!


I was having the same problem, so, just to share my solution: I have realised that I was trining and makint the predictions with the column dates not beying seted to an index. So I seted the dates on the test and train set, and it worked perfectly with the dates string on the start and end parameters in the prediction =].