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

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

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

Keyword: AGARCH, 非対称, 実現値

概要

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

AGARCH type2のデータ 

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

出力結果

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

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


  Realization Number 1
    I            HT(I)            ET(I)
   --------------------------------------
     1           0.6400           0.2790
     2           0.5336          -0.9098
     3           0.7780           0.5840
     4           0.6491           0.6731
     5           0.5670          -0.9456
     6           0.8275          -0.0172
     7           0.6593          -0.2390
     8           0.5639           0.5980
     9           0.5005          -0.0032
    10           0.4303           0.2917

  Realization Number 2
    I            HT(I)            ET(I)
   --------------------------------------
     1           0.3874          -1.0205
     2           0.7594          -0.5659
     3           0.7371           0.2709
     4           0.6013          -1.2499
     5           1.1133           0.2505
     6           0.8638          -0.5457
     7           0.8014          -0.6395
     8           0.8013           2.2341
     9           1.0003           1.2908
    10           0.9002           0.0727

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

ソースコード

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

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


このソースコードをダウンロード
/* nag_rand_agarchII (g05pec) 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.08e0, 0.2e0, 0.7e0 };
  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_agarchII (g05pec) 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_agarchII(dist, num, ip, iq, theta, gamma, df, ht, et, fcall, r,
                    lr, state, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_rand_agarchII (g05pec).\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_agarchII(dist, num, ip, iq, theta, gamma, df, ht, et, fcall, r,
                    lr, state, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_rand_agarchII (g05pec).\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