Home 21090308 Forums Numerical Method Statistics Question about VARMA forecast

• This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
• Author
Posts
• #2666
ozcanalp
Member

Hi,

I have an example for a bivariate series with n=2, p=2, and q=0 and i wanna estimate N+1. value by fitting an VARMA model.
I’ve used suanshu.net-2.6.0 for the below code.
I’ve fitted a model but i got an exception on this line
instance = new VARMAForecastOneStep(X_T, varmaModel);
and i don’t know how to estimate the next term. I’m new with Suanshu and any help or advise will be appreciated.

Exception :

at com.numericalmethod.suanshu.misc.ArgumentAssertion.assertTrue(Boolean condition, String errorMessage, Object[] args)
at com.numericalmethod.suanshu.stats.timeseries.linear.multivariate.stationaryprocess.arma.VARMAAutoCovariance..ctor(VARMAModel model, Int32 nLags)
at com.numericalmethod.suanshu.stats.timeseries.linear.multivariate.stationaryprocess.arma.VARMAForecastOneStep..ctor(MultivariateIntTimeTimeSeries Xt, VARMAModel model)

code:
X_T = new MultivariateSimpleTimeSeries(
new double[][]{
new double[]{1, 50},
new double[]{2, 60},
new double[]{3, 70},
new double[]{4, 80},
new double[]{5, 90},
new double[]{6, 100},
new double[]{7, 110},
new double[]{8, 120},
new double[]{9, 130},
new double[]{10, 140},
new double[]{11, 150},
new double[]{12, 160},
new double[]{13, 170},
new double[]{14, 180},
new double[]{15, 190},
new double[]{16, 200},
new double[]{17, 210},
new double[]{18, 220},
new double[]{19, 230},
new double[]{20, 240}

});

VARFitting fitting = new VARFitting(X_T, 2);

VARMAModel varmaModel = fitting.getVARMA();
VARMAForecastOneStep instance = null;
try
{
instance = new VARMAForecastOneStep(X_T, varmaModel);
int T = X_T.size();
Vector xTHat = instance.xHat(T + 1);
Matrix V = instance.covariance(T);
Console.Write(“Predictor at time ” + T + “: ” + xTHat + “, covariance of errors: ” + V);
Console.Write(“\n”);
}catch(Exception e){
Console.WriteLine(“\nStackTrace —\n{0}”, e.StackTrace);
}

#2668
hao.ding
Member

Hi ozcanalp,

The model that is passed to VARMAForecastOneStep should be a zero mean model. You can get the demeaned model easily by (following your code): varmaModel.getDemeanedModel(). Therefore, changing
“instance = new VARMAForecastOneStep(X_T, varmaModel);”
to
“instance = new VARMAForecastOneStep(X_T, varmaModel.getDemeanedModel());”

should solve your problem. And finally add the mean back to get the forecast of the original VARMA model.

Please let me know if there is anything else I can help.

Best wishes,
Ding Hao

#2671
ozcanalp
Member

Thank you very much Ding Hao,

I have one more question about “public VARFitting(MultivariateIntTimeTimeSeries mts,int p)”. How can I estimate p value by using akaike information criterion. For example if I used ARIMA model below code is ok for me. But how can I estimate p value for VARMA model by using akaike information criterion?

Best wishes,
ozcanalp

double[] inputNumbers = new double[] { 2, 3, 4 };
int P_VALUE = 2;
int D_VALUE = 1;
int Q_VALUE = 3;

int p = P_VALUE;
int d = D_VALUE;
int q = Q_VALUE;

ARIMAModel arima = null;

double maxAic = 0;
double actualAic = 0;
int maxp = 10;
int maxd = 10;
int maxq = 10;

ConditionalSumOfSquares csos = new ConditionalSumOfSquares(inputTimeSeries, p, d, q);

for(int ii=0;ii<=3;ii++){ for(int jj=0;jj<=2;jj++){ for(int kk=0;kk maxAic){ maxAic = actualAic; maxp = p; maxd = d; maxq = q; csos = new ConditionalSumOfSquares(inputTimeSeries, p, d, q); } } } } Console.Write("\n"); Console.Write("maxp: " + maxp + "," + maxd + "," + maxq); Console.Write("\n"); arima = csos.getModel(); IntTimeTimeSeries xt = new SimpleTimeSeries(inputTimeSeries); ARIMAForecast instance = new ARIMAForecast(xt, arima); ARIMAForecast.Forecast frc = instance.next(); double next = frc.xHat(); double err = frc.var();

#2672
hao.ding
Member

Hi ozcanalp,

for the AIC of VARMA model, please see p388 of the paper here.

Basically speaking AIC can be computed as the norm of covariance matrix of VARMA residuals plus a penalty of order p, number of variables n, and length T.

#2674
ozcanalp
Member

Thank you very much Ding Hao,

I want to perform pairwise Granger causality wald tests after VAR but I can’t find any function for The Granger causality test F statistics in the suanshu package.How can I determine the first
series does not case the second series or the second series does not cause the first series by using Granger causality test. Can you help me ?

Best wishes,

ozcanalp

#2675
hao.ding
Member

Hi ozcanalp,

For the Granger causality test, here is an interesting article. It describes procedure step by step. Hope this helps.

#2929
ozcanalp
Member

Thank you very much Ding Hao,

When I’ve fitted a model, i got an {“no solution to this system of linear equations”} exception on this line “VARFitting fitting = new VARFitting(X_T, 2);”. How can I fit the model? My code and exception are given below.
any help or advise will be appreciated.

code:

X_T = new MultivariateSimpleTimeSeries(
new double[][]{
new double[]{0, 0},
new double[]{0, 0.008},
new double[]{0, 0.269},
new double[]{0, 0.008},
new double[]{0, 0.009},
new double[]{0, 0.002},
new double[]{0, 0.005},
new double[]{0, 0.009},
new double[]{0.005, 0.008},
new double[]{0.006, 0.003}

});

try
{
VARFitting fitting = new VARFitting(X_T, 2);

VARMAModel varmaModel = fitting.getVARMA();
VARMAForecastOneStep instance = null;

instance = new VARMAForecastOneStep(X_T, varmaModel.getDemeanedModel());
int T = X_T.size();
Vector xTHat = instance.xHat(T + 1);
Matrix V = instance.covariance(T);
Console.Write(“Predictor at time ” + (T+1) + “: ” + xTHat + “, covariance of errors: ” + V);
Console.Write(“\n”);
}catch(Exception e){

Console.WriteLine(“\nStackTrace —\n{0}”, e.StackTrace);

}

Exception :

at com.numericalmethod.suanshu.algebra.linear.matrix.doubles.linearsystem.BackwardSubstitution.new(UpperTriangularMatrix , Vector , Double )
at com.numericalmethod.suanshu.algebra.linear.matrix.doubles.linearsystem.BackwardSubstitution.solve(UpperTriangularMatrix U, Vector b, Double epsilon)
at com.numericalmethod.suanshu.algebra.linear.matrix.doubles.linearsystem.OLSSolverByQR.solve(LSProblem problem)
at com.numericalmethod.suanshu.stats.regression.linear.ols.OLSRegression..ctor(LMProblem problem, Double epsilon)
at com.numericalmethod.suanshu.stats.regression.linear.ols.OLSRegression..ctor(LMProblem problem)
at com.numericalmethod.suanshu.stats.timeseries.linear.multivariate.stationaryprocess.arma.VARFitting.new(MultivariateIntTimeTimeSeries , Int32 )
at com.numericalmethod.suanshu.stats.timeseries.linear.multivariate.stationaryprocess.arma.VARFitting.true(MultivariateIntTimeTimeSeries , Int32 )
at com.numericalmethod.suanshu.stats.timeseries.linear.multivariate.stationaryprocess.arma.VARFitting..ctor(MultivariateIntTimeTimeSeries mts, Int32 p)
at MultivariateTimeSeries.MultiLinearTimeSeries.run() in \Visual Studio 2010\Projects\MultivariateTimeSeries\MultivariateTimeSeries\MultiLinearTimeSeries.cs:line 323

#2930
hao.ding
Member

Your data is ill-defined. For example, you have two time series, one of them is:0,0,0,0,0,0,0,0,0.005,0.006. It seems very odd to me. And it is very likely that it will cause numerical problems in computations.

Viewing 8 posts - 1 through 8 (of 8 total)
• You must be logged in to reply to this topic.