Title: | Financial Risk Modelling and Portfolio Optimisation with R |
---|---|
Description: | Accompanying package of the book 'Financial Risk Modelling and Portfolio Optimisation with R', second edition. The data sets used in the book are contained in this package. |
Authors: | Bernhard Pfaff [aut, cre] |
Maintainer: | Bernhard Pfaff <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.4-1 |
Built: | 2025-01-29 02:36:35 UTC |
Source: | https://github.com/bpfaff/frapo |
Utility functions for returning a list of the included examples and displaying, executing, saving and editing the example codes are provided.
listEx() showEx(Example) saveEx(Example) editEx(Example, ...) runEx(Example, ...)
listEx() showEx(Example) saveEx(Example) editEx(Example, ...) runEx(Example, ...)
Example |
|
... |
Ellipsis argument. See details. |
The ellipsis arguments in the function editEx()
are passed down
to the function file.edit()
. If the option editor
is
unset and/or a different editor shall be employed for openening the
example code, then the ellipsis argument can be utilised by
editor = "foo"
, wherey foo
is the name of the editor to
be used.
The ellipsis arguments in the function runEx()
are passed down
to the function source()
.
listEx
Returns a character vector of the examples' names.showEx
Returns the example of of Example
to the console.saveEx
Returns a logical
whether the saving of the R code example into
the working directory was successful.editEx
Opens a copy of the example code in an editor.runEx
Executes the example code.
Bernhard Pfaff
## Not run: listEx() showEx(Example = "Part1Chapter3Ex2") saveEx(Example = "Part1Chapter3Ex2") runEx(Example = "Part1Chapter3Ex2", echo = TRUE) editEx(Example = listEx()[1], editor = "emacs") ## End(Not run)
## Not run: listEx() showEx(Example = "Part1Chapter3Ex2") saveEx(Example = "Part1Chapter3Ex2") runEx(Example = "Part1Chapter3Ex2", echo = TRUE) editEx(Example = listEx()[1], editor = "emacs") ## End(Not run)
The values of a series that are absolute greater than min
and/or max
are capped to these specified values.
capser(y, min, max)
capser(y, min, max)
y |
Objects of classes: numeric, matrix, data.frame, ts, mts, and timeSeries are supported. |
min |
Numeric, minimum value for the series. |
max |
Numeric, maximim value for the series. |
An object of the same class as y
, containing the truncated series.
The calculation is applied per column of the data.frame and only if all columns are numeric.
The calculation is applied per column of the matrix.
The calculation is applied per column of the mts object. The attributes are preserved and an object of the same class is returned.
Calculation of the es trend.
The calculation is applied per column of the timeSeries object and an object of the same class is returned.
Calculation of the es trend. The attributes are preserved and an object of the same class is returned.
Calculation of the es trend. The attributes are preserved and an object of the same class is returned.
Calculation of the es trend. The attributes are preserved and an object of the same class is returned.
Bernhard Pfaff
trdbilson
, trdbinary
, trdes
,
trdhp
, trdsma
, trdwma
data(StockIndex) y <- StockIndex[, "SP500"] cs <- capser(y, min = 100, max = 200) head(cs)
data(StockIndex) y <- StockIndex[, "SP500"] cs <- capser(y, min = 100, max = 200) head(cs)
These functions compute the diversification ratio, the volatility weighted average correlation and concentration ratio of a portfolio.
dr(weights, Sigma) cr(weights, Sigma) rhow(weights, Sigma)
dr(weights, Sigma) cr(weights, Sigma) rhow(weights, Sigma)
weights |
Vector: portfolio weights. |
Sigma |
Matrix: Variance-covariance matrix of portfolio assets. |
The diversification ratio of a portfolio is defined as:
for a portfolio of assets and
signify the
weight of the i-th asset and
its standard deviation and
the variance-covariance matrix of asset returns. The
diversification ratio is therefore the weighted average of the assets'
volatilities divided by the portfolio volatility.
The concentration ration is defined as:
and the volatility-weighted average correlation of the assets as:
The following equation between these measures does exist:
numeric
, the value of the diversification measure.
Bernhard Pfaff
Choueifaty, Y. and Coignard, Y. (2008): Toward Maximum Diversification, Journal of Portfolio Management, Vol. 34, No. 4, 40–51.
Choueifaty, Y. and Coignard, Y. and Reynier, J. (2011): Properties of the Most Diversified Portfolio, Working Paper, http://papers.ssrn.com
data(MultiAsset) Rets <- returnseries(MultiAsset, method = "discrete", trim = TRUE) w <- Weights(PMD(Rets)) V <- cov(Rets) DR <- dr(w, V) CR <- cr(w, V) RhoW <- rhow(w, V) test <- 1 / sqrt(RhoW * (1 - CR) + CR) all.equal(DR, test)
data(MultiAsset) Rets <- returnseries(MultiAsset, method = "discrete", trim = TRUE) w <- Weights(PMD(Rets)) V <- cov(Rets) DR <- dr(w, V) CR <- cr(w, V) RhoW <- rhow(w, V) test <- 1 / sqrt(RhoW * (1 - CR) + CR) all.equal(DR, test)
Daily spot rates of major currencies against the EUR.
data(ESCBFX)
data(ESCBFX)
A data frame with 3,427 daily observations of the spot currency rates rates AUD, CAD, CHF, GBP, HKD, JPY and USD against EUR. The sample starts in 1999-01-04 and ends in 2012-04-04.
The data has been retrieved from the Statistical Data Warehouse (SDW) Internet-Site of the ECB. In case of missing data entries due to holidays, the last observed data point has been carried forward.
data(ESCBFX)
data(ESCBFX)
Weekly price data of 48 EURO STOXX 50 constituents.
data(EuroStoxx50)
data(EuroStoxx50)
A data frame with 265 weekly observations of 48 members of the EURO STOXX 50 index. The sample starts at 2003-03-03 and ends in 2008-03-24.
The data set was used in the reference below. The authors adjusted the price data for dividends and have removed stocks if two or more consecutive missing values were found. In the remaining cases the NA entries have been replaced by interpolated values.
http://host.uniroma3.it/docenti/cesarone/DataSets.htm
http://finance.yahoo.com/
Cesarone, F. and Scozzari, A. and Tardella, F.: Portfolio selection
problems in practice: a comparison between linear and quadratic
optimization models, Working Paper, Universita degli Studi Roma Tre,
Universita Telematica delle Scienze Umane and Universita di Roma, July
2010.
http://arxiv.org/ftp/arxiv/papers/1105/1105.3594.pdf
data(EuroStoxx50)
data(EuroStoxx50)
Weekly price data of 79 FTSE 100 constituents.
data(FTSE100)
data(FTSE100)
A data frame with 265 weekly observations of 79 members of the FTSE 100 index. The sample starts at 2003-03-03 and ends in 2008-03-24.
The data set was used in the reference below. The authors adjusted the price data for dividends and have removed stocks if two or more consecutive missing values were found. In the remaining cases the NA entries have been replaced by interpolated values.
http://host.uniroma3.it/docenti/cesarone/DataSets.htm
http://finance.yahoo.com/
Cesarone, F. and Scozzari, A. and Tardella, F.: Portfolio selection
problems in practice: a comparison between linear and quadratic
optimization models, Working Paper, Universita degli Studi Roma Tre,
Universita Telematica delle Scienze Umane and Universita di Roma, July
2010.
http://arxiv.org/ftp/arxiv/papers/1105/1105.3594.pdf
data(FTSE100)
data(FTSE100)
Weekly price data of the Hang Seng index and 31 constituents.
data(INDTRACK1)
data(INDTRACK1)
A data frame with 291 weekly observations of the index and 31 members of the Hang Seng index. The sample starts in March 1991 and ends in September 1997.
The data set was used in the first two references below. Stocks with missing values during the sample period have been discarded. The data was downloaded from DATASTREAM and has been anonymized. The first columne refers to the index data itself. See the attached license file that is part of this package: ‘BeasleyLicence’.
http://people.brunel.ac.uk/~mastjjb/jeb/info.html
http://people.brunel.ac.uk/~mastjjb/jeb/orlib/legal.html
Canakgoz, N.A. and J.E. Beasley (2008), Mixed-integer programming
approaches for index tracking and enhanced indexation, European
Journal of Operational Research, Vol. 196, 384–399.
Beasley, J.E. and N. Meade and T.-J. Chang (2003), An evolutionary
heuristic for the index tracking problem, European Journal of
Operational Research, Vol. 148, 621–643.
Beasley, J. E. (1990), OR-Library: Distributing Test Problems by
Electronic Mail, Journal of the Operational Research Society,
Vol. 41, No. 11, 1069–1072.
data(INDTRACK1)
data(INDTRACK1)
Weekly price data of the DAX 100 and 85 constituents.
data(INDTRACK2)
data(INDTRACK2)
A data frame with 291 weekly observations of the index and 85 members of the DAX 100 index. The sample starts in March 1991 and ends in September 1997.
The data set was used in the first two references below. Stocks with missing values during the sample period have been discarded. The data was downloaded from DATASTREAM and has been anonymized. The first columne refers to the index data itself. See the attached license file that is part of this package: ‘BeasleyLicence’.
http://people.brunel.ac.uk/~mastjjb/jeb/info.html
http://people.brunel.ac.uk/~mastjjb/jeb/orlib/legal.html
Canakgoz, N.A. and J.E. Beasley (2008), Mixed-integer programming
approaches for index tracking and enhanced indexation, European
Journal of Operational Research, Vol. 196, 384–399.
Beasley, J.E. and N. Meade and T.-J. Chang (2003), An evolutionary
heuristic for the index tracking problem, European Journal of
Operational Research, Vol. 148, 621–643.
Beasley, J. E. (1990), OR-Library: Distributing Test Problems by
Electronic Mail, Journal of the Operational Research Society,
Vol. 41, No. 11, 1069–1072.
data(INDTRACK2)
data(INDTRACK2)
Weekly price data of of the FTSE 100 index and 89 constituents.
data(INDTRACK3)
data(INDTRACK3)
A data frame with 291 weekly observations of of the index and 89 members of the FTSE 100 index. The sample starts in March 1991 and ends in September 1997.
The data set was used in the first two references below. Stocks with missing values during the sample period have been discarded. The data was downloaded from DATASTREAM and has been anonymized. The first columne refers to the index data itself. See the attached license file that is part of this package: ‘BeasleyLicence’.
http://people.brunel.ac.uk/~mastjjb/jeb/info.html
http://people.brunel.ac.uk/~mastjjb/jeb/orlib/legal.html
Canakgoz, N.A. and J.E. Beasley (2008), Mixed-integer programming
approaches for index tracking and enhanced indexation, European
Journal of Operational Research, Vol. 196, 384–399.
Beasley, J.E. and N. Meade and T.-J. Chang (2003), An evolutionary
heuristic for the index tracking problem, European Journal of
Operational Research, Vol. 148, 621–643.
Beasley, J. E. (1990), OR-Library: Distributing Test Problems by
Electronic Mail, Journal of the Operational Research Society,
Vol. 41, No. 11, 1069–1072.
data(INDTRACK3)
data(INDTRACK3)
Weekly price data of S&P 100 index and 98 constituents.
data(INDTRACK4)
data(INDTRACK4)
A data frame with 291 weekly observations of the index 98 members of the S&P 100 index. The sample starts in March 1991 and ends in September 1997.
The data set was used in the first two references below. Stocks with missing values during the sample period have been discarded. The data was downloaded from DATASTREAM and has been anonymized. The first columne refers to the index data itself. See the attached license file that is part of this package: ‘BeasleyLicence’.
http://people.brunel.ac.uk/~mastjjb/jeb/info.html
http://people.brunel.ac.uk/~mastjjb/jeb/orlib/legal.html
Canakgoz, N.A. and J.E. Beasley (2008), Mixed-integer programming
approaches for index tracking and enhanced indexation, European
Journal of Operational Research, Vol. 196, 384–399.
Beasley, J.E. and N. Meade and T.-J. Chang (2003), An evolutionary
heuristic for the index tracking problem, European Journal of
Operational Research, Vol. 148, 621–643.
Beasley, J. E. (1990), OR-Library: Distributing Test Problems by
Electronic Mail, Journal of the Operational Research Society,
Vol. 41, No. 11, 1069–1072.
data(INDTRACK4)
data(INDTRACK4)
Weekly price data of Nikkei 225 index and 225 constituents.
data(INDTRACK5)
data(INDTRACK5)
A data frame with 291 weekly observations of the index and 225 members of the Nikkei 225 index. The sample starts in March 1991 and ends in September 1997.
The data set was used in the first two references below. Stocks with missing values during the sample period have been discarded. The data was downloaded from DATASTREAM and has been anonymized. The first columne refers to the index data itself. See the attached license file that is part of this package: ‘BeasleyLicence’.
http://people.brunel.ac.uk/~mastjjb/jeb/info.html
http://people.brunel.ac.uk/~mastjjb/jeb/orlib/legal.html
Canakgoz, N.A. and J.E. Beasley (2008), Mixed-integer programming
approaches for index tracking and enhanced indexation, European
Journal of Operational Research, Vol. 196, 384–399.
Beasley, J. E. (1990), OR-Library: Distributing Test Problems by
Electronic Mail, Journal of the Operational Research Society,
Vol. 41, No. 11, 1069–1072.
data(INDTRACK5)
data(INDTRACK5)
Weekly price data of S&P 500 index and 457 constituents.
data(INDTRACK6)
data(INDTRACK6)
A data frame with 291 weekly observations of the index and 457 members of the S&P 500 index. The sample starts in March 1991 and ends in September 1997.
The data set was used in the first two references below. Stocks with missing values during the sample period have been discarded. The data was downloaded from DATASTREAM and has been anonymized. The first columne refers to the index data itself. See the attached license file that is part of this package: ‘BeasleyLicence’.
http://people.brunel.ac.uk/~mastjjb/jeb/info.html
http://people.brunel.ac.uk/~mastjjb/jeb/orlib/legal.html
Canakgoz, N.A. and J.E. Beasley (2008), Mixed-integer programming
approaches for index tracking and enhanced indexation, European
Journal of Operational Research, Vol. 196, 384–399.
Beasley, J. E. (1990), OR-Library: Distributing Test Problems by
Electronic Mail, Journal of the Operational Research Society,
Vol. 41, No. 11, 1069–1072.
data(INDTRACK6)
data(INDTRACK6)
Weekly price data of 226 MIBTEL constituents.
data(MIBTEL)
data(MIBTEL)
A data frame with 265 weekly observations of 226 members of the Milano Indice Borsa Telematica index. The sample starts at 2003-03-03 and ends in 2008-03-24.
The data set was used in the reference below. The authors adjusted the price data for dividends and have removed stocks if two or more consecutive missing values were found. In the remaining cases the NA entries have been replaced by interpolated values.
http://host.uniroma3.it/docenti/cesarone/DataSets.htm
http://finance.yahoo.com/
Cesarone, F. and Scozzari, A. and Tardella, F.: Portfolio selection
problems in practice: a comparison between linear and quadratic
optimization models, Working Paper, Universita degli Studi Roma Tre,
Universita Telematica delle Scienze Umane and Universita di Roma, July
2010.
http://arxiv.org/ftp/arxiv/papers/1105/1105.3594.pdf
data(MIBTEL)
data(MIBTEL)
This function returns the marginal contributions to portfolio risk, whereby the latter is defined in terms of the portfolio standard deviation.
mrc(weights, Sigma, percentage = TRUE)
mrc(weights, Sigma, percentage = TRUE)
weights |
Vector: portfolio weights. |
Sigma |
Matrix: Variance-covariance matrix of portfolio assets. |
percentage |
|
The marginal contributions to risk are computed for a given dispersion matrix and weight vector.
numeric
, the marginal risk contributions of the portfolio's
asset.
Bernhard Pfaff
Month-end price data of stock and bond indices and gold.
data(MultiAsset)
data(MultiAsset)
A data frame with 85 month-end observations of stock and bond indices and gold, represented by the ETF SPDR Gold. The sample starts at 2004-11-30 and ends in 2011-11-30.
The data set has been obtained from Yahoo Finance and hereby the unadjusted closing prices have been retrieved. If a month-end value was not reported, the value of the previous day has been used. The Yahoo mnemonics with the respective item description are listed below:
United States: S \& P 500 Index (Equity)
United States: Russell 3000 Index (Equity)
Germany: DAX (XETRA) Index (Equity)
United Kingdom: FTSE 100 Index (Equity)
Japan: Nikkei 225 Index (Equity)
iShares: MSCI Emerging Markets Index (Equity)
United States: Dow Jones CBOT Treasury Index (Bonds)
Germany: REX-Performance Index (Bonds)
United Kingdom: Gilt All Index (Bonds)
United States: SPDR Gold Shares (Commodities)
data(MultiAsset)
data(MultiAsset)
Weekly price data of 2,196 NASDAQ constituents.
data(NASDAQ)
data(NASDAQ)
A data frame with 265 weekly observations of 2196 members of the NASDAQ index. The sample starts at 2003-03-03 and ends in 2008-03-24.
The data set was used in the reference below. The authors adjusted the price data for dividends and have removed stocks if two or more consecutive missing values were found. In the remaining cases the NA entries have been replaced by interpolated values.
http://host.uniroma3.it/docenti/cesarone/DataSets.htm
http://finance.yahoo.com/
Cesarone, F. and Scozzari, A. and Tardella, F.: Portfolio selection
problems in practice: a comparison between linear and quadratic
optimization models, Working Paper, Universita degli Studi Roma Tre,
Universita Telematica delle Scienze Umane and Universita di Roma, July
2010.
http://arxiv.org/ftp/arxiv/papers/1105/1105.3594.pdf
data(NASDAQ)
data(NASDAQ)
This function returns the result of a long-only portfolio optimization whereby the portfolio's (historic) average draw down is constrained to an upper limit.
PAveDD(PriceData, AveDD = 0.1, softBudget = FALSE, ...)
PAveDD(PriceData, AveDD = 0.1, softBudget = FALSE, ...)
PriceData |
A rectangular array of price data. |
AveDD |
Numeric, the upper bound of the average portfolio draw down. |
softBudget |
Logical, whether the budget constraint shall be implemented as a soft constraint, i.e. the sum of the weights can be less than one. The default is to use an equality constraint. |
... |
Arguments are passed down to |
This function implements a long-only portfolio optimisation with an average draw down constraint (see references below). The problem can be stated in the form of a linear program and GLPK is used as solver.
An object of formal class "PortAdd"
.
A warning is issued in case the solver had exit status not equal to zero.
Bernhard Pfaff
Chekhlov, A. and Uryasev, S. and Zabarankin, M., Portfolio Optimization with Drawdown Constraints, Department of Industrial and Systems Engineering, University of Florida, Research Report 2000-5, 2000, Gainesville, FL. Chekhlov, A. and Uryasev, S. and Zabarankin, M., Drawdown Measure in Portfolio Optimization, International Journal of Theoretical and Applied Finance, 2005, 8(1), 13–58.
"PortSol"
, "PortAdd"
,
"PortDD"
, PMaxDD
,
PCDaR
, PMinCDaR
## Not run: data(StockIndex) popt <- PAveDD(PriceData = StockIndex, AveDD = 0.1, softBudget = TRUE) ## End(Not run)
## Not run: data(StockIndex) popt <- PAveDD(PriceData = StockIndex, AveDD = 0.1, softBudget = TRUE) ## End(Not run)
This function returns the result of a long-only portfolio optimization whereby the portfolio's (historic) conditional draw down at risk is constrained to an upper limit.
PCDaR(PriceData, alpha = 0.95, bound = 0.05, softBudget = FALSE, ...)
PCDaR(PriceData, alpha = 0.95, bound = 0.05, softBudget = FALSE, ...)
PriceData |
A rectangular array of price data. |
alpha |
Numeric, the confidence level for which the conditional draw down shall be computed. |
bound |
Numeric, the upper bound of the conditional draw down. |
softBudget |
Logical, whether the budget constraint shall be implemented as a soft constraint, i.e. the sum of the weights can be less than one. The default is to use an equality constraint. |
... |
Arguments are passed down to |
This function implements a long-only portfolio optimisation with a CDaR constraint (see references below). The problem can be stated in the form of a linear program and GLPK is used as solver.
An object of formal class "PortAdd"
.
A warning is issued in case the solver had exit status not equal to zero.
Bernhard Pfaff
Chekhlov, A. and Uryasev, S. and Zabarankin, M., Portfolio Optimization with Drawdown Constraints, Department of Industrial and Systems Engineering, University of Florida, Research Report 2000-5, 2000, Gainesville, FL. Chekhlov, A. and Uryasev, S. and Zabarankin, M., Drawdown Measure in Portfolio Optimization, International Journal of Theoretical and Applied Finance, 2005, 8(1), 13–58.
"PortSol"
, "PortCdd"
,
"PortDD"
, PMaxDD
,
PAveDD
, PMinCDaR
## Not run: data(StockIndex) popt <- PCDaR(PriceData = StockIndex, alpha = 0.95, bound = 0.1, softBudget = TRUE) ## End(Not run)
## Not run: data(StockIndex) popt <- PCDaR(PriceData = StockIndex, alpha = 0.95, bound = 0.1, softBudget = TRUE) ## End(Not run)
This function solves for equal risk contributed portfolio weights.
PERC(Sigma, par = NULL, percentage = TRUE, optctrl = ctrl(), ...)
PERC(Sigma, par = NULL, percentage = TRUE, optctrl = ctrl(), ...)
Sigma |
Matrix, the variance-covariance matrix of asset returns |
par |
Vector, the initial values of the weights. |
percentage |
Logical, whether the weights shall be returned as decimals or percentages (default). |
optctrl |
Object of class |
... |
Ellipsis argument is passed down to |
The objective function is the standard deviation of the marginal risk contributions, which is minimal, i.e. zero, if all contributions are equal. The weights are rescaled to sum to unity.
An object of formal class "PortSol"
.
The optimisation is conducted by calling nlminb()
. Hereby, the
arguments lower = 0
and upper = 1
have been specified.
Bernhard Pfaff
Maillard, S. and Roncalli, T. and Teiletche, J.: The Properties of Equally Weighted Risk Contribution Portfolios, Journal of Portfolio Management, Vol. 36, No. 4, Summer 2010, 60–70.
"PortSol"
data(MultiAsset) Rets <- returnseries(MultiAsset, method = "discrete", trim = TRUE, percentage = TRUE) V <- cov(Rets) ERC <- PERC(V) ERC w <- Weights(ERC) w * V
data(MultiAsset) Rets <- returnseries(MultiAsset, method = "discrete", trim = TRUE, percentage = TRUE) V <- cov(Rets) ERC <- PERC(V) ERC w <- Weights(ERC) w * V
This function returns the solution of the global minimum variance portfolio (long-only).
PGMV(Returns, percentage = TRUE, optctrl = ctrl(), ...)
PGMV(Returns, percentage = TRUE, optctrl = ctrl(), ...)
Returns |
A rectangular array of return data. |
percentage |
Logical, whether the weights shall be returned as decimals or percentages (default). |
optctrl |
Object of class |
... |
Arguments are passed down to |
An object of formal class "PortSol"
.
The optimisation is conducted by calling cccp()
.
Bernhard Pfaff
"PortSol"
data(MultiAsset) Rets <- returnseries(MultiAsset, method = "discrete", trim = TRUE) PGMV(Rets)
data(MultiAsset) Rets <- returnseries(MultiAsset, method = "discrete", trim = TRUE) PGMV(Rets)
plot
in Package graphics
Additional arguments to the plot
-method pertinent to the
defined S4-classes in this package are detailed below.
## S4 method for signature 'PortDD' plot(x, main = NULL, xlab = NULL, ylab = NULL, col = c("black", "red"), grid = TRUE, invert = TRUE, ...)
## S4 method for signature 'PortDD' plot(x, main = NULL, xlab = NULL, ylab = NULL, col = c("black", "red"), grid = TRUE, invert = TRUE, ...)
x |
|
main |
|
xlab |
|
ylab |
|
col |
|
grid |
|
invert |
|
... |
Ellipsis argument is passed to the generic |
Bernhard Pfaff
This function returns the result of a long-only portfolio optimization whereby the portfolio's (historic) draw down is constrained to an upper limit.
PMaxDD(PriceData, MaxDD = 0.1, softBudget = FALSE, ...)
PMaxDD(PriceData, MaxDD = 0.1, softBudget = FALSE, ...)
PriceData |
A rectangular array of price data. |
MaxDD |
Numeric, the upper bound of the maximum draw down. |
softBudget |
Logical, whether the budget constraint shall be implemented as a soft constraint, i.e. the sum of the weights can be less than one. The default is to use an equality constraint. |
... |
Arguments are passed down to |
This function implements a long-only portfolio optimisation with a maximum draw down constraint (see references below). The problem can be stated in the form of a linear program and GLPK is used as solver.
An object of formal class "PortMdd"
.
A warning is issued in case the solver had exit status not equal to zero.
Bernhard Pfaff
Chekhlov, A. and Uryasev, S. and Zabarankin, M., Portfolio Optimization with Drawdown Constraints, Department of Industrial and Systems Engineering, University of Florida, Research Report 2000-5, 2000, Gainesville, FL. Chekhlov, A. and Uryasev, S. and Zabarankin, M., Drawdown Measure in Portfolio Optimization, International Journal of Theoretical and Applied Finance, 2005, 8(1), 13–58.
"PortSol"
, "PortMdd"
,
"PortDD"
, PCDaR
,
PAveDD
, PMinCDaR
## Not run: data(StockIndex) popt <- PMaxDD(PriceData = StockIndex, MaxDD = 0.1, softBudget = TRUE) ## End(Not run)
## Not run: data(StockIndex) popt <- PMaxDD(PriceData = StockIndex, MaxDD = 0.1, softBudget = TRUE) ## End(Not run)
This function returns the solution of the most diversified portfolio (long-only).
PMD(Returns, percentage = TRUE, optctrl = ctrl(),...)
PMD(Returns, percentage = TRUE, optctrl = ctrl(),...)
Returns |
A rectangular array of return data. |
percentage |
Logical, whether the weights shall be returned as decimals or percentages (default). |
optctrl |
Object of class |
... |
Arguments are passed down to |
The optimisation problem is akin to that of a global minimum-variance portfolio, but instead of using the variance-covariance matrix of the asset returns, the correlation matrix is utilised as dispersion measure. The weights are then recovered by rescaling the optimal solution with the assets' standard deviations and normalizing, such that the weights sum to one.
An object of formal class "PortSol"
.
The optimisation is conducted by calling cccp()
.
Bernhard Pfaff
Choueifaty, Y. and Coignard, Y. (2008): Toward Maximum Diversification, Journal of Portfolio Management, Vol. 34, No. 4, 40–51.
Choueifaty, Y. and Coignard, Y. and Reynier, J. (2011): Properties of the Most Diversified Portfolio, Working Paper, http://papers.ssrn.com
"PortSol"
data(MultiAsset) Rets <- returnseries(MultiAsset, method = "discrete", trim = TRUE) PMD(Rets)
data(MultiAsset) Rets <- returnseries(MultiAsset, method = "discrete", trim = TRUE) PMD(Rets)
This function returns the result of a long-only portfolio optimization whereby the portfolio's (historic) conditional draw down at risk is minimized.
PMinCDaR(PriceData, alpha = 0.95, softBudget = FALSE, ...)
PMinCDaR(PriceData, alpha = 0.95, softBudget = FALSE, ...)
PriceData |
A rectangular array of price data. |
alpha |
Numeric, the confidence level for which the conditional draw down shall be computed. |
softBudget |
Logical, whether the budget constraint shall be implemented as a soft constraint, i.e. the sum of the weights can be less than one. The default is to use an equality constraint. |
... |
Arguments are passed down to |
This function implements a long-only portfolio optimisation for a minimum conditional draw down at risk (see references below). The problem can be stated in the form of a linear program and GLPK is used as solver.
An object of formal class "PortAdd"
.
A warning is issued in case the solver had exit status not equal to zero.
Bernhard Pfaff
Chekhlov, A. and Uryasev, S. and Zabarankin, M., Portfolio Optimization with Drawdown Constraints, Department of Industrial and Systems Engineering, University of Florida, Research Report 2000-5, 2000, Gainesville, FL. Chekhlov, A. and Uryasev, S. and Zabarankin, M., Drawdown Measure in Portfolio Optimization, International Journal of Theoretical and Applied Finance, 2005, 8(1), 13–58.
"PortSol"
, "PortCdd"
,
"PortDD"
, PMaxDD
,
PAveDD
, PCDaR
## Not run: data(StockIndex) popt <- PMinCDaR(PriceData = StockIndex, alpha = 0.95, softBudget = FALSE) ## End(Not run)
## Not run: data(StockIndex) popt <- PMinCDaR(PriceData = StockIndex, alpha = 0.95, softBudget = FALSE) ## End(Not run)
This function computes the solution of a minimum tail dependent portfolio (long-only).
PMTD(Returns, method = c("EmpTC", "EVT"), k = NULL, percentage = TRUE, optctrl = ctrl(),...)
PMTD(Returns, method = c("EmpTC", "EVT"), k = NULL, percentage = TRUE, optctrl = ctrl(),...)
Returns |
A rectangular array of return data. |
method |
Character, the type of non-parametric estimation. |
k |
Integer, the threshold value for the order statistic. If left
|
percentage |
Logical, whether the weights shall be returned as decimals or percentages (default). |
optctrl |
Object of class |
... |
Arguments are passed down to |
Akin to the optimisation of a global minimum-variance portfolio, the
minimum tail dependennt portfolio is determined by replacing the
variance-covariance matrix with the matrix of the lower tail
dependence coefficients as returned by tdc
.
An object of formal class "PortSol"
.
The optimisation is conducted by calling cccp()
.
Bernhard Pfaff
data(StockIndex) Rets <- returnseries(StockIndex, method = "discrete", trim = TRUE, percentage = TRUE) PMTD(Rets)
data(StockIndex) Rets <- returnseries(StockIndex, method = "discrete", trim = TRUE, percentage = TRUE) PMTD(Rets)
"PortAdd"
This class is intended to hold the results from a portfolio optimisation with a constraint on its average draw down.
Objects can be created by calls of the form new("PortAdd",
...)
. This class extends the "PortSol"
class.
AveDD
:Numeric, the average draw down.
DrawDown
:timeSeries, the hsitoric portfolio's draw downs.
weights
:Numeric, vector of optimal weights.
opt
:List, the result of the call to GLPK.
type
:Character, the type of the optimized portfolio.
call
:The call to the function that created the object.
Class "PortSol"
, directly.
No methods defined with class "PortAdd" in the signature.
Bernhard Pfaff
"PortSol"
, "PortMdd"
,
"PortCdd"
showClass("PortAdd")
showClass("PortAdd")
"PortCdd"
This class is intended to hold the results from a portfolio optimisation with a constraint on its average draw down.
Objects can be created by calls of the form new("PortCdd",
...)
. This class extends the "PortSol"
class.
CDaR
:Numeric, the conditional draw down at risk.
thresh
:Numeric, threshold value for draw downs at the
level.
DrawDown
:timeSeries, the hsitoric portfolios draw downs.
weights
:Numeric, vector of optimal weights.
opt
:List, the result of the call to GLPK.
type
:Character, the type of the optimized portfolio.
call
:The call to the function that created the object.
Class "PortSol"
, directly.
No methods defined with class "PortCdd" in the signature.
Bernhard Pfaff
"PortSol"
, "PortMdd"
, "PortAdd"
showClass("PortCdd")
showClass("PortCdd")
"PortDD"
Class union of "PortAdd"
, "PortCdd"
and "PortMdd"
A virtual Class: No objects may be created from it.
signature(object = "PortDD")
: Returns the
portfolio draw downs.
signature(object = "PortDD")
: Time series plot of
draw downs.
This virtual class is intended for specifying methods that are common to all type of draw down portfolios.
Bernhard Pfaff
"PortAdd"
, "PortMdd"
,
"PortCdd"
, PMinCDaR
,
PCDaR
, PAveDD
, PMaxDD
showClass("PortDD")
showClass("PortDD")
"PortMdd"
This class is intended to hold the results from a portfolio optimisation with a constraint on its maximum draw down.
Objects can be created by calls of the form new("PortMdd",
...)
. This class extends the "PortSol"
class.
MaxDD
:Numeric, the maximum draw down.
DrawDown
:timeSeries, the hsitoric portfolio's draw downs.
weights
:Numeric, vector of optimal weights.
opt
:List, the result of the call to GLPK.
type
:Character, the type of the optimized portfolio.
call
:The call to the function that created the object.
Class "PortSol"
, directly.
No methods defined with class "PortMdd" in the signature.
Bernhard Pfaff
"PortSol"
, "PortAdd"
, "PortCdd"
showClass("PortMdd")
showClass("PortMdd")
"PortSol"
This class is intended to hold the results for the weights of an optimal portfolio. Currently, this class is used for minimum-variance and equal-risk-contributed portfolios. It can further be used to store the results of optimal factor weights according to one of the aforementioned portfolio types.
Objects can be created by calls of the form new("PortSol", ...)
.
weights
:Numeric, vector of optimal weights.
opt
:List, the result of the call to the optimizing function.
type
:Character, the type of the optimized portfolio.
call
:The call to the function that created the object.
signature(object = "PortSol")
: Returns the
portfolio type as text with the optimal weights from the object.
signature(object = "PortSol")
: Returns the
list object of the optimizer, i.e. the slot opt
from
the object.
signature(object = "PortSol")
: Returns the list
object of the optimizer, i.e. the slot weights
from
the object.
signature(object = "PortSol")
: updates object
by calling the issuing function with altered arguments.
Bernhard Pfaff
showClass("PortSol")
showClass("PortSol")
Either continuous returns or discrete returns can be converted into the other type.
returnconvert(y, convdir = c("cont2disc", "disc2cont"), percentage = TRUE)
returnconvert(y, convdir = c("cont2disc", "disc2cont"), percentage = TRUE)
y |
Objects of classes: numeric, matrix, data.frame, ts, mts, and timeSeries are supported. |
convdir |
Character, the type of return conversion. |
percentage |
Logical, if |
An object of the same class as y
, containing the converted returns.
The calculation is applied per column of the data.frame and only if all columns are numeric.
The calculation is applied per column of the matrix.
The calculation is applied per column of the mts object. The attributes are preserved and an object of the same class is returned.
Calculation of the returns.
The calculation is applied per column of the timeSeries object and an object of the same class is returned.
Calculation of the returns. The attributes are preserved and an object of the same class is returned.
Calculation of the returns. The attributes are preserved and an object of the same class is returned.
Calculation of the returns. The attributes are preserved and an object of the same class is returned.
Bernhard Pfaff
data(StockIndex) yc <- diff(log(StockIndex[, "SP500"])) * 100 yd <- returnseries(StockIndex[, "SP500"], method = "discrete", percentage = TRUE, trim = TRUE) yconv <- returnconvert(yd, convdir = "disc2cont", percentage = TRUE) all.equal(yc, yconv)
data(StockIndex) yc <- diff(log(StockIndex[, "SP500"])) * 100 yd <- returnseries(StockIndex[, "SP500"], method = "discrete", percentage = TRUE, trim = TRUE) yconv <- returnconvert(yd, convdir = "disc2cont", percentage = TRUE) all.equal(yc, yconv)
Either continuous returns or discrete returns are computed for an
object. The returns can be expressed as percenatges and the first NA
value can be trimmed.
returnseries(y, method = c("continuous", "discrete"), percentage = TRUE, trim = FALSE, compound = FALSE)
returnseries(y, method = c("continuous", "discrete"), percentage = TRUE, trim = FALSE, compound = FALSE)
y |
Objects of classes: numeric, matrix, data.frame, ts, mts, and timeSeries are supported. |
method |
Character, the type of return to be computed. |
percentage |
Logical, if |
trim |
Logical, if |
compound |
Logical, if |
An object of the same class as y
, containing the truncated series.
The calculation is applied per column of the data.frame and only if all columns are numeric.
The calculation is applied per column of the matrix.
The calculation is applied per column of the mts object. The attributes are preserved and an object of the same class is returned.
Calculation of the es trend.
The calculation is applied per column of the timeSeries object and an object of the same class is returned.
Calculation of the returns. The attributes are preserved and an object of the same class is returned.
Calculation of the returns. The attributes are preserved and an object of the same class is returned.
Calculation of the returns. The attributes are preserved and an object of the same class is returned.
Bernhard Pfaff
data(StockIndex) y <- StockIndex[, "SP500"] ret <- returnseries(y) head(ret)
data(StockIndex) y <- StockIndex[, "SP500"] ret <- returnseries(y) head(ret)
Weekly price data of 476 S&P 500 constituents.
data(SP500)
data(SP500)
A data frame with 265 weekly observations of 476 members of the S&P 500 index. The sample starts at 2003-03-03 and ends in 2008-03-24.
The data set was used in the reference below. The authors adjusted the price data for dividends and have removed stocks if two or more consecutive missing values were found. In the remaining cases the NA entries have been replaced by interpolated values.
http://host.uniroma3.it/docenti/cesarone/DataSets.htm
http://finance.yahoo.com/
Cesarone, F. and Scozzari, A. and Tardella, F.: Portfolio selection
problems in practice: a comparison between linear and quadratic
optimization models, Working Paper, Universita degli Studi Roma Tre,
Universita Telematica delle Scienze Umane and Universita di Roma, July
2010.
http://arxiv.org/ftp/arxiv/papers/1105/1105.3594.pdf
data(SP500)
data(SP500)
This function returns the square root of a quadratic and diagonalisable matrix.
sqrm(x, ...)
sqrm(x, ...)
x |
|
... |
The ellipsis argument is passed down to |
The computation of the square root of a matrix is based upon its eigen
values and corresponding eigen vectors. The square matrix is
diagonisable if there is a matrix
such that
,
whereby
is a diagonal matrix. This is only achieved if the eigen
vectors of the
matrix
constitute a basis of
dimension
. The square root of
is then
.
A matrix
object and a scalar in case a matrix has been
provided.
Bernhard Pfaff
data(StockIndex) S <- cov(StockIndex) SR <- sqrm(S) all.equal(crossprod(SR), S)
data(StockIndex) S <- cov(StockIndex) SR <- sqrm(S) all.equal(crossprod(SR), S)
Month-end price data of six stock indices.
data(StockIndex)
data(StockIndex)
A data frame with 240 month-end observations of six stock indices: SP 500, Nikkei 225, FTSE 100, CAC40, GDAX and Hang Seng index. The sample starts at 1991-07-31 and ends in 2011-06-30.
The data set has been obtained from Yahoo Finance and hereby the unadjusted closing prices have been retrieved.
data(StockIndex)
data(StockIndex)
Adjusted month-end price data of six stock indices.
data(StockIndexAdj)
data(StockIndexAdj)
A data frame with 240 month-end observations of six stock indices: SP 500, Nikkei 225, FTSE 100, CAC40, GDAX and Hang Seng index. The sample starts at 1991-07-31 and ends in 2011-06-30.
The data set has been obtained from Yahoo Finance and hereby the adjusted closing prices have been retrieved.
data(StockIndexAdj)
data(StockIndexAdj)
Adjusted daily price data of six stock indices.
data(StockIndexAdj)
data(StockIndexAdj)
A data frame with 5,202 daily observations of six stock indices: SP 500, Nikkei 225, FTSE 100, CAC40, GDAX and Hang Seng index. The sample starts at 1991-07-01 and ends in 2011-06-30.
The data set has been obtained from Yahoo Finance and hereby the adjusted closing prices have been retrieved.
data(StockIndexAdjD)
data(StockIndexAdjD)
This function returns the pairwise tail dependence coefficients
between series. The TDCs are estimated non-parametrically by
either the empirical tail copula or based on the stable
tail-dependence function.
tdc(x, method = c("EmpTC", "EVT"), lower = TRUE, k = NULL, ...)
tdc(x, method = c("EmpTC", "EVT"), lower = TRUE, k = NULL, ...)
x |
Matrix, or an object that can be coerced to it. |
method |
Character, the type of non-parametric estimation. |
lower |
Logical, if |
k |
Integer, the threshold value for the order statistic. If left
|
... |
Ellipsis, arguments are passed down to |
For a matrix or an object that can be coerced to it with ncol(x)
>= 2
, the pair wise tail dependencies are estimated
non-parametrically and returned as a symmetric matrix. The threshold
value k
is the upper/lower bound for the order statistics to be
considered. The diagonal elements are always equal to one, because a
series has a dependence of one with itself, of course.
A matrix with the tail dependent coefficients.
Bernhard Pfaff
Schmidt, R. and Stadtm\"uller, U., Nonparametric estimation of tail dependence, The Scandinavian Journal of Statistics, 33, 307–335.
data(StockIndex) Rets <- returnseries(StockIndex, method = "discrete", trim = TRUE, percentage = TRUE) tdc(Rets, method = "EmpTC") tdc(Rets, method = "EVT")
data(StockIndex) Rets <- returnseries(StockIndex, method = "discrete", trim = TRUE, percentage = TRUE) tdc(Rets, method = "EmpTC") tdc(Rets, method = "EVT")
Calculation of the Bilson Trend as a technical trading indicator.
trdbilson(y, exponent)
trdbilson(y, exponent)
y |
Objects of classes: numeric, matrix, data.frame, ts, mts, and timeSeries are supported. |
exponent |
Numeric, the value for |
The Bilson trend is calculated according to the formula:
An object of the same class as y
, containing the computed
Bilson trend values.
The calculation is applied per column of the data.frame and only if all columns are numeric.
The calculation is applied per column of the matrix.
The calculation is applied per column of the mts object. The attributes are preserved and an object of the same class is returned.
Calculation of the bilson trend.
The calculation is applied per column of the timeSeries object and an object of the same class is returned.
Calculation of the bilson trend. The attributes are preserved and an object of the same class is returned.
Calculation of the bilson trend. The attributes are preserved and an object of the same class is returned.
Calculation of the bilson trend. The attributes are preserved and an object of the same class is returned.
Bernhard Pfaff
trdbinary
, trdes
,
trdhp
, trdsma
,
trdwma
, capser
data(StockIndex) y <- StockIndex[, "SP500"] yret <- diff(log(y)) bilson <- trdbilson(yret, exponent = 2) head(bilson)
data(StockIndex) y <- StockIndex[, "SP500"] yret <- diff(log(y)) bilson <- trdbilson(yret, exponent = 2) head(bilson)
Calculation of the Binary Trend as a technical trading indicator.
trdbinary(y)
trdbinary(y)
y |
Objects of classes: numeric, matrix, data.frame, ts, mts, and timeSeries are supported. |
The Binary trend is calculated according to the formula:
An object of the same class as y
, containing the computed
Binary trend values.
The calculation is applied per column of the data.frame and only if all columns are numeric.
The calculation is applied per column of the matrix.
The calculation is applied per column of the mts object. The attributes are preserved and an object of the same class is returned.
Calculation of the binary trend.
The calculation is applied per column of the timeSeries object and an object of the same class is returned.
Calculation of the binary trend. The attributes are preserved and an object of the same class is returned.
Calculation of the binary trend. The attributes are preserved and an object of the same class is returned.
Calculation of the binary trend. The attributes are preserved and an object of the same class is returned.
Bernhard Pfaff
trdbilson
, trdes
,
trdhp
, trdsma
,
trdwma
, capser
data(StockIndex) y <- StockIndex[, "SP500"] yret <- diff(log(y)) binary <- trdbinary(yret) head(binary)
data(StockIndex) y <- StockIndex[, "SP500"] yret <- diff(log(y)) binary <- trdbinary(yret) head(binary)
Calculation of the exponentially smoothed trend as a technical trading indicator.
trdes(y, lambda, init = NULL)
trdes(y, lambda, init = NULL)
y |
Objects of classes: numeric, matrix, data.frame, ts, mts, and timeSeries are supported. |
lambda |
Numeric, the smoothing parameter for |
init |
The initial value in the recursive calculation of the
filter. Specifies the initial values of the time series just prior to
the start value, in reverse time order. The default, i.e.
|
The exponetially smoothed trend is calculated according to the formula:
An object of the same class as y
, containing the computed
exponetially smoothed values.
The calculation is applied per column of the data.frame and only if all columns are numeric.
The calculation is applied per column of the matrix.
The calculation is applied per column of the mts object. The attributes are preserved and an object of the same class is returned.
Calculation of the es trend.
The calculation is applied per column of the timeSeries object and an object of the same class is returned.
Calculation of the es trend. The attributes are preserved and an object of the same class is returned.
Calculation of the es trend. The attributes are preserved and an object of the same class is returned.
Calculation of the es trend. The attributes are preserved and an object of the same class is returned.
Bernhard Pfaff
filter
, trdbilson
,
trdbinary
, trdhp
,
trdsma
, trdwma
,
capser
data(StockIndex) y <- StockIndex[, "SP500"] yret <- diff(log(y)) es <- trdes(yret, lambda = 0.95) head(es)
data(StockIndex) y <- StockIndex[, "SP500"] yret <- diff(log(y)) es <- trdes(yret, lambda = 0.95) head(es)
Calculation of the Hodrick-Prescott filter as a technical trading indicator.
trdhp(y, lambda)
trdhp(y, lambda)
y |
Objects of classes: numeric, matrix, data.frame, ts, mts, and timeSeries are supported. |
lambda |
Numeric, the value for |
The Hodrick-Prescott filter is calculated according to the formula:
An object of the same class as y
, containing the computed
Hodrick-Prescott values.
The calculation is applied per column of the data.frame and only if all columns are numeric.
The calculation is applied per column of the matrix.
The calculation is applied per column of the mts object. The attributes are preserved and an object of the same class is returned.
Calculation of the bilson trend.
The calculation is applied per column of the timeSeries object and an object of the same class is returned.
Calculation of the bilson trend. The attributes are preserved and an object of the same class is returned.
Calculation of the bilson trend. The attributes are preserved and an object of the same class is returned.
Calculation of the bilson trend. The attributes are preserved and an object of the same class is returned.
Bernhard Pfaff
Hodrick, R. and E.C. Prescott (1997), Postwar U.S. Business Cycles: An Empirical Investigation, Journal of Money, Credit and Banking 29(1).
trdbinary
, trdes
,
trdbilson
, trdsma
,
trdwma
, capser
data(StockIndex) y <- StockIndex[, "SP500"] hp <- trdhp(y, lambda = 1600) head(hp)
data(StockIndex) y <- StockIndex[, "SP500"] hp <- trdhp(y, lambda = 1600) head(hp)
Calculation of a right ended simple moving average with equal weights
determined by n.periods
.
trdsma(y, n.periods, trim = FALSE)
trdsma(y, n.periods, trim = FALSE)
y |
Objects of classes: numeric, matrix, data.frame, ts, mts, and timeSeries are supported. |
n.periods |
Integer, the number of periods to be included in the calculation of the simple moving average. |
trim |
Logical, if |
An object of the same class as y
, containing the computed
simple moving averages.
The calculation is applied per column of the data.frame and only if all columns are numeric.
The calculation is applied per column of the matrix.
The calculation is applied per column of the mts object. The attributes are preserved and an object of the same class is returned.
Calculation of the es trend.
The calculation is applied per column of the timeSeries object and an object of the same class is returned.
Calculation of the es trend. The attributes are preserved and an object of the same class is returned.
Calculation of the es trend. The attributes are preserved and an object of the same class is returned.
Calculation of the es trend. The attributes are preserved and an object of the same class is returned.
Bernhard Pfaff
filter
, trdbilson
,
trdbinary
, trdhp
,
trdwma
, capser
,
trdes
data(StockIndex) y <- StockIndex[, "SP500"] sma <- trdsma(y, n.periods = 24) head(sma, 30)
data(StockIndex) y <- StockIndex[, "SP500"] sma <- trdsma(y, n.periods = 24) head(sma, 30)
Calculation of a right ended weighted moving average with weights
according to weights
.
trdwma(y, weights, trim = FALSE)
trdwma(y, weights, trim = FALSE)
y |
Objects of classes: numeric, matrix, data.frame, ts, mts, and timeSeries are supported. |
weights |
Numeric, a vector containing the weights. |
trim |
Logical, if |
If the sum of the weights is greater than unity, a warning is issued.
An object of the same class as y
, containing the computed
weighted moving averages.
The calculation is applied per column of the data.frame and only if all columns are numeric.
The calculation is applied per column of the matrix.
The calculation is applied per column of the mts object. The attributes are preserved and an object of the same class is returned.
Calculation of the es trend.
The calculation is applied per column of the timeSeries object and an object of the same class is returned.
Calculation of the es trend. The attributes are preserved and an object of the same class is returned.
Calculation of the es trend. The attributes are preserved and an object of the same class is returned.
Calculation of the es trend. The attributes are preserved and an object of the same class is returned.
Bernhard Pfaff
filter
, trdbilson
,
trdbinary
, trdhp
,
trdes
, trdsma
,
capser
data(StockIndex) y <- StockIndex[, "SP500"] wma <- trdwma(y, weights = c(0.4, 0.3, 0.2, 0.1)) head(wma, 30)
data(StockIndex) y <- StockIndex[, "SP500"] wma <- trdwma(y, weights = c(0.4, 0.3, 0.2, 0.1)) head(wma, 30)