Skip to content

Add stochastic volatility model from Hoffman & Gelman 2014#326

Open
colinpochart2 wants to merge 16 commits into
stan-dev:developmentfrom
colinpochart2:add-stochastic-volatility
Open

Add stochastic volatility model from Hoffman & Gelman 2014#326
colinpochart2 wants to merge 16 commits into
stan-dev:developmentfrom
colinpochart2:add-stochastic-volatility

Conversation

@colinpochart2

Copy link
Copy Markdown

Adds the stochastic volatility model from Hoffman & Gelman (2014, NUTS paper).

  • Dataset: S&P 500 daily prices, T=3000 (faithful to the paper)
  • Model: centered parameterization (Stan)
  • Includes raw price cache CSV for full reproducibility

PS: reference posterior draws are not yet included - the HMC run is computationally demanding. Happy to follow
maintainer guidance on the sampling configuration.

@MansMeg

MansMeg commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Excellent! @JTorgander could you do a review?

@JTorgander JTorgander left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basic model structure looks fine but some changes related to formatting and data dimension are needed. See comments below.

}

// Term from marginalizing out tau analytically:
// target += -((T + 1) / 2.0) * log(0.01 + 0.5 * sum((log s_i - log s_{i-1})^2))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed

Comment on lines +1 to +4
functions {

}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block can be removed

target += -0.01 * s[1];

// Likelihood: (log y_i - log y_{i-1}) / s_i ~ t_nu
// Add -log(s_i) for each term because of the Jacobian of standardization.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this happening in the code?

}

transformed data {
vector[T-1] log_returns; // log y_i - log y_{i-1} for i = 2, ..., T

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment can be removed.

Comment thread .gitignore

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to include information about the data source, time range etc

Comment thread posterior_database/data/info/stochastic_volatility.info.json Outdated
"name": "stochastic_volatility",
"keywords": ["time_series", "stochastic_volatility", "marginalized"],
"title": "Stochastic Volatility Model with Marginalized Precision",
"description": "Stochastic volatility model from Hoffman & Gelman (2014, NUTS paper, p. 1614-1615). Daily log-returns follow a Student-t distribution with time-varying scale s_i. The log-scale follows a Gaussian random walk with precision tau, which is marginalized analytically. Resulting posterior is (T+1)-dimensional over (s, nu).",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"description": "Stochastic volatility model from Hoffman & Gelman (2014, NUTS paper, p. 1614-1615). Daily log-returns follow a Student-t distribution with time-varying scale s_i. The log-scale follows a Gaussian random walk with precision tau, which is marginalized analytically. Resulting posterior is (T+1)-dimensional over (s, nu).",
"description": "Stochastic volatility model from Hoffman & Gelman (2014, NUTS paper, p. 1614-1615). Daily log-returns follow a Student-t distribution with time-varying scale s_i. The log-scale follows a Gaussian random walk with precision tau, which is marginalized analytically. Resulting posterior is T-dimensional over (s, nu), where T is the number of data points.",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a bit confusing to the user that the raw data has 3021 data points whereas the json data file 3000.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes more sense to store this data under the name sp500_[time-range]_T and then name the posterior sp500_[time-range]_T-stochastic_...

colinpochart2 and others added 2 commits June 8, 2026 16:15
Co-authored-by: JTorgander <55882444+JTorgander@users.noreply.github.com>
- info.json: posterior is T-dimensional over (s, nu), not (T+1)
- stochastic_volatility.stan: remove empty functions block and stale comments
@colinpochart2 colinpochart2 force-pushed the add-stochastic-volatility branch from fba05bd to bac96c0 Compare June 8, 2026 15:33
colinpochart2 and others added 7 commits June 10, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants