{"id":32203836,"url":"https://github.com/reckziegel/ffp","last_synced_at":"2026-02-19T09:01:56.785Z","repository":{"id":41429878,"uuid":"372660354","full_name":"Reckziegel/FFP","owner":"Reckziegel","description":"Fully Flexible Probabilities for Stress-Testing and Portfolio Construction","archived":false,"fork":false,"pushed_at":"2022-09-29T18:26:55.000Z","size":15203,"stargazers_count":19,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-29T05:25:31.581Z","etag":null,"topics":["bayesian-inference","entropy-pooling","flexible-probabilities","portolio-optimization","risk-management","scenarios","views"],"latest_commit_sha":null,"homepage":"https://reckziegel.github.io/FFP/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Reckziegel.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-01T00:34:32.000Z","updated_at":"2025-11-01T16:41:30.000Z","dependencies_parsed_at":"2022-08-20T22:50:33.120Z","dependency_job_id":null,"html_url":"https://github.com/Reckziegel/FFP","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Reckziegel/FFP","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reckziegel%2FFFP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reckziegel%2FFFP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reckziegel%2FFFP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reckziegel%2FFFP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Reckziegel","download_url":"https://codeload.github.com/Reckziegel/FFP/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Reckziegel%2FFFP/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29609524,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T06:47:36.664Z","status":"ssl_error","status_checked_at":"2026-02-19T06:45:47.551Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bayesian-inference","entropy-pooling","flexible-probabilities","portolio-optimization","risk-management","scenarios","views"],"created_at":"2025-10-22T04:46:29.395Z","updated_at":"2026-02-19T09:01:56.779Z","avatar_url":"https://github.com/Reckziegel.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n\u003cimg src='man/figures/ffp_sticker.png' align=\"right\" width=\"147\" height=\"170\" /\u003e\n\n# Fully Flexible Probabilities\n\n\u003c!-- badges: start --\u003e\n[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)\n[![R-CMD-check](https://github.com/Reckziegel/FFP/workflows/R-CMD-check/badge.svg)](https://github.com/Reckziegel/FFP/actions)\n[![Codecov test coverage](https://codecov.io/gh/Reckziegel/FFP/branch/main/graph/badge.svg)](https://app.codecov.io/gh/Reckziegel/FFP?branch=main)\n[![CRAN status](https://www.r-pkg.org/badges/version/ffp)](https://CRAN.R-project.org/package=ffp)\n[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/last-month/ffp?color=blue)](https://r-pkg.org/pkg/ffp)\n[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/grand-total/ffp?color=blue)](https://r-pkg.org/pkg/ffp)\n\u003c!-- badges: end --\u003e\n\n\u003e Functions for Scenario Analysis and Risk Management\n\nOftentimes, 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.\n\nTo 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.\n\n## Installation\n\nInstall the official version from CRAN with: \n\n```{r eval = FALSE}\ninstall.packages(\"ffp\")\n```\n\nInstall the development version from github with:\n\n```{r eval = FALSE}\n# install.packages(\"devtools\")\ndevtools::install_github(\"Reckziegel/ffp\")\n```\n\n## Probability Estimation\n\nThe package `ffp` comes with five functions to extract probabilities from the historical scenarios: \n\n- `exp_decay()`: accounts for the time-changing nature of volatility by giving more weight to recent observations;\n- `crisp()`: selects scenarios where a logical statement is satisfied;\n- `kernel_normal()`: generalizes the `crisp` condition by wrapping scenarios over \na normal kernel;\n- `kernel_entropy()`: uses entropy-polling to satisfy a conditioning statement;\n- `double_decay()`: uses entropy-polling and a double-decay factor to constrain the first two moments of a distribution.\n\n```{r, echo=FALSE, message=FALSE, warning=FALSE, fig.align='center', out.width=\"70%\", out.height=\"70%\"}\nlibrary(dplyr)\nlibrary(ffp)\n\ndata(\"db_tbl\")\ninflation \u003c- db_tbl %\u003e% \n  dplyr::select(`10YR Inflation Swap Rate`) %\u003e% \n  dplyr::slice(1:(nrow(db_tbl) - 1)) \n\ninvariants \u003c- db_tbl %\u003e% \n  dplyr::select(VIX, SWAP10YR, `S\u0026P 500`) %\u003e% \n  purrr::map_df(~diff(log(.)))\n\n#### Full Information #### \n# exponential-smoothing \nfp_es1 \u003c- exp_decay(invariants, 0.0166)\nfp_es2 \u003c- exp_decay(invariants, 0.0055)\n# crisp-conditioning on inflation \nfp_cc \u003c- crisp(inflation, lgl = as.logical(inflation \u003e= 2.8))\n# normal kernel on inflation \nfp_kd \u003c- kernel_normal(inflation, mean = 3, sigma = var(diff(inflation[[1]])))\n#### Partial Information ####\n# entropy-pooling by kernel-dumping on inflation\nfp_ekd \u003c- kernel_entropy(inflation, mean = 3, sigma = var(diff(inflation[[1]])))\n# entropy-pooling by moment-matching\nfp_emc \u003c- double_decay(invariants, slow = 0.0055, fast = 0.0166)\n\nbind_probs(fp_es1, fp_es2, fp_cc, fp_kd, fp_ekd, fp_emc) %\u003e% \n  dplyr::mutate(names = c(rep(\"Exp. Smoothing (high decay)\", 1082), rep(\"Exp. Smoothing (slow decay)\", 1082), \n                          rep(\"Market-Conditioning\", 1082),  rep(\"Normal Kernel\", 1082), \n                          rep(\"FFP Kernel\", 1082), rep(\"FFP Double-Decay\", 1082))) %\u003e% \n  ggplot2::ggplot(ggplot2::aes(x = rowid, y = probs, color = names)) + \n  ggplot2::geom_line(show.legend = FALSE) + \n  ggplot2::facet_wrap(~names) +  \n                    #  labeller = ggplot2::labeller(\n                    #    fn = c(\"Exp. Smoothing\", \"Exp. Smoothing\", \n                    #            \"Market-Conditioning\", \"Normal Kernel\", \n                    #            \"FFP Kernel\", \"FFP Double-Decay\"))) +\n  ggplot2::scale_y_continuous(labels = scales::percent_format()) + \n  ggplot2::scale_x_continuous(labels = NULL, breaks = NULL) + \n  ggplot2::scale_color_brewer(palette = \"Paired\") + \n  ggdist::theme_ggdist() + \n  ggplot2::labs(title = NULL, subtitle = NULL, x = NULL, y = NULL) \n```\n\n## Stress-Testing and Portfolio Construction \n\nThe package also offers eight different constructors to make it easier to input views \non the market for portfolio optimization (mean-variance, risk-parity, etc.): \n\n- `view_on_mean()`\n- `view_on_covariance()` \n- `view_on_correlation()` \n- `view_on_volatility()` \n- `view_on_rank()` \n- `view_on_copula()`\n- `view_on_marginal_distribution()`\n- `view_on_joint_distribution()`\n\nThe output is a list that `entropy_pooling()` can handle easily. To combine multiple \nviews in a single object use `bind_views()`.\n\n## Scenario Analysis\n\nOnce the new probabilities have been estimated, `bootstrap_scenarios()` can be used to sample data, while keeping the structure of the empirical copulas intact. \n\nThe main statistics of arbitrary scenarios can be computed with `empirical_stats()`.\n\n## References\n\n- 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.\n\n- De Santis, G., R. Litterman, A. Vesval, and K. Winkelmann, 2003, Covariance\nmatrix estimation, Modern investment management: an equilibrium\napproach, Wiley.\n\n- 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\n\n- 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\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freckziegel%2Fffp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freckziegel%2Fffp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freckziegel%2Fffp/lists"}