Ljung-Box test on a out of sample residue with good forecast

To test the fbprophet library, I created a very simple synthetic series and generated a model like this:

import statsmodels.api as sm
from fbprophet import Prophet
import pandas as pd
import numpy as np

idx = pd.date_range('2016-01-01', '2016-05-04', freq='D')
phase = np.pi / 2
len_idx = len(idx)
points = np.arange(0, len_idx)
df = pd.DataFrame({'y': np.sin(points * 2 * np.pi / 30 + phase) + points / 100}, index=idx)
df['ds'] = df.index

mdl = Prophet()
df_result = mdl.predict(30, 'D')
_ = mdl.model.plot(df_result)


what looks like a very good fit and forecast. I'm now trying to evaluate the forecast using the Ljung-Box statistic:

df_train = df.iloc[:100]
df_test = df.iloc[100:]
mdl = Prophet()
df_forecast = mdl.predict(df_test)
df_forecast.index = df_forecast.ds
residue = df_test.y - df_forecast.yhat
nlags = 20
sm.stats.diagnostic.acorr_ljungbox(residue, nlags)
(array([26.58531982, 37.54004325, 39.75143298, 39.87513462, 39.87724859,
39.87823833, 39.87841515]),
array([2.52152459e-07, 7.05152716e-09, 1.20293579e-08, 4.59357440e-08,
1.58094709e-07, 4.81312117e-07, 1.32806258e-06]))


and I get very small values for the p-value, meaning that the null hypothesis cannot be rejected (if I understood the test correctly), so there is still autocorrelated values in the forecast residue. What is the probable cause of this? The residues for this model look like

• Either a deficient model or a deterministic time series – IrishStat Sep 8 at 8:45
• Sorry, I didn't get that. How a deterministic time series would generate a Ljung-Box test with small p-values? – Ivan Sep 14 at 12:35

• The OP doesn't use R either: this is Python code. The code and the plot look like enough information to generate the data using any language you like--how about Fortran? :-) – whuber Sep 14 at 20:01