Hi Perry,
thanks for the reply. Below you can see the model that I want to implement.
The code that I have so far is this:
code <- nimbleCode({
# Priors for each asset
for (i in 1:N) {
phi[i] ~ T(dnorm(0, sd=0.3), -0.99, 0.99) # Persistence factor
sigma_h[i] ~ dinvgamma(1, scale=0.5) # Std of transitory volatility
}
sv[1] <- 1 # Normalize first factor to 1
for (i in 2:N) {
sv[i] ~ dnorm(1, sd=0.5) # Scale factor for permanent component
}
sm[1] <- 1 # Normalize first factor to 1
for (i in 2:N) {
sm[i] ~ dnorm(1, sd=0.5) # Scale factor for jumps in mean
}
# Priors for constant variables
sigma_eta ~ dinvgamma(2, scale=2) # Std of permanent component
sigma_nu ~ dinvgamma(2, scale=2) # Std of jumps in mean
p_v ~ dbeta(2,5) # Probability of volatility jumps
p_m ~ dbeta(2,3) # Probability of jumps in mean
# Priors for each time step
mu[1] ~ dnorm(-10, sd=0.2) # Initial state of permanent volatility
for (t in 2:T) {
mu[t] ~ dnorm(mu[t-1], sd=delta_v[t]*sigma_eta)
}
for (t in 1:T) {
u_v[t] ~ dunif(0, 1)
u_m[t] ~ dunif(0, 1)
z_m[t] ~ dnorm(0, 1) # Standard normal innovations for jumps in mean
delta_v[t] <- step(u_v[t]-(1-p_v))
delta_m[t] <- step(u_m[t]-(1-p_m))
}
# Priors for each asset and time step
for (i in 1:N) {
h[1, i] ~ dnorm(0, sd=sigma_h[i]/sqrt(1-phi[i]*phi[i])) # Initial state of transitory volatility
for (t in 2:T) {
h[t, i] ~ dnorm(phi[i] * h[t-1,i], sd=sigma_h[i]) # Transitory component
}
}
for (i in 1:N) {
for (t in 1:T) {
gamma[t, i] <- sm[i] * delta_m[t] * sigma_nu * z_m[t] # Jump process in mean
}
}
# Loop over assets
for (i in 1:N) {
for (t in 1:T) {
y[t, i] ~ dnorm(gamma[t, i]*exp((h[t, i] + sv[i] * mu[t]) / 2), sd = exp((h[t, i] + sv[i] * mu[t]) / 2)) # Observation equation
}
}
})
The parts I am not sure about are highlighted in red. Defining mu the way I did it here does not work properly, as it prevents sigma_eta from updating over iterations. So I was wondering how to properly incorporate the Bernoulli variable delta_v into the mu equation.
Further, according to the model the Bernoulli processes are sampled using auxiliary uniform variables and take on value one if the uniform variables exceed a threshold that is aligned with the parameters p_m and p_v. Therefore, I decided to use 1-p_v and 1-p_m as thresholds but I am open for other suggestions.
Lastly the observation equation contains the conditional volatility in the mean so far, which I am not sure about. Should I only use gamma as conditional mean?
Thank you very much for any suggestions!
Best regards
JM