GJR GARCHプロセスの実現値の生成

C言語によるサンプルソースコード : 使用関数名:nag_rand_garchGJR (g05pfc)

ホーム > 製品 > nAG数値計算ライブラリ > サンプルソースコード集 > GJR GARCHプロセスの実現値の生成 (C言語/C++)

Keyword: GARCH, GJR, 実現値

概要

本サンプルはGJR GARCHプロセスの実現値の生成を行うC言語によるサンプルプログラムです。 本サンプルは以下の式で示されるGJR GARCHモデルにより10個の観測値から成る2つの実現値を生成し出力します。

GJR GARCHのデータ 

※本サンプルはnAG Cライブラリに含まれる関数 nag_rand_garchGJR() のExampleコードです。本サンプル及び関数の詳細情報は nag_rand_garchGJR のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで

出力結果

(本関数の詳細はnag_rand_garchGJR のマニュアルページを参照)

この出力例をダウンロード
nag_rand_garchGJR (g05pfc) Example Program Results


  Realization Number 1
    I            HT(I)            ET(I)
   --------------------------------------
     1           1.8000           0.4679
     2           1.6819          -1.6152
     3           2.0991           0.9592
     4           1.9614           1.1701
     5           1.9099          -1.7355
     6           2.3393          -0.0289
     7           2.0377          -0.4201
     8           1.8617           1.0865
     9           1.8212          -0.0061
    10           1.6749           0.5754

  Realization Number 2
    I            HT(I)            ET(I)
   --------------------------------------
     1           1.6055          -2.0776
     2           2.3872          -1.0034
     3           2.2724           0.4756
     4           2.0133          -2.2871
     5           2.8554           0.4012
     6           2.4149          -0.9125
     7           2.2570          -1.0732
     8           2.2102           3.7105
     9           3.3239           2.3530
    10           3.2804           0.1388

  • 7〜16行目に1つめの実現値の条件付き分散と観測値が出力されています。
  • 21〜30行目に2つめの実現値の条件付き分散と観測値が出力されています。

ソースコード

(本関数の詳細はnag_rand_garchGJR のマニュアルページを参照)

※本サンプルソースコードはnAG数値計算ライブラリ(Windows, Linux, MAC等に対応)の関数を呼び出します。
サンプルのコンパイル及び実行方法


このソースコードをダウンロード
/* nag_rand_garchGJR (g05pfc) Example Program.
 *
 * CLL6I261D/CLL6I261DL Version.
 *
 * Copyright 2017 Numerical Algorithms Group.
 *
 * Mark 26.1, 2017.
 */
/* Pre-processor includes */
#include <stdio.h>
#include <math.h>
#include <nag.h>
#include <nag_stdlib.h>
#include <nagg05.h>

int main(void)
{
  /* Integer scalar and array declarations */
  Integer exit_status = 0;
  Integer lr, i, lstate;
  Integer *state = 0;

  /* nAG structures */
  NagError fail;
  Nag_Boolean fcall;

  /* Double scalar and array declarations */
  double *et = 0, *ht = 0, *r = 0;

  /* Number of terms to generate */
  Integer num = 10;

  /* Normally distributed errors */
  Nag_ErrorDistn dist = Nag_NormalDistn;
  Integer df = 0;

  /* Set up the parameters for the series being generated */
  Integer ip = 1;
  Integer iq = 1;
  double theta[] = { 0.4e0, 0.1e0, 0.7e0 };
  double gamma = 0.1e0;

  /* Choose the base generator */
  Nag_BaseRNG genid = Nag_Basic;
  Integer subid = 0;

  /* Set the seed */
  Integer seed[] = { 1762543 };
  Integer lseed = 1;

  /* Initialize the error structure */
  INIT_FAIL(fail);

  printf("nag_rand_garchGJR (g05pfc) Example Program Results\n\n\n");

  /* Get the length of the state array */
  lstate = -1;
  nag_rand_init_repeatable(genid, subid, seed, lseed, state, &lstate, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_rand_init_repeatable (g05kfc).\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  /* Calculate the size of the reference vector */
  lr = 2 * (iq + ip + 2);

  /* Allocate arrays */
  if (!(et = nAG_ALLOC(num, double)) ||
      !(ht = nAG_ALLOC(num, double)) ||
      !(r = nAG_ALLOC(lr, double)) || !(state = nAG_ALLOC(lstate, Integer)))
  {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  /* Initialize the generator to a repeatable sequence */
  nag_rand_init_repeatable(genid, subid, seed, lseed, state, &lstate, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_rand_init_repeatable (g05kfc).\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  /* Generate the first realization */
  fcall = Nag_TRUE;
  nag_rand_garchGJR(dist, num, ip, iq, theta, gamma, df, ht, et, fcall, r,
                    lr, state, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_rand_garchGJR (g05pfc).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }

  /* Display the results */
  printf("  Realization Number 1\n");
  printf("    I            HT(I)            ET(I)\n");
  printf("   --------------------------------------\n");
  for (i = 0; i < num; i++)
    printf(" %5ld %16.4f %16.4f\n", i + 1, ht[i], et[i]);
  printf("\n");

  /* Generate a second realization */
  fcall = Nag_FALSE;
  nag_rand_garchGJR(dist, num, ip, iq, theta, gamma, df, ht, et,
                    fcall, r, lr, state, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_rand_garchGJR (g05pfc).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }

  /* Display the results */
  printf("  Realization Number 2\n");
  printf("    I            HT(I)            ET(I)\n");
  printf("   --------------------------------------\n");
  for (i = 0; i < num; i++)
    printf(" %5ld %16.4f %16.4f\n", i + 1, ht[i], et[i]);

END:
  nAG_FREE(et);
  nAG_FREE(ht);
  nAG_FREE(r);
  nAG_FREE(state);

  return exit_status;
}


関連情報
Privacy Policy  /  Trademarks