Learn R Programming

portfolio (version 0.5-3)

portfolioBasic-class: Class "portfolioBasic"

Description

An object of the lightweight class "portfolioBasic" contains a data frame of weights and a data frame of supplementary information.

Arguments

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 the id.var slot.

id.var:

Object of class "character" containing the name of the column in the data slot to be used as a unique identifier.

symbol.var:

Object of class "character" containing the name of the column in the data slot to be used as a descriptive symbol.

in.var:

Object of class "character" containing the name of the column in the data slot to be used as a rank vector in calls to create.

weight.var:

Object of class "character" containing the name of the column in the data slot to be used as weight overrides in calls to create.

ret.var:

Object of class "character" containing the name of the column in the data slot to be used as the return in calls to performance.

type:

Object of class "character" containing the type of weight formation to use in calls to create. May be one of "relative", "equal", "linear", "sigmoid", "centroid", or "complex". Defaults to equal.

size:

Object of class "characterOrNumeric" containing the size of the portfolio to use in calls to create. May either contain the number of securities per side or one of "decile", "quintile", "quartile", "tercile", or "demile". Defaults to quintile.

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 two portfolioBasic objects for "near equality". Two portfolioBasic objects are all.equal iff their weights slots contain exactly the same set of securities and weight vectors that are all.equal.

balance

signature(object = "portfolioBasic", in.var = "character"): balances the positions in portfolio object to be neutral to the categories specified by column in.var in the data slot.

contribution

signature(object = "portfolioBasic", contrib.var = "character"): returns one data.frame with contribution analysis for each element of contrib.var. All results are returned in a list.

create

signature(object = "portfolioBasic"): use this object's creation parameters (such as in slots size and type) to create and return a new object of class portfolioBasic.

exposure

signature(object = "portfolioBasic", exp.var = "character"): returns one data.frame with exposure analysis for each element of contrib.var. All results are returned in a list.

matching

signature(object = "portfolioBasic", covariates = "character": returns a matchedPortfolio object containing n.matches matched portfolios. object is the portfolioBasic 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 a portfolioBasic object, between two portfolios.

scaleWeights

signature(object = "portfolioBasic"): scale weights to the weights supplied in the target parameter. To restrict the set of positions whose weights are scaled, use the condition 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 calling create.

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

Jeff Enos jeff@kanecap.com with contributions from Daniel Gerlanc dgerlanc@gmail.com

Examples

Run this code
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"))

Run the code above in your browser using DataLab