This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # 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] | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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, | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Generate fake data | |
| dgp <- "data { | |
| int<lower=1> N; | |
| real x[N]; | |
| real rho; | |
| real sigma; | |
| } | |
| transformed data { | |
| vector[N] mu; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Some fake data | |
| library(dplyr); library(rstan) | |
| # Write out the data generation with known parameters | |
| # Set the number of individuals | |
| n_ind <- 50 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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){ | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | library(KFAS) | |
| library(rstan) | |
| data(GlobalTemp) | |
| model_dlm1a <- stan_model("../stan/dlm1a.stan") | |
| y <- as.matrix(GlobalTemp) | |
| data <- | |
| within(list(), | |
| { | 
NewerOlder