Skip to content

Instantly share code, notes, and snippets.

View khakieconomics's full-sized avatar

Jim khakieconomics

View GitHub Profile
# In this demonstration, I estimate a discrete-time NGARCH model.
# I first simulate the model with known parameters, then try to
# recover the parameters from simulated data. Then I apply the
# model to weekly returns for Google.
# The model seems to be able to recover most of the parameters
# fairly well, with inference for alpha, beta fairly week. gamma
# does not seem to be well identified.
# jim savage, [email protected]
library(MASS); library(rstan)
# Sample size
N <- 5000
# Generate two uncorrelated covariates (means 1 and 5, both with standard deviations of 1)
X <- mvrnorm(N, c(1, 5), matrix(c(1, 0, 0, 1), 2, 2))
plot(X)
# Loadings matrix
Gamma <- matrix(c(0.5, 1,
# Generate fake data
dgp <- "data {
int<lower=1> N;
real x[N];
real rho;
real sigma;
}
transformed data {
vector[N] mu;
# Some fake data
library(dplyr); library(rstan)
# Write out the data generation with known parameters
# Set the number of individuals
n_ind <- 50
library(readr); library(dplyr); library(lubridate)
dat_2 <- read_csv("Datathon WC Data Games 11-20.csv")
glimpse(dat_2)
dat_3 <- read_csv("Datathon WC Data Games 21-30.csv")
as_datetime <- function(x){
library(KFAS)
library(rstan)
data(GlobalTemp)
model_dlm1a <- stan_model("../stan/dlm1a.stan")
y <- as.matrix(GlobalTemp)
data <-
within(list(),
{