class-fPFOLIOSPEC
:
setClass("fPFOLIOSPEC",
representation(
model = "list",
portfolio = "list",
optim = "list") )
An object of class fPFOLIOSPEC
has three slots, named
@model
, @code{portfolio}, and @optim
The first slot @model
holds the model information, the second
slot @portfolio
the portfolio information, and the last slot
@optim
the information about the solver used for optimization.
The default settings are as follows:
model = list(
type = "MV",
optimize = "minRisk",
estimator = "covEstimator",
tailRisk = list(),
params = list(alpha=0.05, a=2)),
portfolio = list(
weights = NULL,
targetReturn = NULL,
targetRisk = NULL,
riskFreeRate = 0,
nFrontierPoints = 50,
status = NA),
optim = list(
solver = NULL,
trace = FALSE)
To retrieve or modify portfolio specifications several
getSpec
and setSpec
function are
available. To set a portfolio specification from scratch
one can also use the function portfolioSpec
.
Note, there is a generic print function to print information from
portfolio specifications. For example print(portfolioSpec()
prints the default portfolio specification."timeSeries"
, the preferred
time series representation in Rmetrics.
Internally, the portfolio functions use the portfolioData
function to generate an S4 object of class-fPFOLIODATA
:
setClass("fPFOLIODATA",
representation(
data = "list",
statistics = "list",
tailRisk = "list") )
An object of class fPFOLIODATA
has three slots repfresented
by lists, named @data
, @code{@statistics}, and @tailrisk
.
The first slot @data
holds the data information, the second
slot @statistics
the estimated mean and covariance together
with optional robust estimates, and the last slot @tailRisk
optional information if we include copulae tail risk baskets into
portfolio optimization.
The function
portfolioData(data, spec = portfolioSpec())
creates an S4 object of class fPFOLIODATA
using the
portfolio specification to get the required information how to
estimate mean and covariance matrix of the assets.
To retrieve information about the portfolios data set of assets
several getData
functions are available.
Note, there is a generic print function to print information from
a portfolio data object.data
as an
S4 object of class timeSeries
. The remaining two arguments
spec=portfolioSpec()
, and constraints="LongOnly"
have
default values. The portfolio functions return an S4 object of class-fPORTFOLIO
which is represented by the following slots:
setClass("fPFOLIOCON",
representation(
call = "call",
data = "list",
spec = "list",
constraints = "character",
portfolio = "list",
title = "character",
description = "character") )
To retrieve information from a portfolio object use one of the
extractor function, see getPortfolio
.
Note, there is a generic print function to print information
from a portfolio data object and a plot function to display
charts.
The computation of a feasiblePortfolio
doesn't require
portfolio optimization at all. Given the weights through portfolio
specifiaction, use setWeights
, the function
feasiblePortfolio
directly computes the target return
and the target risk. The results are returned as an S4 object of
class fPortfolio
.
The optimization of an efficient portfolio is done by the function
efficientPortfolio
. By default a mean--variance Markowitz
optimization is performed with "LongOnly". If neither the target
return is specified by the function setTargetReturn
nor
the risk is pecified by the function setTargetRisk
, then the
results for the tangency portfolio with given risk free rate, will
be returned.
The tangencyPortfolio
and minvariancePortfolio
are two special efficient portfolios, the first yields the tangency
point on the efficient frontier with respect to the rosk free rate,
and the second the point on the efficient frontier with the lowest
risk.
The function portfolioFrontier
allows to compute points
along the efficient frontier, use setNFrontierPoints
to modify the default value of 50. The points cover the whole range
of feasible points on the efficient frontier with returns in equidistant
steps.
The solver used for portfolio optimization is selected automatically,
but can also chosen by the experienced user. It is in the responsibility
of the user that he select a solver which is not in conflict with
the specified portfolio model. Provided interfaces and solvers are:
solveRshortExact
for unlimited short selling,
solveRquadprog
for quadratic objective with linear constraints,
solveRglpk
for linear objective with linear constraints,
solveRsocp
for linear objective with linear/quadratic constraints,
solveRdonlp2
for non-linear objective with non-linear constraints.
weightsPie
Plotplot
frontierPlot
weightsPlot
frontierSlider
weightsSlider
rollingPortfolio
portfolioBacktesting
rollingPortfolio
portfolioBacktesting