Keyword: ARMA, 時系列, 実現値
概要
本サンプルはARMAモデルの時系列の実現値の生成を行うC#によるサンプルプログラムです。 本サンプルは以下の式で示されるARMAモデルに対して10個の観測値を生成し出力します。
※本サンプルはnAG Library for .NETに含まれる関数 g05ph() のExampleコードです。本サンプル及び関数の詳細情報は g05ph のマニュアルページをご参照ください。
出力結果
| この出力例をダウンロード |
g05ph Example Program Results
-1.7103
-0.4042
-0.1845
-1.5004
-1.1946
-1.8184
-1.0895
1.6408
1.3555
1.1908
- 3〜12行目に生成された10個の観測値が出力されています。
ソースコード
※本サンプルソースコードは .NET環境用の科学技術・統計計算ライブラリである「nAG Library for .NET」の関数を呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
// g05ph Example Program Text
// C# version, nAG Copyright 2008
using System;
using NagLibrary;
using System.IO;
namespace NagDotNetExamples
{
public class G05PHE
{
static void Main(String[] args)
{
StartExample();
}
public static void StartExample()
{
try
{
const int ip=2;
const int iq=0;
const int n=10;
const int mseed=1;
double avar, var, xmean; int genid, i, subid;
double[] phi = new double[ip];
double[] r = new double[ip+iq+6+ip];
double[] theta = new double[iq];
double[] x = new double[n];
int[] seed = new int[mseed];
int ifail;
Console.WriteLine("g05ph Example Program Results");
Console.WriteLine("");
// Set the ARMA model parameters
xmean = 0.00e0;
phi[0] = 0.40e0;
phi[1] = 0.20e0;
avar = 1.00e0;
// 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 L40;
}
// Set up the reference vector and generate the N realisations
// Choose mode = 2
G05.g05ph(2, n, xmean, ip, phi,iq,theta, avar,r, g05State, out var, x, out ifail);
if (ifail != 0)
{
Console.WriteLine("** g05ph failed with ifail = {0,5}", ifail);
goto L40;
}
// Display the variates
for (i = 1 ; i <= n ; i++)
{
Console.WriteLine(" {0,12:f4}",x[i - 1]);
}
//
L40: ;
//
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine( "Exception Raised");
}
}
}
}
