/*
* gretl -- Gnu Regression, Econometrics and Time-series Library
* Copyright (C) 2001 Allin Cottrell and Riccardo "Jack" Lucchetti
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
/* Sample program to estimate an ARMA model via libgretl and
produce a few forecast values */
#include
#include
int main (void)
{
libgretl_init();
PRN *prn = gretl_print_new(GRETL_PRINT_STDOUT, NULL);
int err, i;
int size = 11;
int interStart = 4;
int interEnd = 6;
double data[] = {0, 0.1, 0.2, 0.3, 0, 0, 0, 0.3, 0.2, 0.1, 0};
double lags[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
DATASET *gretlData = create_new_dataset(3, size, 0);
for(i = 0; i < size; i++)
{
gretlData->Z[1][i] = data[i];
gretlData->Z[2][i] = lags[i];
}
int *list = gretl_list_new(7);
list[1] = 1; /* AR order */
list[2] = 0; /* order of integration */
list[3] = 0; /* MA order */
list[4] = LISTSEP; /* separator */
list[5] = 1; /* position of dependent variable in dataset */
list[6] = 0; /* add constant */
list[7] = 2; /* position of independent variable in dataset */
MODEL *model = gretl_model_new();
*model = arma(list, NULL, gretlData, OPT_C, prn);
if(model->errcode) printf("Could not estimate model.\n");
else
{
FITRESID *forecast = get_forecast(model, interStart, interEnd, 0, gretlData, OPT_NONE, &err);
if(err) printf("Could not forecast.\n");
else
{
printf("Interpolated samples: ");
for(i = interStart; i <= interEnd; ++i)
{
printf("%f\t", forecast->fitted[i]);
}
printf("\n");
free_fit_resid(forecast);
}
}
gretl_model_free(model);
destroy_dataset(gretlData);
gretl_print_destroy(prn);
libgretl_cleanup();
return 0;
}