portfolioBasic-class {portfolio} | R Documentation |
Class "portfolioBasic"
Description
An object of the lightweight class "portfolioBasic" contains a data frame of weights and a data frame of supplementary information.
Objects from the Class
Objects can be created by calls of the form new("portfolioBasic", ...)
.
Slots
name
:Object of class
"character"
containing the name of this portfolio.instant
:Object of class
"ANY"
containing an instant to which this portfolio pertains.data
:Object of class
"data.frame"
containing supplementary information about the positions in this portfolio. Must include a unique column specified in theid.var
slot.id.var
:Object of class
"character"
containing the name of the column in thedata
slot to be used as a unique identifier.symbol.var
:Object of class
"character"
containing the name of the column in thedata
slot to be used as a descriptive symbol.in.var
:Object of class
"character"
containing the name of the column in thedata
slot to be used as a rank vector in calls tocreate
.weight.var
:Object of class
"character"
containing the name of the column in thedata
slot to be used as weight overrides in calls tocreate
.ret.var
:Object of class
"character"
containing the name of the column in thedata
slot to be used as the return in calls toperformance
.type
:Object of class
"character"
containing the type of weight formation to use in calls tocreate
. May be one of "relative", "equal", "linear", "sigmoid", "centroid", or "complex". Defaults toequal
.size
:Object of class
"characterOrNumeric"
containing the size of the portfolio to use in calls tocreate
. May either contain the number of securities per side or one of "decile", "quintile", "quartile", "tercile", or "demile". Defaults toquintile
.weights
:Object of class
"data.frame"
containing the data frame of weights for this portfolio's positions. Must contain a unique column called "id".
Methods
- +
signature(e1 = "portfolioBasic", e2 = "portfolioBasic")
- all.equal
signature(target = "portfolioBasic", current = "portfolioBasic")
: Compare twoportfolioBasic
objects for "near equality". TwoportfolioBasic
objects areall.equal
iff theirweights
slots contain exactly the same set of securities and weight vectors that areall.equal
.- balance
signature(object = "portfolioBasic", in.var = "character")
: balances the positions in portfolioobject
to be neutral to the categories specified by columnin.var
in thedata
slot.- contribution
signature(object = "portfolioBasic", contrib.var = "character")
: returns one data.frame with contribution analysis for each element ofcontrib.var
. All results are returned in a list.- create
signature(object = "portfolioBasic")
: use this object's creation parameters (such as in slotssize
andtype
) to create and return a new object of classportfolioBasic
.- exposure
signature(object = "portfolioBasic", exp.var = "character")
: returns one data.frame with exposure analysis for each element ofcontrib.var
. All results are returned in a list.- matching
signature(object = "portfolioBasic", covariates = "character"
: returns amatchedPortfolio
object containingn.matches
matched portfolios.object
is theportfolioBasic
to be matched.covariates
is a character vector of the attributes on which to match.- performance
signature(object = "portfolioBasic")
: returns a list containing performance results.- plot
signature(x = "portfolioBasic", y = "missing")
: Plot this object.- portfolioDiff
signature(object = "portfolioBasic", x = "portfolioBasic")
: computes the difference, as aportfolioBasic
object, between two portfolios.- scaleWeights
signature(object = "portfolioBasic")
: scale weights to the weights supplied in thetarget
parameter. To restrict the set of positions whose weights are scaled, use thecondition
argument.- show
signature(object = "portfolioBasic")
: display this object, briefly.- summary
signature(object = "portfolioBasic")
: display descriptive information about this portfolio.- initialize
signature(object = "portfolioBasic")
: initialize the portfolio by callingcreate
.- mapMarket
signature(object = "portfolioBasic")
: create a map of the market plot of the portfolio.
Matched portfolios
The matching
method allows one to benchmark a portfolio against
a similar portfolio formed from other stocks in the universe. The
universe consists of all the stocks in the data
slot of
original
.
matching
calculates a propensity score for each stock in the
universe. covariates
determines which attributes are used to
calculate the propensity score. covariates
must refer to the
names of columns in the data
slot of original
.
Matching accepts an optional argument, method
, which sets the
algorithm for determining the best match for each
stock. There are 2 available algorithms, "greedy"
and
"sample"
. "greedy"
is the default and generates 1
matched portfolio. "sample"
randomly matches each stock
in original
with one of the stocks in the universe. Although the matching is random,
stocks in original
are most likely to be matched with stocks
having similar propensity scores.
n.matches
is another optional argument to matching
which
determines the number of matched portfolios to generate. Requesting
more than 1 matched portfolio. (n.matches > 1
) while using
greedy
is not allowed. When using sample
, there is
no bound on n.matches
.
Author(s)
Jeff Enos jeff@kanecap.com with contributions from Daniel Gerlanc dgerlanc@gmail.com
Examples
data(dow.jan.2005)
p <- new("portfolioBasic",
id.var = "symbol",
in.var = "price",
sides = "long",
ret.var = "month.ret",
data = dow.jan.2005)
summary(p)
exposure(p, exp.var = c("price", "sector"))
performance(p)
contribution(p, contrib.var = c("cap.bil", "sector"))
p <- new("portfolioBasic",
id.var = "symbol",
in.var = "price",
type = "linear",
sides = c("long", "short"),
ret.var = "month.ret",
data = dow.jan.2005)
summary(p)
exposure(p, exp.var = c("price", "sector"))
performance(p)
contribution(p, contrib.var = c("cap.bil","sector"))