EGARCHプロセスの時系列の実現値の生成

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

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

Keyword: EGARCH, 実現値

概要

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

EGARCHのデータ 

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

出力結果

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

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


  Realization Number 1
    I            HT(I)            ET(I)
   --------------------------------------
     1           2.5098           0.5526
     2           2.1785          -1.8383
     3           3.3844           1.2180
     4           2.6780           1.3672
     5           2.0953          -1.8178
     6           3.2813          -0.0343
     7           2.9958          -0.5094
     8           3.0815           1.3978
     9           2.3961          -0.0070
    10           2.2445           0.6661

  Realization Number 2
    I            HT(I)            ET(I)
   --------------------------------------
     1           1.9327          -2.2795
     2           3.5577          -1.2249
     3           4.1461           0.6424
     4           3.4455          -2.9920
     5           5.9199           0.5777
     6           4.8221          -1.2894
     7           5.3174          -1.6473
     8           6.1095           6.1689
     9           3.1579           2.2935
    10           2.2189           0.1141

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

ソースコード

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

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


このソースコードをダウンロード
/* nag_rand_egarch (g05pgc) 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.1e0, -0.3e0, 0.1e0, 0.9e0 };

  /* 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_egarch (g05pgc) 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 * (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_egarch(dist, num, ip, iq, theta, df, ht, et, fcall, r, lr,
                  state, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_rand_egarch (g05pgc).\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_egarch(dist, num, ip, iq, theta, df, ht, et, fcall, r, lr,
                  state, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_rand_egarch (g05pgc).\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