stochvolTMB

Likelihood estimation of stochastic volatility models

https://github.com/jenswahl/stochvoltmb

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
  • Host: GitHub
  • Owner: JensWahl
  • License: gpl-3.0
  • Language: HTML
  • Default Branch: master
  • Homepage:
  • Size: 5.12 MB
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


[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version-last-release/stochvolTMB)](https://cran.r-project.org/package=stochvolTMB)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/grand-total/stochvolTMB?color=blue)](https://r-pkg.org/pkg/stochvolTMB)
[![R buildstatus](https://github.com/JensWahl/stochvolTMB/workflows/R-CMD-check/badge.svg)](https://github.com/JensWahl/stochvolTMB/actions)
[![License: GPLv3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Lifecycle:experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![DOI](https://zenodo.org/badge/162462958.svg)](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()
```

![](man/figures/shinyApp.png)

Owner

  • Name: Jens Christian Wahl
  • Login: JensWahl
  • Kind: user
  • Location: Oslo
  • Company: @NorskRegnesentral

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

All Time
  • Total Commits: 161
  • Total Committers: 4
  • Avg Commits per committer: 40.25
  • Development Distribution Score (DDS): 0.391
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email 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

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 208 Last month
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