stochvolTMB
Likelihood estimation of stochastic volatility models
Science Score: 23.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
✓Academic publication links
Links to: zenodo.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (16.8%) to scientific vocabulary
Last synced: 11 months ago
·
JSON representation
Repository
Likelihood estimation of stochastic volatility models
Basic Info
Statistics
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 1
- Releases: 3
Created over 7 years ago
· Last pushed over 1 year ago
Metadata Files
Readme
Changelog
License
README.Rmd
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# stochvolTMB
[](https://cran.r-project.org/package=stochvolTMB)
[](https://r-pkg.org/pkg/stochvolTMB)
[](https://github.com/JensWahl/stochvolTMB/actions)
[](https://www.gnu.org/licenses/gpl-3.0)
[](https://lifecycle.r-lib.org/articles/stages.html)
[](https://zenodo.org/badge/latestdoi/162462958)
`stochvolTMB` is a package for fitting stochastic volatility (SV) models to time series data. It is inspired by the package [stochvol](https://github.com/gregorkastner/stochvol), but parameter estimates are obtained through optimization and not MCMC, leading to significant speed up. It is built on [Template Model Builder](https://github.com/kaskr/adcomp) for fast and efficient estimation. The latent volatility is integrated out of the likelihood using the Laplace approximation and automatic differentiation (AD) is used for accurate evaluation of derivatives.
Four distributions for the observational error are implemented:
* **Gaussian** - The classic SV model with Gaussian noise
* **t** - t-distributed noise for heavy tail returns
* **Leverage** - Extending the **Gaussian** model by allowing observed returns to be correlated with the latent volatility
* **Skew-Gaussian** - Skew-Gaussian distributed noise for asymmetric returns
## Installation
To install the current stable release from CRAN, use
```{r eval = FALSE}
install.packages("stochvolTMB")
```
To install the current development version, use
``` {r eval = FALSE}
# install.packages("remotes")
remotes::install_github("JensWahl/stochvolTMB")
```
If you would also like to build and view the vignette locally, use
```{r, eval = FALSE}
remotes::install_github("JensWahl/stochvolTMB", dependencies = TRUE, build_vignettes = TRUE)
```
## Example
The main function for estimating parameters is `estimate_parameters`:
```{r example}
library(stochvolTMB, warn.conflicts = FALSE)
# load s&p500 data from 2005 to 2018
data(spy)
# find the best model using AIC
gaussian <- estimate_parameters(spy$log_return, model = "gaussian", silent = TRUE)
t_dist <- estimate_parameters(spy$log_return, model = "t", silent = TRUE)
skew_gaussian <- estimate_parameters(spy$log_return, model = "skew_gaussian", silent = TRUE)
leverage <- estimate_parameters(spy$log_return, model = "leverage", silent = TRUE)
# the leverage model stands out with an AIC far below the other models
AIC(gaussian, t_dist, skew_gaussian, leverage)
# get parameter estimates with standard error
estimates <- summary(leverage)
head(estimates, 10)
# plot estimated volatility with 95 % confidence interval
plot(leverage, include_ci = TRUE, dates = spy$date)
```
Given the estimated parameters we can simulate future volatility and log-returns using `predict`.
```{r}
set.seed(123)
# simulate future prices with or without parameter uncertainty
pred = predict(leverage, steps = 10)
# Calculate the mean, 2.5% and 97.5% quantiles from the simulations
pred_summary = summary(pred, quantiles = c(0.025, 0.975), predict_mean = TRUE)
print(pred_summary)
# plot predicted volatility with 0.025 and 0.975 quantiles
plot(leverage, include_ci = TRUE, forecast = 50, dates = spy$d) +
ggplot2::xlim(c(spy[.N, date] - 150, spy[.N, date] + 50))
```
## Shiny app
By running `demo()` you start a shiny application where you can visually inspect the effect of choosing different models and parameter configurations
```{r eval = FALSE}
demo()
```

Owner
- Name: Jens Christian Wahl
- Login: JensWahl
- Kind: user
- Location: Oslo
- Company: @NorskRegnesentral
- Repositories: 1
- Profile: https://github.com/JensWahl
GitHub Events
Total
- Release event: 1
- Push event: 8
- Pull request event: 2
- Create event: 2
Last Year
- Release event: 1
- Push event: 8
- Pull request event: 2
- Create event: 2
Committers
Last synced: over 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| JensWahl | j****l@n****o | 98 |
| JensWahl | j****l@g****m | 52 |
| JensWahl | J****l@s****o | 7 |
| Jens Christian Wahl | j****w@a****o | 4 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 1
- Total pull requests: 8
- Average time to close issues: N/A
- Average time to close pull requests: 24 days
- Total issue authors: 1
- Total pull request authors: 1
- Average comments per issue: 0.0
- Average comments per pull request: 0.0
- Merged pull requests: 7
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 2
- Average time to close issues: N/A
- Average time to close pull requests: 21 minutes
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- waynelapierre (1)
Pull Request Authors
- JensWahl (8)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 208 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 5
- Total maintainers: 1
cran.r-project.org: stochvolTMB
Likelihood Estimation of Stochastic Volatility Models
- Homepage: https://github.com/JensWahl/stochvolTMB
- Documentation: http://cran.r-project.org/web/packages/stochvolTMB/stochvolTMB.pdf
- License: GPL-3
-
Latest release: 0.3.0
published over 1 year ago
Rankings
Stargazers count: 18.7%
Forks count: 21.9%
Dependent packages count: 29.8%
Average: 32.0%
Dependent repos count: 35.5%
Downloads: 54.1%
Maintainers (1)
Last synced:
11 months ago
Dependencies
DESCRIPTION
cran
- R >= 3.5.0 depends
- MASS * imports
- TMB * imports
- data.table * imports
- ggplot2 * imports
- sn * imports
- stats * imports
- knitr * suggests
- rmarkdown * suggests
- shiny * suggests
- stochvol * suggests
- testthat >= 2.1.0 suggests
.github/workflows/R-CMD-check.yaml
actions
- actions/cache v4 composite
- actions/checkout v4 composite
- actions/upload-artifact main composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
.github/workflows/rhub.yaml
actions
- r-hub/actions/checkout v1 composite
- r-hub/actions/platform-info v1 composite
- r-hub/actions/run-check v1 composite
- r-hub/actions/setup v1 composite
- r-hub/actions/setup-deps v1 composite
- r-hub/actions/setup-r v1 composite