q1 = np.asmatrix([ [-0., 0.], [0., -0.], ]) p = [p1]#, p2] #, p3] q = [q1]#q1] # y0 = np.asmatrix([[0., 0., 0.]]).T #, [0., 0., 0.] X = sim.varmapqGaussian(t = t, pMatrix = p, qMatrix = q)#, y0 = y0) y = VARMAX(X.T, order = (1,1)).fit() print(y.summary()) x1 = np.asarray(X[0,:]).reshape(t) x2 = np.asarray(X[1,:]).reshape(t) # x3 = np.asarray(X[2,:]).reshape(t) # nprocess = X.shape[0] pLag = len(p) qLag = len(q) # params = logL.maxVARMApqN(X, pLag, qLag) print(params)
df_transformed = df.diff().diff() df_transformed = df_transformed.dropna() # fourth, split data set # ---------- nobs = 12 #number of observations for the test set train = df_transformed.iloc[: -nobs] #start = beginning of dataframe, or 0, to -12 from the end test = df_transformed.iloc[-nobs:] #start at -12 from the end to go to the end #fifth, fit the VARMA model # ---------- # VARMAX needs as input the suggested p and q (no d) and a trend c which is the standard = linear trend # fit requires both maxiter and disp, where disp is display=False => display less information model = VARMAX(train, order=(1, 2), trend='c').fit(maxiter=500, disp=False) print(model.summary()) #sixth, run a prediction vs test set # ---------- df_forecast = model.forecast(nobs) # sixth-bis, reverse the differencing to make values turn normal and understandable # ---------- # we transform the differences by taking the cumulative sum of a column and adding it to a one line difference to revert it df_forecast['Money_diff1x'] = ( df['Money'].iloc[-nobs - 1] - df['Money'].iloc[-nobs - 2]) + df_forecast['Money_diff2x'].cumsum() df_forecast['Money_Fcst'] = df['Money'].iloc[ -nobs - 1] + df_forecast['Money_diff1x'].cumsum() df_forecast['Spending_diff1x'] = (