Keyword: GARCH, GJR, 実現値
概要
本サンプルはGJR GARCHプロセスの実現値の生成を行うC#によるサンプルプログラムです。 本サンプルは以下の式で示されるGJR GARCHモデルにより10個の観測値から成る2つの実現値を生成し出力します。
※本サンプルはnAG Library for .NETに含まれる関数 g05pf() のExampleコードです。本サンプル及び関数の詳細情報は g05pf のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
出力結果
(本関数の詳細はg05pf のマニュアルページを参照)| この出力例をダウンロード |
g05pf Example Program Results
Realisation 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
Realisation 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つめの実現値の条件付き分散と観測値が出力されています。
ソースコード
(本関数の詳細はg05pf のマニュアルページを参照)
※本サンプルソースコードは .NET環境用の科学技術・統計計算ライブラリである「nAG Library for .NET」の関数を呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
// g05pf Example Program Text
// C# version, nAG Copyright 2008
using System;
using NagLibrary;
using System.IO;
namespace NagDotNetExamples
{
public class G05PFE
{
static void Main(String[] args)
{
StartExample();
}
public static void StartExample()
{
try
{
const int mseed=1;
const int num=10;
const int ip=1;
const int iq=1;
double gamma=0.0;
int df, genid, i, subid;
bool fcall=false;
string dist="";
double[] et = new double[num];
double[] ht = new double[num];
double[] r = new double[2*(iq+ip+2)];
double[] theta = new double[ip+iq+1];
int[] seed = new int[mseed];
int ifail;
Console.WriteLine("g05pf Example Program Results");
Console.WriteLine("");
// Initialise the seed
seed[0] = 1762543;
// genid and subid identify the base generator
genid = 1;
subid = 1;
// Initialise the generator to a repeatable sequence
G05.G05State g05State = new G05.G05State(genid, subid, seed, out ifail);
if (ifail != 0)
{
Console.WriteLine("** Generator initialisation failed with ifail = {0,5}", ifail);
goto L60;
}
// Set up the parameters for the series being generated
dist = "N";
theta[0] = 0.40e0;
theta[1] = 0.10e0;
theta[2] = 0.70e0;
gamma = 0.10e0;
df = 0;
fcall = true ;
// Generate the first realisation
G05.g05pf(dist, num, ip, iq, theta, gamma, df, ht, et, fcall, r, g05State, out ifail);
if (ifail != 0)
{
Console.WriteLine("** g05pf failed with ifail = {0,5}", ifail);
goto L60;
}
// Display the results
Console.WriteLine("");
Console.WriteLine(" {0}"," Realisation Number 1");
Console.WriteLine(" {0}"," I HT(I) ET(I)");
Console.WriteLine(" {0}"," --------------------------------------");
for (i = 1 ; i <= num ; i++)
{
Console.WriteLine(" {0,5} {1,16:f4} {2,16:f4}",i,ht[i - 1],et[i - 1]);
}
// Generate a second realisation
fcall = false ;
G05.g05pf(dist, num, ip, iq, theta, gamma, df, ht, et, fcall, r, g05State, out ifail);
if (ifail != 0)
{
Console.WriteLine("** g05pf failed with ifail = {0,5}", ifail);
goto L60;
}
// Display the results
Console.WriteLine("");
Console.WriteLine(" {0}"," Realisation Number 2");
Console.WriteLine(" {0}"," I HT(I) ET(I)");
Console.WriteLine(" {0}"," --------------------------------------");
for (i = 1 ; i <= num ; i++)
{
Console.WriteLine(" {0,5} {1,16:f4} {2,16:f4}",i,ht[i - 1],et[i - 1]);
}
//
L60: ;
//
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine( "Exception Raised");
}
}
}
}
