Skip to content

Commit 34217ec

Browse files
author
Ben Goodrich
committed
fix stochastic volatility examples
1 parent 3e170c6 commit 34217ec

File tree

6 files changed

+50
-19
lines changed

6 files changed

+50
-19
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ y[1] <- err[1] + mu + phi * mu;
1212
for (t in 2:T)
1313
y[t] <- err[t] + (mu + phi * y[t-1] + theta * err[t-1]);
1414

15-
library('rstan')
15+
#library('rstan')
1616
# fit <- stan('arma11.stan', data=list(T=T, y=y), iter=2000, chains=4);

misc/moving-avg/arma11_alt.data.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
mu <- -1.25;
2+
sigma <- 0.75;
3+
theta <- 0.5;
4+
phi <- 0.2;
5+
6+
T <- 1000;
7+
8+
err <- rnorm(T,0,sigma);
9+
nu <- rep(0,T);
10+
y <- rep(0,T);
11+
y[1] <- err[1] + mu + phi * mu;
12+
for (t in 2:T)
13+
y[t] <- err[t] + (mu + phi * y[t-1] + theta * err[t-1]);
14+
15+
#library('rstan')
16+
# fit <- stan('arma11.stan', data=list(T=T, y=y), iter=2000, chains=4);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ for (t in 3:T) {
2020
epsilon[t] <- y[t] - predictor;
2121
}
2222

23-
library('rstan')
23+
#library('rstan')
2424
# fit <- stan('ma2.stan', data=list(T=T, y=y), iter=500, chains=2, init=0);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
phi <- 0.95;
3+
sigma <- 0.25;
4+
beta <- 0.6;
5+
mu <- 2 * log(beta);
6+
7+
T <- 500;
8+
9+
h <- rep(NA,T);
10+
h[1] <- rnorm(1, mu, sigma / sqrt(1 - phi * phi));
11+
for (t in 2:T)
12+
h[t] <- rnorm(1, mu + phi * (h[t-1] - mu), sigma);
13+
y <- rep(NA,T);
14+
for (t in 1:T)
15+
y[t] <- rnorm(1, 0, exp(h[t] / 2));
Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
2-
phi <- 0.95;
3-
sigma <- 0.25;
4-
beta <- 0.6;
5-
mu <- 2 * log(beta);
6-
7-
T <- 500;
8-
9-
h <- rep(NA,T);
10-
h[1] <- rnorm(1, mu, sigma / sqrt(1 - phi * phi));
11-
for (t in 2:T)
12-
h[t] <- rnorm(1, mu + phi * (h[t-1] - mu), sigma);
13-
y <- rep(NA,T);
14-
for (t in 1:T)
15-
y[t] <- rnorm(1, 0, exp(h[t] / 2));
16-
1+
source("stochastic-volatility.data.R")
172
library("rstan");
183
start_time <- proc.time();
19-
fit <- stan(file="stochastic-volatility.stan", data=list(T=T,y=y), iter=10000, chains=4, init=0, fit=fit);
4+
fit <- stan(file="stochastic-volatility.stan", data=list(T=T,y=y), iter=10000, chains=4, init=0);
205
elapsed_time <- proc.time() - start_time;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
phi <- 0.95;
3+
sigma <- 0.25;
4+
beta <- 0.6;
5+
mu <- 2 * log(beta);
6+
7+
T <- 500;
8+
9+
h <- rep(NA,T);
10+
h[1] <- rnorm(1, mu, sigma / sqrt(1 - phi * phi));
11+
for (t in 2:T)
12+
h[t] <- rnorm(1, mu + phi * (h[t-1] - mu), sigma);
13+
y <- rep(NA,T);
14+
for (t in 1:T)
15+
y[t] <- rnorm(1, 0, exp(h[t] / 2));

0 commit comments

Comments
 (0)