ffp

Fully Flexible Probabilities for Stress-Testing and Portfolio Construction

https://github.com/reckziegel/ffp

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (18.5%) to scientific vocabulary

Keywords

bayesian-inference entropy-pooling flexible-probabilities portolio-optimization risk-management scenarios views
Last synced: 5 months ago · JSON representation

Repository

Fully Flexible Probabilities for Stress-Testing and Portfolio Construction

Basic Info
Statistics
  • Stars: 17
  • Watchers: 2
  • Forks: 3
  • Open Issues: 0
  • Releases: 0
Topics
bayesian-inference entropy-pooling flexible-probabilities portolio-optimization risk-management scenarios views
Created over 4 years ago · Last pushed over 3 years ago
Metadata Files
Readme Contributing License

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```



# Fully Flexible Probabilities


[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/Reckziegel/FFP/workflows/R-CMD-check/badge.svg)](https://github.com/Reckziegel/FFP/actions)
[![Codecov test coverage](https://codecov.io/gh/Reckziegel/FFP/branch/main/graph/badge.svg)](https://app.codecov.io/gh/Reckziegel/FFP?branch=main)
[![CRAN status](https://www.r-pkg.org/badges/version/ffp)](https://CRAN.R-project.org/package=ffp)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/last-month/ffp?color=blue)](https://r-pkg.org/pkg/ffp)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/grand-total/ffp?color=blue)](https://r-pkg.org/pkg/ffp)


> Functions for Scenario Analysis and Risk Management

Oftentimes, the econometrician needs to stress-test the potential outcomes for a given set of risk-drivers. This process can be computationally costly when the entire set of scenarios needs to be repriced.

To overcome this difficulty, the Fully Flexible Probabilities (FFP) approach offers an inexpensive way for scenario generation: it reprices the _probabilities_ associated to each scenario, instead of the scenarios themselves. Once the new probabilities have been defined, the computations can be performed very quickly because the burden of scenario generation has been left aside.

## Installation

Install the official version from CRAN with: 

```{r eval = FALSE}
install.packages("ffp")
```

Install the development version from github with:

```{r eval = FALSE}
# install.packages("devtools")
devtools::install_github("Reckziegel/ffp")
```

## Probability Estimation

The package `ffp` comes with five functions to extract probabilities from the historical scenarios: 

- `exp_decay()`: accounts for the time-changing nature of volatility by giving more weight to recent observations;
- `crisp()`: selects scenarios where a logical statement is satisfied;
- `kernel_normal()`: generalizes the `crisp` condition by wrapping scenarios over 
a normal kernel;
- `kernel_entropy()`: uses entropy-polling to satisfy a conditioning statement;
- `double_decay()`: uses entropy-polling and a double-decay factor to constrain the first two moments of a distribution.

```{r, echo=FALSE, message=FALSE, warning=FALSE, fig.align='center', out.width="70%", out.height="70%"}
library(dplyr)
library(ffp)

data("db_tbl")
inflation <- db_tbl %>% 
  dplyr::select(`10YR Inflation Swap Rate`) %>% 
  dplyr::slice(1:(nrow(db_tbl) - 1)) 

invariants <- db_tbl %>% 
  dplyr::select(VIX, SWAP10YR, `S&P 500`) %>% 
  purrr::map_df(~diff(log(.)))

#### Full Information #### 
# exponential-smoothing 
fp_es1 <- exp_decay(invariants, 0.0166)
fp_es2 <- exp_decay(invariants, 0.0055)
# crisp-conditioning on inflation 
fp_cc <- crisp(inflation, lgl = as.logical(inflation >= 2.8))
# normal kernel on inflation 
fp_kd <- kernel_normal(inflation, mean = 3, sigma = var(diff(inflation[[1]])))
#### Partial Information ####
# entropy-pooling by kernel-dumping on inflation
fp_ekd <- kernel_entropy(inflation, mean = 3, sigma = var(diff(inflation[[1]])))
# entropy-pooling by moment-matching
fp_emc <- double_decay(invariants, slow = 0.0055, fast = 0.0166)

bind_probs(fp_es1, fp_es2, fp_cc, fp_kd, fp_ekd, fp_emc) %>% 
  dplyr::mutate(names = c(rep("Exp. Smoothing (high decay)", 1082), rep("Exp. Smoothing (slow decay)", 1082), 
                          rep("Market-Conditioning", 1082),  rep("Normal Kernel", 1082), 
                          rep("FFP Kernel", 1082), rep("FFP Double-Decay", 1082))) %>% 
  ggplot2::ggplot(ggplot2::aes(x = rowid, y = probs, color = names)) + 
  ggplot2::geom_line(show.legend = FALSE) + 
  ggplot2::facet_wrap(~names) +  
                    #  labeller = ggplot2::labeller(
                    #    fn = c("Exp. Smoothing", "Exp. Smoothing", 
                    #            "Market-Conditioning", "Normal Kernel", 
                    #            "FFP Kernel", "FFP Double-Decay"))) +
  ggplot2::scale_y_continuous(labels = scales::percent_format()) + 
  ggplot2::scale_x_continuous(labels = NULL, breaks = NULL) + 
  ggplot2::scale_color_brewer(palette = "Paired") + 
  ggdist::theme_ggdist() + 
  ggplot2::labs(title = NULL, subtitle = NULL, x = NULL, y = NULL) 
```

## Stress-Testing and Portfolio Construction 

The package also offers eight different constructors to make it easier to input views 
on the market for portfolio optimization (mean-variance, risk-parity, etc.): 

- `view_on_mean()`
- `view_on_covariance()` 
- `view_on_correlation()` 
- `view_on_volatility()` 
- `view_on_rank()` 
- `view_on_copula()`
- `view_on_marginal_distribution()`
- `view_on_joint_distribution()`

The output is a list that `entropy_pooling()` can handle easily. To combine multiple 
views in a single object use `bind_views()`.

## Scenario Analysis

Once the new probabilities have been estimated, `bootstrap_scenarios()` can be used to sample data, while keeping the structure of the empirical copulas intact. 

The main statistics of arbitrary scenarios can be computed with `empirical_stats()`.

## References

- Attilio Meucci (2021). Historical Scenarios with Fully Flexible Probabilities (https://www.mathworks.com/matlabcentral/fileexchange/31360-historical-scenarios-with-fully-flexible-probabilities), MATLAB Central File Exchange. Retrieved June 11, 2021.

- De Santis, G., R. Litterman, A. Vesval, and K. Winkelmann, 2003, Covariance
matrix estimation, Modern investment management: an equilibrium
approach, Wiley.

- Meucci, Attilio, Fully Flexible Views: Theory and Practice (August 8, 2008). Fully Flexible Views: Theory and Practice, Risk, Vol. 21, No. 10, pp. 97-102, October 2008, Available at SSRN: https://www.ssrn.com/abstract=1213325

- Meucci, Attilio, Historical Scenarios with Fully Flexible Probabilities (October 23, 2010). GARP Risk Professional, pp. 47-51, December 2010, Available at SSRN: https://www.ssrn.com/abstract=1696802 or http://dx.doi.org/10.2139/ssrn.1696802

Owner

  • Name: Bernardo Reckziegel
  • Login: Reckziegel
  • Kind: user
  • Location: Porto Alegre, Brazil

GitHub Events

Total
  • Watch event: 4
Last Year
  • Watch event: 4

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 75
  • Total Committers: 2
  • Avg Commits per committer: 37.5
  • Development Distribution Score (DDS): 0.013
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Bernardo Reckziegel b****e@h****m 74
Bernardo Reckziegel B****e@h****m 1

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 13
  • Total pull requests: 8
  • Average time to close issues: 3 months
  • Average time to close pull requests: about 4 hours
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 0.38
  • Average comments per pull request: 0.25
  • Merged pull requests: 8
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • Reckziegel (13)
Pull Request Authors
  • Reckziegel (8)
Top Labels
Issue Labels
enhancement (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 274 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 2
  • Total versions: 4
  • Total maintainers: 1
cran.r-project.org: ffp

Fully Flexible Probabilities for Stress Testing and Portfolio Construction

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 2
  • Downloads: 274 Last month
Rankings
Stargazers count: 18.3%
Dependent repos count: 19.3%
Forks count: 21.0%
Average: 25.1%
Dependent packages count: 28.8%
Downloads: 38.1%
Maintainers (1)
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • R >= 2.10 depends
  • NlcOptim >= 0.6 imports
  • assertthat >= 0.2.1 imports
  • crayon * imports
  • dplyr >= 1.0.9 imports
  • forcats >= 0.5.1 imports
  • ggdist >= 3.1.1 imports
  • ggplot2 >= 3.3.6 imports
  • lubridate >= 1.8.0 imports
  • magrittr >= 2.0.3 imports
  • methods * imports
  • mvtnorm >= 1.1 imports
  • nloptr >= 2.0.3 imports
  • purrr >= 0.3.4 imports
  • rlang >= 1.0.2 imports
  • scales >= 1.2.0 imports
  • stats * imports
  • stringr >= 1.4.0 imports
  • tibble >= 3.1.7 imports
  • tidyr >= 1.2.0 imports
  • vctrs >= 0.4.1 imports
  • covr * suggests
  • knitr >= 1.39 suggests
  • markdown * suggests
  • roxygen2 * suggests
  • spelling * suggests
  • testthat >= 3.1.4 suggests
  • xts >= 0.12.1 suggests