| Title: | Statistical Methods in Quantitative Finance |
| Version: | 1.1-1 |
| Description: | Provides data and functions used in the book "Statistical Methods in Quantitative Finance" by David Ardia (2026). |
| License: | GPL-3 |
| LazyData: | true |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.1.0), xts |
| URL: | https://github.com/ArdiaD/smqf-package |
| BugReports: | https://github.com/ArdiaD/smqf-package/issues |
| Suggests: | zoo, testthat (≥ 3.0.0), PerformanceAnalytics, glmnet |
| Config/testthat/edition: | 3 |
| Imports: | graphics, stats, nloptr, pracma |
| Config/roxygen2/version: | 8.0.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-05-28 13:02:31 UTC; ardiad |
| Author: | David Ardia |
| Maintainer: | David Ardia <david.ardia.ch@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-06-01 09:00:07 UTC |
smqf: Statistical Methods in Quantitative Finance
Description
'smqf' is an R package providing datasets and functions used in the book "Statistical Methods in Quantitative Finance" Ardia (2026).
Acknowledgments
The market datasets 'SP500', 'DJ', 'DJ_const', 'FTSE', 'FTSE_const',
'EURSTOXX', 'EURSTX_const', 'DAX', 'CAC', 'NIKKEI', 'SMI', 'HSI',
'GOLD', and 'VIX' are redistributed from the **qrmdata** package by
Marius Hofert, Kurt Hornik, and Alexander J. McNeil under the same
GPL (\ge 2) license. The original data was collected by the qrmdata authors from
Yahoo Finance and FRED (via Quandl) on 2016-01-03. See
<https://CRAN.R-project.org/package=qrmdata> for the upstream package
and the individual dataset help pages for details.
Author(s)
David Ardia
References
David Ardia (2026). *Statistical Methods in Quantitative Finance*. CRC Press.
Hofert, M., Hornik, K., & McNeil, A. J. *qrmdata: Data Sets for Quantitative Risk Management Practice*. <https://CRAN.R-project.org/package=qrmdata>.
See Also
Useful links:
CAC 40 Index (Daily, xts)
Description
Daily adjusted close prices of the Cotation Assistée en Continu (CAC 40)
stock index (ticker symbol ^FCHI), from its first date of
availability on Yahoo Finance to 2015-12-31.
Usage
data("CAC")
Format
An xts object with 6549 daily observations and a single
column ^FCHI containing adjusted close prices in index points.
The time index spans from 1990-03-01 to 2015-12-31.
Details
Originally distributed as CAC in the qrmdata package
(Hofert, Hornik, & McNeil), ported into smqf so that the book's
examples remain reproducible without an extra dependency. The data is
redistributed here under the same GPL (\ge 2) license as
qrmdata.
Source
Yahoo Finance, downloaded on 2016-01-03 via qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("CAC")
class(CAC) # "xts" "zoo"
dim(CAC)
head(CAC)
DAX Index (Daily, xts)
Description
Daily adjusted close prices of the Deutscher Aktienindex (DAX) stock
index (ticker symbol ^GDAXI), from its first date of
availability on Yahoo Finance to 2015-12-30.
Usage
data("DAX")
Format
An xts object with 6355 daily observations and a single
column ^GDAXI containing adjusted close prices in index points.
The time index spans from 1990-11-26 to 2015-12-30.
Details
Originally distributed as DAX in the qrmdata package
(Hofert, Hornik, & McNeil), ported into smqf so that the book's
examples remain reproducible without an extra dependency. The data is
redistributed here under the same GPL (\ge 2) license as qrmdata.
Source
Yahoo Finance, downloaded on 2016-01-03 via qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("DAX")
class(DAX) # "xts" "zoo"
dim(DAX)
head(DAX)
Dow Jones Industrial Average Index (Daily, xts)
Description
Daily adjusted close prices of the Dow Jones Industrial Average
(ticker symbol ^DJI), from its first date of availability on
Yahoo Finance to 2015-12-31.
Usage
data("DJ")
Format
An xts object with 7797 daily observations and a single
column ^DJI containing adjusted close prices in index points.
The time index spans from 1985-01-29 to 2015-12-31.
Details
Originally distributed as DJ in the qrmdata package
(Hofert, Hornik, & McNeil), ported into smqf so that the book's
examples remain reproducible without an extra dependency. The data is
redistributed here under the same GPL (\ge 2) license as qrmdata.
Source
Yahoo Finance, downloaded on 2016-01-03 via qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("DJ")
class(DJ) # "xts" "zoo"
dim(DJ)
head(DJ)
Dow Jones Industrial Average Constituents (Daily, xts)
Description
Daily adjusted close prices for the 30 constituents of the Dow Jones Industrial Average as of 2016-01-03.
Usage
data("DJ_const")
Format
An xts object with 13595 daily observations and 30
columns, one per constituent (e.g., AAPL, IBM,
JPM, XOM). Missing values appear before the first date
at which a given constituent was available. The time index spans
from 1962-01-02 to 2015-12-31.
Details
Originally distributed as DJ_const in the qrmdata
package (Hofert, Hornik, & McNeil), ported into smqf so that
the book's examples remain reproducible without an extra dependency. The
data is redistributed here under the same GPL (\ge 2) license as
qrmdata.
Source
Yahoo Finance, downloaded on 2016-01-03 via qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("DJ_const")
class(DJ_const) # "xts" "zoo"
dim(DJ_const)
head(colnames(DJ_const))
Euro Stoxx 50 Index (Daily, xts)
Description
Daily adjusted close prices of the Euro Stoxx 50 stock index
(ticker symbol ^STOXX50E), from its first date of availability
on Yahoo Finance to 2015-12-23.
Usage
data("EURSTOXX")
Format
An xts object with 7445 daily observations and a single
column ^STOXX50E containing adjusted close prices in index
points. The time index spans from 1986-12-31 to 2015-12-23.
Details
Originally distributed as EURSTOXX in the qrmdata
package (Hofert, Hornik, & McNeil), ported into smqf so that
the book's examples remain reproducible without an extra dependency. The
data is redistributed here under the same GPL (\ge 2) license as
qrmdata.
Source
Yahoo Finance, downloaded on 2016-01-03 via qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("EURSTOXX")
class(EURSTOXX) # "xts" "zoo"
dim(EURSTOXX)
head(EURSTOXX)
Euro Stoxx 50 Constituents (Daily, xts)
Description
Daily adjusted close prices for the 50 constituents of the Euro Stoxx 50 stock index as of 2016-01-03.
Usage
data("EURSTX_const")
Format
An xts object with 4174 daily observations and 50
columns, one per constituent (e.g., SAP.DE, BNP.PA,
SAN.MC). Missing values appear before the first date at which
a given constituent was available. The time index spans from
2000-01-03 to 2015-12-31.
Details
Originally distributed as EURSTX_const in the qrmdata
package (Hofert, Hornik, & McNeil), ported into smqf so that
the book's examples remain reproducible without an extra dependency. The
data is redistributed here under the same GPL (\ge 2) license as
qrmdata.
Source
Yahoo Finance, downloaded on 2016-01-03 via qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("EURSTX_const")
class(EURSTX_const) # "xts" "zoo"
dim(EURSTX_const)
head(colnames(EURSTX_const))
FTSE 100 Index (Daily, xts)
Description
Daily adjusted close prices of the FTSE 100 stock index
(ticker symbol ^FTSE), from its first date of availability on
Yahoo Finance to 2015-12-31.
Usage
data("FTSE")
Format
An xts object with 8333 daily observations and a single
column ^FTSE containing adjusted close prices in index points.
The time index spans from 1984-01-03 to 2015-12-31.
Details
Originally distributed as FTSE in the qrmdata package
(Hofert, Hornik, & McNeil), ported into smqf so that the book's
examples remain reproducible without an extra dependency. The data is
redistributed here under the same GPL (\ge 2) license as qrmdata.
Source
Yahoo Finance, downloaded on 2016-01-03 via qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("FTSE")
class(FTSE) # "xts" "zoo"
dim(FTSE)
head(FTSE)
FTSE 100 Constituents (Daily, xts)
Description
Daily adjusted close prices for 98 constituents of the FTSE 100 stock index as of 2016-01-03.
Usage
data("FTSE_const")
Format
An xts object with 7198 daily observations and 98
columns, one per constituent (e.g., HSBA.L, BP.L,
VOD.L). Missing values appear before the first date at which
a given constituent was available. The time index spans from
1988-05-03 to 2015-12-31.
Details
Originally distributed as FTSE_const in the qrmdata
package (Hofert, Hornik, & McNeil), ported into smqf so that
the book's examples remain reproducible without an extra dependency. The
data is redistributed here under the same GPL (\ge 2) license as
qrmdata.
Only 98 of the 100 constituents were available at the time of the
download.
Source
Yahoo Finance, downloaded on 2016-01-03 via qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("FTSE_const")
class(FTSE_const) # "xts" "zoo"
dim(FTSE_const)
head(colnames(FTSE_const))
Fama–French Factors (Monthly, xts)
Description
Monthly time series of the three Fama–French equity risk factors and the
risk-free rate, as provided by Kenneth French's data library.
Values are expressed in percentage points (e.g., -1.20
means a return of -1.20\%).
Usage
data("FamaFrenchMonthly")
Format
An xts object with 360 monthly observations
(from 1969-01-01 to 1998-12-01) and 4 columns:
- mkt_rf
Excess return on the market (market return minus risk-free rate), in %.
- smb
Small-Minus-Big size factor return, in %.
- hml
High-Minus-Low value factor return, in %.
- rf
Risk-free rate (monthly), in %.
Details
The time index is set to the first calendar day of each month.
Divide by 100 to convert to decimal returns before use in calculations.
For the weekly version of this dataset see FamaFrenchWeekly.
Source
Kenneth R. French Data Library, https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html.
References
Fama, E. F., & French, K. R. (1993). Common Risk Factors in the Returns on Stocks and Bonds. Journal of Financial Economics, 33(1), 3–56.
See Also
FamaFrenchWeekly for the higher-frequency
(weekly, 1926-2019) companion dataset built from the same Kenneth French
source. The two datasets are pedagogically complementary: the monthly
version is convenient for low-frequency factor-model illustrations, while
the weekly version offers a much longer sample for time-series exercises.
Examples
data("FamaFrenchMonthly")
class(FamaFrenchMonthly) # "xts" "zoo"
dim(FamaFrenchMonthly) # 360 x 4
head(FamaFrenchMonthly)
# Convert to decimal and extract the three equity factors
ff <- FamaFrenchMonthly[, c("mkt_rf", "smb", "hml")] / 100
rf <- FamaFrenchMonthly[, "rf"] / 100
Fama–French Factors (Weekly, xts)
Description
Weekly time series of the three Fama–French equity risk factors and the
risk-free rate, as provided by Kenneth French's data library.
Values are expressed in percentage points (e.g., 1.60 means
a return of 1.60%).
Usage
data("FamaFrenchWeekly")
Format
An xts object with 4\,834 weekly observations
(from 1926-07-02 to 2019-02-22) and 4 columns:
- mkt_rf
Excess return on the market (market return minus risk-free rate), in %.
- smb
Small-Minus-Big size factor return, in %.
- hml
High-Minus-Low value factor return, in %.
- rf
Risk-free rate (weekly), in %.
Details
Divide by 100 to convert to decimal returns before use in calculations.
For the monthly version of this dataset see FamaFrenchMonthly.
Source
Kenneth R. French Data Library, https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html.
References
Fama, E. F., & French, K. R. (1993). Common Risk Factors in the Returns on Stocks and Bonds. Journal of Financial Economics, 33(1), 3–56.
See Also
FamaFrenchMonthly for the lower-frequency
(monthly, 1969-1998) companion dataset built from the same Kenneth French
source. The two datasets are pedagogically complementary: the weekly
version offers a much longer sample for time-series exercises, while the
monthly version is convenient for low-frequency factor-model
illustrations.
Examples
data("FamaFrenchWeekly")
class(FamaFrenchWeekly) # "xts" "zoo"
dim(FamaFrenchWeekly) # 4834 x 4
head(FamaFrenchWeekly)
# Convert to decimal and extract the three equity factors
ff <- FamaFrenchWeekly[, c("mkt_rf", "smb", "hml")] / 100
rf <- FamaFrenchWeekly[, "rf"] / 100
FRED-MD Macro Factors and Dow Jones Returns (Monthly, 2015–2019)
Description
A list containing a matrix of 128 FRED-MD macroeconomic predictors and a vector of monthly Dow Jones Industrial Average log-returns, aligned over the period 2015-01 to 2019-12. Used to illustrate high-dimensional regularised regression (Lasso, Ridge) in a return-prediction context.
Usage
data("Fred")
Format
A named list with two components:
- X
A
60 \times 128numeric matrix of standardised FRED-MD macro variables (monthly, January 2015 to December 2019). Row names are"YYYY-MM-01"strings; column names are FRED-MD series codes (e.g.,"INDPRO","CPIAUCSL","GS10"). The series have been transformed (differenced or log-differenced) to achieve stationarity following the FRED-MD transformation codes.- y
A
60 \times 1numeric matrix of one-month-ahead Dow Jones Industrial Average log-returns (column name"DJI.Adjusted"), shifted so that rowtofXpredicts rowtofy.
Details
The predictors in X were downloaded from the McCracken–Ng FRED-MD
database and transformed according to the recommended stationarity codes.
The target y was obtained from Yahoo Finance via
quantmod::getSymbols("^DJI") and converted to monthly log-returns.
Both series are restricted to the 60-month window 2015-01 to 2019-12 and
temporally aligned so that X[t, ] can be used to predict
y[t].
Source
McCracken, M. W., & Ng, S. FRED-MD database, https://www.stlouisfed.org/research/economists/mccracken/fred-databases.
Dow Jones daily prices via
quantmod::getSymbols("^DJI"), Yahoo Finance.
References
McCracken, M. W., & Ng, S. (2016). FRED-MD: A Monthly Database for Macroeconomic Research. Journal of Business & Economic Statistics, 34(4), 574–589.
See Also
The book chapter on Dimension Reduction (Chapter 4 of
Statistical Methods in Quantitative Finance) introduces Lasso and
Ridge regression on the lower-dimensional GoyalWelch dataset;
Fred provides a complementary high-dimensional (p \gg n) test
bed for the same regularised-regression workflow.
Examples
data("Fred")
X <- Fred$X # 60 x 128 macro predictors
y <- Fred$y # 60 x 1 DJ log-returns
dim(X)
head(rownames(X))
# Lasso with cross-validation (requires glmnet)
if (requireNamespace("glmnet", quietly = TRUE)) {
set.seed(1234)
fit <- glmnet::cv.glmnet(X, y, alpha = 1)
coef(fit, s = "lambda.min")[coef(fit, s = "lambda.min")[,1] != 0, , drop = FALSE]
}
Fung–Hsieh Factors (Monthly, xts)
Description
Monthly time series of commonly used Fung–Hsieh style and macro factors.
The object is an xts matrix with a monthly index and the columns
listed below. Typical use cases include hedge-fund replication and
factor attribution.
Usage
data("FungHsieh")
Format
An xts object with 276 monthly observations
(from 1994-01 to 2016-12) and 8 columns:
- EMKT
Equity market factor (broad market return / excess return).
- RF
Risk-free rate (monthly).
- SS
Size or related equity style spread (e.g., small–minus–big).
- CST10Y
Change in the 10-year U.S. Treasury constant-maturity yield.
- BAA
Change in a BAA credit spread / yield (credit conditions).
- PTFSBD
Fung–Hsieh trend-following factor: bond.
- PTFSCOM
Fung–Hsieh trend-following factor: commodity.
- PTFSFX
Fung–Hsieh trend-following factor: currency (FX).
Details
Columns are provided as in the original Fung–Hsieh factor construction.
Units may appear as percentage points or basis points depending on source/
vintage; treat the series consistently within your analysis. The time index
is monthly and stored in UTC; the object class is c("xts","zoo").
Source
Compiled from public factor sources commonly used in the Fung–Hsieh
literature
(e.g., Hsieh’s data library, FRED/H.15, and Fama–French style factors).
If you distribute the data, include a data-raw/ script that reproduces
this object from original sources.
References
Fung, W., & Hsieh, D. A. (2004). Hedge Fund Benchmarks: A Risk-Based Approach. Financial Analysts Journal, 60(5), 65–80. Fung, W., & Hsieh, D. A. (2001). The Risk in Hedge Fund Strategies: Theory and Evidence from Trend Followers. Review of Financial Studies, 14(2), 313–341.
Examples
data("FungHsieh")
class(FungHsieh) # "xts" "zoo"
head(FungHsieh)
colnames(FungHsieh)
# Quick plot of the three PTFS factors
if (requireNamespace("zoo", quietly = TRUE)) {
zoo::plot.zoo(FungHsieh[, c("PTFSBD", "PTFSCOM", "PTFSFX")], screens = 1, col = 1:3)
}
Gold Price (Daily, xts)
Description
Daily World Gold Council gold price in USD per troy ounce, from 1970-01-01 to 2015-12-31.
Usage
data("GOLD")
Format
An xts object with 9691 daily observations and a single
column GOLD containing USD prices per troy ounce.
Details
Originally distributed as GOLD in the qrmdata package
(Hofert, Hornik, & McNeil), ported into smqf so that the book's
examples remain reproducible without an extra dependency. The data is
redistributed here under the same GPL (\ge 2) license as qrmdata.
Source
Federal Reserve Economic Data (FRED) via Quandl, downloaded on
2016-01-03 with qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("GOLD")
class(GOLD) # "xts" "zoo"
dim(GOLD)
head(GOLD)
Goyal–Welch Predictive Variables (Monthly, U.S.)
Description
Monthly time series of equity predictors and bond/credit variables commonly
used in return predictability studies following Goyal & Welch (2008).
Stored as an xts object with a monthly Date index (UTC).
Usage
data("GoyalWelch")
Format
An xts object with monthly observations (1980–2018 in this
snapshot) and 15 variables:
- Index
Broad U.S. equity price index level (e.g., S&P 500).
- D12
Trailing 12-month cash dividends on the index (level).
- E12
Trailing 12-month earnings on the index (level).
- b/m
Aggregate book-to-market ratio.
- tbl
3-month Treasury bill rate (monthly).
- AAA
Moody’s AAA corporate bond yield.
- BAA
Moody’s BAA corporate bond yield.
- lty
Long-term government bond yield.
- ntis
Net equity expansion: shares issued less repurchases scaled by total equity (a supply measure).
- Rfree
Risk-free rate (monthly).
- infl
Inflation (monthly change in price level).
- ltr
Long-term government bond total return (monthly).
- corpr
Corporate bond total return (monthly).
- svar
Stock market variance proxy (e.g., rolling sum of daily squared returns).
- csp
Corporate bond return spread:
corpr - ltr.
Details
This object mirrors the variables used in
Goyal & Welch (2008) and subsequent updates. From these levels you can form
the standard ratios used in the literature, for example
dp = log(D12/Index), ep = log(E12/Index),
dfy = BAA - AAA, and tms = lty - tbl.
Source
Compiled from the public Goyal–Welch data library (predictable stock returns)
and standard fixed-income sources (e.g., FRED). If you distribute this data,
include a data-raw/ script that reproduces the object from originals.
References
Goyal, A., & Welch, I. (2008). A Comprehensive Look at The Empirical Performance of Equity Premium Prediction. Review of Financial Studies, 21(4), 1455–1508.
Examples
data("GoyalWelch")
class(GoyalWelch) # "xts" "zoo"
head(GoyalWelch)
# Construct common predictors:
dp <- log(GoyalWelch[,"D12"] / GoyalWelch[,"Index"]) # dividend–price
ep <- log(GoyalWelch[,"E12"] / GoyalWelch[,"Index"]) # earnings–price
dfy <- GoyalWelch[,"BAA"] - GoyalWelch[,"AAA"] # default yield spread
tms <- GoyalWelch[,"lty"] - GoyalWelch[,"tbl"] # term spread
Hang Seng Index (Daily, xts)
Description
Daily adjusted close prices of the Hang Seng stock index (ticker
symbol ^HSI), from its first date of availability on Yahoo
Finance to 2015-12-31.
Usage
data("HSI")
Format
An xts object with 7214 daily observations and a single
column ^HSI containing adjusted close prices in index points.
The time index spans from 1986-12-31 to 2015-12-31.
Details
Originally distributed as HSI in the qrmdata package
(Hofert, Hornik, & McNeil), ported into smqf so that the book's
examples remain reproducible without an extra dependency. The data is
redistributed here under the same GPL (\ge 2) license as
qrmdata.
Source
Yahoo Finance, downloaded on 2016-01-03 via qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("HSI")
class(HSI) # "xts" "zoo"
dim(HSI)
head(HSI)
NIKKEI 225 Index (Daily, xts)
Description
Daily adjusted close prices of the NIKKEI 225 stock index
(ticker symbol ^N225), from its first date of availability on
Yahoo Finance to 2015-12-30.
Usage
data("NIKKEI")
Format
An xts object with 7880 daily observations and a single
column ^N225 containing adjusted close prices in index points.
The time index spans from 1984-01-04 to 2015-12-30.
Details
Originally distributed as NIKKEI in the qrmdata package
(Hofert, Hornik, & McNeil), ported into smqf so that the book's
examples remain reproducible without an extra dependency. The data is
redistributed here under the same GPL (\ge 2) license as qrmdata.
Source
Yahoo Finance, downloaded on 2016-01-03 via qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("NIKKEI")
class(NIKKEI) # "xts" "zoo"
dim(NIKKEI)
head(NIKKEI)
Swiss Market Index (Daily, xts)
Description
Daily adjusted close prices of the Swiss Market Index (SMI) stock
index (ticker symbol ^SSMI), from its first date of
availability on Yahoo Finance to 2015-12-30.
Usage
data("SMI")
Format
An xts object with 6350 daily observations and a single
column ^SSMI containing adjusted close prices in index points.
The time index spans from 1990-11-09 to 2015-12-30.
Details
Originally distributed as SMI in the qrmdata package
(Hofert, Hornik, & McNeil), ported into smqf so that the book's
examples remain reproducible without an extra dependency. The data is
redistributed here under the same GPL (\ge 2) license as
qrmdata. Note: the MSGARCH package ships a different
dataset also named SMI (SMI log-returns); to use that one, load
it explicitly with data("SMI", package = "MSGARCH").
Source
Yahoo Finance, downloaded on 2016-01-03 via qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("SMI")
class(SMI) # "xts" "zoo"
dim(SMI)
head(SMI)
S&P 500 Index (Daily, xts)
Description
Daily adjusted close prices of the Standard & Poor's 500 stock index
(ticker symbol ^GSPC), from its first date of availability on
Yahoo Finance to 2015-12-31.
Usage
data("SP500")
Format
An xts object with 16607 daily observations and a single
column ^GSPC containing adjusted close prices in index points.
The time index spans from 1950-01-03 to 2015-12-31.
Details
Originally distributed as SP500 in the qrmdata package
(Hofert, Hornik, & McNeil), ported into smqf so that the book's
examples remain reproducible without an extra dependency. The data is
redistributed here under the same GPL (\ge 2) license as qrmdata.
Source
Yahoo Finance, downloaded on 2016-01-03 via qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("SP500")
class(SP500) # "xts" "zoo"
dim(SP500)
head(SP500)
Daily Term Structure (1m–30y)
Description
A compact term–structure object holding daily yield curves across 11 standard maturities from mid-2006 to late-2008. The object is a named list with the observation dates, the maturity grid (in years), and a rates matrix (rows = dates, columns = maturities).
Usage
data("TermStructure")
Format
A list with three components:
- time
Character vector of ISO-8601 calendar dates (e.g.,
"2006-05-12"). Length equals the number of rows inrates.- tau
Numeric vector of maturities in years:
c(1/12, 1/4, 1/2, 1, 2, 3, 5, 7, 10, 20, 30).- rates
Numeric matrix of annualized yields (percent, not decimals) with dimension
T \times 11. Column names:X1mo,X3mo,X6mo,X1yr,X2yr,X3yr,X5yr,X7yr,X10yr,X20yr,X30yr.
Details
Dates run from 2006-05-12 to 2008-10-31 (about 622 business
days in this snapshot). Yields are curve levels for each maturity on each
date and can be used directly for fitting/parsing term-structure models
(e.g., Nelson–Siegel or Svensson), computing spreads (term, slope,
butterfly),
or building zero curves.
Examples
data("TermStructure")
str(TermStructure)
# Convert 'time' to Date and build an xts for quick plotting
dts <- as.Date(TermStructure$time)
y.mat <- TermStructure$rates
colnames(y.mat)
# Example: 10Y vs 2Y term spread (in percentage points)
sprd_10y2y <- y.mat[, "X10yr"] - y.mat[, "X2yr"]
head(sprd_10y2y)
# Example: maturity grid (years)
TermStructure$tau
CBOE Volatility Index VIX (Daily, xts)
Description
Daily close values of the Chicago Board Options Exchange (CBOE)
volatility index VIX (ticker symbol ^VIX), from its first date
of availability on Yahoo Finance to 2015-12-31.
Usage
data("VIX")
Format
An xts object with 6553 daily observations and a single
column ^VIX containing the VIX level in percent
(annualized implied volatility). The time index spans from
1990-01-02 to 2015-12-31.
Details
Originally distributed as VIX in the qrmdata package
(Hofert, Hornik, & McNeil), ported into smqf so that the book's
examples remain reproducible without an extra dependency. The data is
redistributed here under the same GPL (\ge 2) license as qrmdata. The VIX is
typically used as a market-based measure of volatility, expressed in
percent.
Source
Yahoo Finance, downloaded on 2016-01-03 via qrmtools::get_data().
References
Hofert, M., Hornik, K., & McNeil, A. J. qrmdata: Data Sets for Quantitative Risk Management Practice, https://CRAN.R-project.org/package=qrmdata.
Examples
data("VIX")
class(VIX) # "xts" "zoo"
dim(VIX)
head(VIX)
Clayton Copula PDF (2-Dimensional)
Description
Computes the value of the bivariate Clayton copula probability density
function (PDF) at a specified point (u_1, u_2) for a given dependence
parameter \theta.
Usage
f_clayton_copula_2d_pdf(u, theta)
Arguments
u |
Numeric vector of length 2, containing values in the interval
|
theta |
Numeric scalar giving the dependence parameter
( |
Details
The Clayton copula is an Archimedean copula with lower-tail dependence
\lambda_L = 2^{-1/\theta} and no upper-tail dependence (\lambda_U = 0).
When \theta = 0, the copula reduces to the independence copula,
whose PDF equals 1 for all (u_1, u_2) \in [0,1]^2.
The PDF is given by:
c(u_1, u_2; \theta)
= (1 + \theta)\,(u_1 u_2)^{-(1 + \theta)}\,
\left(u_1^{-\theta} + u_2^{-\theta} - 1\right)^{-2 - 1/\theta}.
Numerical computation may lose precision for large \theta (typically
above about 34).
Value
A numeric value corresponding to the Clayton copula PDF evaluated at the specified point.
References
- Joe, H. (1997). Multivariate Models and Dependence Concepts. Chapman & Hall. - Patton, A. (2006). Modelling Asymmetric Exchange Rate Dependence. International Economic Review, 47(2), 527–556.
See Also
f_gumbel_copula_2d_pdf, f_normal_copula_pdf,
f_student_copula_pdf
Examples
# Example: Evaluate Clayton copula PDF at (u1, u2) = (0.5, 0.5)
f_clayton_copula_2d_pdf(c(0.5, 0.5), theta = 2)
Display a Bivariate Copula Surface
Description
Evaluates and displays a bivariate copula function (typically a PDF or CDF)
on a 2D grid, producing a static 3D surface via base R's persp().
Usage
f_display_copula(my_copula, grid_1, grid_2, plot = TRUE)
Arguments
my_copula |
A function that takes a numeric vector |
grid_1, grid_2 |
Numeric vectors defining the evaluation grid for
|
plot |
Logical; if |
Details
This function provides a simple way to visualize the surface of a bivariate
copula (e.g., Clayton, Gumbel, Gaussian). The copula function should accept a
vector of two uniform values (u_1,u_2) and return its density or CDF
value.
Value
Invisibly returns the matrix of evaluated copula values
f_U, with rows corresponding to grid_1 and columns to grid_2.
Examples
# Example: Display the Clayton copula PDF surface
grid <- seq(0.05, 0.95, length.out = 25)
f_display_copula(
my_copula = function(u) f_clayton_copula_2d_pdf(u, theta = 2),
grid_1 = grid,
grid_2 = grid
)
Compute a Long-Only Mean–Variance Efficient Frontier
Description
Solves a sequence of quadratic programs to trace the long-only, fully-invested Markowitz efficient frontier between the minimum-variance portfolio and the maximum-return (corner) portfolio.
Usage
f_efficient_frontier(mu, Sigma, n_ptf)
Arguments
mu |
Numeric vector of length |
Sigma |
Numeric |
n_ptf |
Integer |
Details
Portfolios are obtained by minimizing variance for a grid of target returns
under the constraints \sum_i w_i = 1 and w_i \ge 0.
Each QP solves
\min_{w}\; w^\top \Sigma\, w \quad
\text{s.t. } \mathbf{1}^\top w = 1,\; w \ge 0
and, for interior points on the frontier, additionally
\mu^\top w = \mu^\star,
where \mu^\star spans a linear grid between the min-variance portfolio
return and the single-asset maximum-return portfolio.
Requires pracma for quadprog. Numerical issues can arise if
Sigma is not positive semidefinite or if target returns are infeasible
under the long-only constraint.
Value
A list with components:
- weights
Numeric matrix
N \times n_ptf: portfolio weights.- volatility
Numeric length-
n_ptf: portfolio standard deviations.- expected_returns
Numeric length-
n_ptf: portfolio expected returns.- frontier
Data frame with columns
point(integer index),expected_return, andvolatilityfor each frontier portfolio.- targets
Numeric vector of length
n_ptf: the target-return grid used to trace the frontier.
References
Markowitz, H. (1952). Portfolio Selection. Journal of Finance, 7(1), 77–91.
See Also
Examples
set.seed(1)
N <- 4
mu <- c(0.08, 0.10, 0.12, 0.09)
M <- matrix(rnorm(N*N), N); Sigma <- crossprod(M) / N # PSD covariance
ef <- f_efficient_frontier(mu, Sigma, n_ptf = 20)
# Inspect end points
ef$expected_returns[c(1, 20)]
ef$volatility[c(1, 20)]
Gumbel Copula CDF (2-Dimensional)
Description
Computes the bivariate Gumbel copula cumulative distribution function (CDF)
at (u_1,u_2) for dependence parameter \theta \ge 1.
Usage
f_gumbel_copula_2d_cdf(u, theta)
Arguments
u |
Numeric vector of length 2 with entries in |
theta |
Numeric scalar, the Gumbel dependence parameter |
Details
The Gumbel copula exhibits upper-tail dependence
\lambda_U = 2 - 2^{1/\theta} and no lower-tail dependence
(\lambda_L = 0). When \theta = 1, it reduces to the independence
copula with C(u_1,u_2)=u_1 u_2.
The CDF is
C(u_1,u_2;\theta)
= \exp\!\left(
-\left[(-\log u_1)^{\theta} + (-\log u_2)^{\theta}\right]^{1/\theta}
\right), \qquad \theta \ge 1.
Value
A numeric scalar: C(u_1,u_2;\theta).
References
Joe, H. (1997). Multivariate Models and Dependence Concepts. Chapman & Hall. Nelsen, R. B. (2006). An Introduction to Copulas (2nd ed.). Springer.
See Also
f_gumbel_copula_2d_pdf, f_clayton_copula_2d_pdf,
f_normal_copula_pdf, f_student_copula_pdf
Examples
f_gumbel_copula_2d_cdf(c(0.5, 0.8), theta = 2)
f_gumbel_copula_2d_cdf(c(0.7, 0.7), theta = 1) # independence: ~0.49
Gumbel Copula PDF (2-Dimensional)
Description
Computes the bivariate Gumbel copula probability density function (PDF)
at (u_1,u_2) for dependence parameter \theta \ge 1.
Usage
f_gumbel_copula_2d_pdf(u, theta)
Arguments
u |
Numeric vector of length 2 with entries in |
theta |
Numeric scalar, the Gumbel dependence parameter |
Details
The PDF can be written as
c(u_1,u_2;\theta)
= C(u_1,u_2;\theta)\;
\frac{ \{[-\log u_1]\;[-\log u_2]\}^{\theta-1} }{u_1 u_2}\;
\left( (-\log u_1)^{\theta} + (-\log u_2)^{\theta} \right)^{1/\theta - 2}\;
\left( \left\{ (-\log u_1)^{\theta} + (-\log u_2)^{\theta} \right\}^{1/\theta}
+ \theta - 1 \right).
When \theta = 1, c(u_1,u_2;1) \equiv 1 (independence).
Value
A numeric scalar: c(u_1,u_2;\theta).
Note
Numerical stability may degrade as u_i \to 0^+ (large -\log u_i).
References
Joe, H. (1997). Multivariate Models and Dependence Concepts. Chapman & Hall. Nelsen, R. B. (2006). An Introduction to Copulas (2nd ed.). Springer.
See Also
f_gumbel_copula_2d_cdf, f_clayton_copula_2d_pdf,
f_normal_copula_pdf, f_student_copula_pdf
Examples
f_gumbel_copula_2d_pdf(c(0.5, 0.8), theta = 2)
f_gumbel_copula_2d_pdf(c(0.7, 0.7), theta = 1) # independence: 1
Multivariate Normal Copula PDF
Description
Computes the probability density function (PDF) of the Gaussian (normal)
copula at a specified point u \in [0,1]^N, given mean vector
\mu and covariance matrix \Sigma of the underlying multivariate
normal distribution.
Usage
f_normal_copula_pdf(u, mu, Sigma)
Arguments
u |
Numeric vector of length |
mu |
Numeric vector of length |
Sigma |
Numeric positive-definite |
Details
The Gaussian copula density is
c(u; \mu, \Sigma)
= \frac{
\phi_N\!\left( \Phi^{-1}(u); \mu, \Sigma \right)
}{
\prod_{i=1}^N \phi_1\!\left( \Phi^{-1}(u_i); \mu_i, \sigma_i^2 \right)
},
where \phi_N and \phi_1 are multivariate and univariate normal
densities respectively, and \Phi^{-1} denotes the inverse normal CDF
applied componentwise. The resulting function is a valid copula density on
the unit hypercube [0,1]^N.
Typically, the copula is defined for \mu = 0 and correlation matrix
R, but the implementation here generalizes to arbitrary mean and
covariance.
Value
A numeric scalar: the value of the Gaussian copula density
c(u; \mu, \Sigma) at the point u. The value is returned
as a plain numeric scalar (not a 1 \times 1 matrix).
References
Joe, H. (1997). *Multivariate Models and Dependence Concepts.* Chapman & Hall. Nelsen, R. B. (2006). *An Introduction to Copulas* (2nd ed.). Springer. McNeil, A. J., Frey, R., & Embrechts, P. (2015). *Quantitative Risk Management.* Princeton University Press.
See Also
f_student_copula_pdf, f_clayton_copula_2d_pdf,
f_gumbel_copula_2d_pdf
Examples
# Example: 2D Gaussian copula
Sigma <- matrix(c(1, 0.7, 0.7, 1), 2, 2)
mu <- c(0, 0)
f_normal_copula_pdf(c(0.5, 0.8), mu, Sigma)
# Compare with independence (Sigma = I)
f_normal_copula_pdf(c(0.5, 0.8), mu, diag(2))
Portfolio Co-Moments (Variance, Co-Skewness, Co-Kurtosis)
Description
Compute the portfolio's centred 2nd, 3rd and 4th moments (variance, co-skewness, co-kurtosis) from the asset-level co-moment matrices and a weight vector.
Usage
f_portfolio_moments(w, M2 = NULL, M3 = NULL, M4 = NULL)
Arguments
w |
Numeric vector of length |
M2 |
Optional |
M3 |
Optional |
M4 |
Optional |
Details
The three quantities are defined as
m_2(w) = w' M_2 w, \quad
m_3(w) = w' M_3 (w \otimes w), \quad
m_4(w) = w' M_4 (w \otimes w \otimes w),
where \otimes denotes the Kronecker product. These are the
building blocks of the mean-variance-skewness-kurtosis (MVSK)
framework of Jondeau, Poon and Rockinger (2007).
The function is a thin, exported wrapper around the package's
internal helpers .portm2, .portm3, .portm4
(which themselves replace the unexported
PerformanceAnalytics:::portm* family). It exists so the
textbook can demonstrate co-moment computation without reaching
into non-exported symbols of the package via :::.
Value
A named list with components m2, m3, m4
(NULL for any component whose corresponding co-moment matrix
was not supplied).
References
Jondeau, E., Poon, S.-H., & Rockinger, M. (2007). Financial Modeling Under Non-Gaussian Distributions. Springer.
Examples
set.seed(1)
R <- matrix(rnorm(200 * 4), 200, 4)
d <- ncol(R)
M2 <- cov(R)
w <- rep(1 / d, d)
# Variance of the equal-weighted portfolio:
f_portfolio_moments(w, M2 = M2)$m2
# Co-skewness / co-kurtosis matrices in d x d^2 / d x d^3 form (e.g. from
# PerformanceAnalytics::M3.MM() / M4.MM()) can be passed as M3, M4.
Maximize Truncated MVSK Utility with Box & Budget Constraints
Description
Solves for portfolio weights that (approximately) maximize expected utility
using a fourth-order moment expansion in mean–variance–skewness–kurtosis
(MVSK). The problem is solved via SLSQP with the constraints
\sum_i w_i = 1 and 0 \le w_i \le w_max.
Usage
f_ptf_max_U(gamma, w_max, M1, M2, M3, M4)
Arguments
gamma |
Non-negative numeric scalar risk-aversion parameter. |
w_max |
Numeric scalar in |
M1 |
Numeric vector of expected returns (length |
M2 |
Numeric |
M3 |
Numeric |
M4 |
Numeric |
Details
The objective implemented is the negative of the truncated MVSK utility series, so minimizing it is equivalent to maximizing the utility:
\text{EU}(w) \approx
\mu_p - \frac{\gamma}{2}\sigma_p^2
+ \frac{\gamma(\gamma+1)}{6}\,S_p
- \frac{\gamma(\gamma+1)(\gamma+2)}{24}\,K_p,
where \mu_p, \sigma_p^2, S_p, K_p are the portfolio's first four
centralized moments and \gamma \ge 0 is a risk-aversion parameter.
The equality constraint is enforced via eval_g_eq and box constraints
via lb/ub. Gradients are supplied analytically using
internal helper functions '.derportm2', '.derportm3', and '.derportm4' defined
in 'portfolio-moments.R'.
Value
A list with:
wNumeric vector of optimal portfolio weights (length
d).EUScalar: value of the (approximate) expected utility at
w(sign-corrected).
Implementation note
Portfolio moment calculations (portm2/3/4 and their gradients) are
performed by internal helpers in ‘R/portfolio-moments.R’, vendored
from the standard kronecker-product formulas (Jondeau et al., 2007).
M3 and M4 must be co-moment matrices (d \times d^2
and d \times d^3), not higher-dimensional arrays.
References
Jondeau, E., Poon, S.-H., & Rockinger, M. (2007). Financial Modeling Under Non-Gaussian Distributions. Harvey, C. R., Liechty, J. C., Liechty, M. W., & Müller, P. (2010). Portfolio selection with higher moments.
Examples
set.seed(1)
d <- 3
M1 <- c(0.06, 0.08, 0.07)
A <- matrix(rnorm(d*d), d); M2 <- crossprod(A)/d
M3 <- matrix(0, d, d^2)
M4 <- matrix(0, d, d^3)
res <- f_ptf_max_U(gamma = 5, w_max = 0.8, M1, M2, M3, M4)
res$w; res$EU
Multivariate Student-t Copula PDF
Description
Computes the probability density function (PDF) of the multivariate
Student-t copula at a specified point u \in [0,1]^N, given
location vector \mu, scatter matrix \Sigma, and degrees of freedom
\nu.
Usage
f_student_copula_pdf(u, mu, Sigma, nu)
Arguments
u |
Numeric vector of length |
mu |
Numeric vector of length |
Sigma |
Numeric |
nu |
Positive numeric scalar: degrees of freedom of the Student- |
Details
The multivariate Student-t copula density is given by
c(u; \mu, \Sigma, \nu)
= \frac{
t_N\!\left(t_{\nu}^{-1}(u); \mu, \Sigma, \nu \right)
}{
\prod_{i=1}^N t_1\!\left(t_{\nu}^{-1}(u_i); \mu_i, \sigma_i^2, \nu \right)
},
where t_N and t_1 denote the multivariate and univariate Student-t
densities, respectively, and t_{\nu}^{-1} is the quantile function of
the univariate Student-t with \nu degrees of freedom.
For \nu \to \infty, this copula converges to the Gaussian copula.
Value
A numeric scalar: the value of the Student-t copula density
c(u; \mu, \Sigma, \nu) at u. The value is returned as a
plain numeric scalar (not a 1 \times 1 matrix).
References
Demarta, S., & McNeil, A. J. (2005). The t Copula and Related Copulas. *International Statistical Review*, 73(1), 111–129. Joe, H. (1997). *Multivariate Models and Dependence Concepts*. Chapman & Hall. Nelsen, R. B. (2006). *An Introduction to Copulas* (2nd ed.). Springer.
See Also
f_normal_copula_pdf, f_clayton_copula_2d_pdf,
f_gumbel_copula_2d_pdf
Examples
# Example: 2D t-copula density
mu <- c(0, 0)
Sigma <- matrix(c(1, 0.7, 0.7, 1), 2, 2)
f_student_copula_pdf(c(0.6, 0.8), mu, Sigma, nu = 5)
# Compare to Gaussian copula (nu large)
f_student_copula_pdf(c(0.6, 0.8), mu, Sigma, nu = 100)
Empirical Tail Dependence and Exceedance Correlation
Description
Estimates the empirical tail‐dependence coefficient and the
exceedance correlation between two series at a given quantile threshold
\alpha for either the lower or upper tail.
Usage
f_tail_dependence(x, y, alpha, side = c("lower", "upper"))
Arguments
x |
Numeric vector of length |
y |
Numeric vector of length |
alpha |
Numeric scalar in |
side |
Character string, either |
Details
The function classifies observations in the \alpha‐quantile tail of
each margin and computes:
the standard empirical tail‐dependence coefficient: the proportion of joint tail events conditional on
xbeing in its tail (lambda), andthe sample correlation between the values of
xandyfor which both lie in their respective tails (excorr).
If no joint tail events are found, lambda = 0 and
excorr = NA. If fewer than two joint-tail observations are available,
excorr is also NA (the sample correlation is undefined).
When the joint-tail subset is degenerate (e.g., x and y are
identical so that the subset has zero variance), cor
returns NA with a warning.
Value
A list with components:
lambdaEmpirical tail‐dependence coefficient. For
side = "lower":\hat{\lambda}_L = \frac{\#\{X < q_\alpha^X \text{ and } Y < q_\alpha^Y\}} {\#\{X < q_\alpha^X\}}.For
side = "upper":\hat{\lambda}_U = \frac{\#\{X > q_{1-\alpha}^X \text{ and } Y > q_{1-\alpha}^Y\}} {\#\{X > q_{1-\alpha}^X\}}.excorrExceedance correlation between
xandyin the joint tail (computed only if there are joint exceedances).
References
Joe, H. (1997). Multivariate Models and Dependence Concepts. Chapman & Hall. Embrechts, P., McNeil, A. J., & Straumann, D. (2002). Correlation and dependence in risk management. Risk Management: Value at Risk and Beyond. Cambridge University Press.
See Also
Examples
set.seed(1)
x <- rnorm(1000)
y <- 0.7 * x + sqrt(1 - 0.7^2) * rnorm(1000)
f_tail_dependence(x, y, alpha = 0.05)
f_tail_dependence(x, y, alpha = 0.05, side = "upper")