AGARCH type1プロセスの実現値の生成

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

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

Keyword: AGARCH, 非対称, 実現値

概要

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

AGARCH type1のデータ 

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

出力結果

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

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


  Realization Number 1
    I            HT(I)            ET(I)
   --------------------------------------
     1           0.9440           0.3389
     2           0.8502          -1.1484
     3           2.2553           0.9943
     4           1.4918           1.0204
     5           1.3413          -1.4544
     6           2.9757          -0.0326
     7           1.6386          -0.3767
     8           1.5433           0.9892
     9           1.1477          -0.0049
    10           1.0281           0.4508

  Realization Number 2
    I            HT(I)            ET(I)
   --------------------------------------
     1           0.8691          -1.5286
     2           3.0485          -1.1339
     3           2.9558           0.5424
     4           1.6547          -2.0734
     5           4.7100           0.5153
     6           2.0336          -0.8373
     7           2.3331          -1.0912
     8           2.4417           3.8999
     9           8.7473           3.8171
    10          10.4783           0.2480

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

ソースコード

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

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


このソースコードをダウンロード
/* nag_rand_agarchI (g05pdc) 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 = 0;
  Integer iq = 3;
  double theta[] = { 0.8e0, 0.6e0, 0.2e0, 0.1e0 };
  double gamma = -0.4e0;

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