Learn R Programming

stockPortfolio (version 1.2)

stockModel: Create a stock model

Description

Input an object of class "stockReturns" and select a model. Available choices are "none", "SIM" (single index model), "CCM" (constant correlation model), and "MGM" (multigroup model).

Usage

stockModel(stockReturns, drop = NULL, Rf = 0, shortSelling = c("y", "n"), model = c("none", "SIM", "CCM", "MGM"), industry = NULL, index = NULL, get = c("overlapOnly", "all"), freq = c("month", "week", "day"), start = "1970-01-01", end = NULL, recentLast = FALSE, rawStockPrices = FALSE)

Arguments

stockReturns
An object of class "stockReturns". Additionally, a character vector of tickers can also be used here, in which case also see argument freq, get, start, and end. Additionally, an object of class "stockModel" can also be input here, which will permit model adjustments, including switching the model altogether. Finally, stock data can also be submitted here as a matrix; the column names should be the ticker names and the row names should be the dates of the returns, YYYY-MM-DD. Additionally, for outside data sets where the oldest stock return is in row 1 (and not the last row), see argument recentLast.
drop
Declare any stocks to be dropped. For instance, if the model "none", "CCM", or "MGM" is used, stock indices might be dropped.
Rf
The risk free rate of return, which must be standardized for the period (e.g. a 2% yearly rate for monthly data would imply Rf=0.02/12, or 2% with daily data would imply Rf=0.02/250 if there are 250 trading days per year.). The default value is 0.
shortSelling
Either "yes" (default) or "no". Some models, "none" and "MGM", will permit short-selling regardless of this selection.
model
Either no model ("none", the default), the single index model ("SIM"), constant correlation model ("CCM"), or the multigroup model ("MGM").
industry
A character or factor vector containing the industries corresponding to stockReturns. This argument is optional except when model="MGM", however, it may be included in any model for slightly enhanced graphics.
index
When using model="SIM", the index is the column number indicating the stock index. Warning if using drop and also specifying the index: The value of index should correspond to the column number AFTER dropping columns. See Details below.
get
"overlapOnly" (default) obtains stock returns for which all stocks had data and drops any dates with NA. "all" yields all stock returns regardless of whether data for all stocks is available. This argument is ignored unless stockReturns is a vector of tickers.
freq
The time period between each stock return. Default is "month" and other options are "week" and "day". This argument is ignored unless stockReturns is a vector of tickers.
start
Start date in the format "YYYY-MM-DD". This argument is ignored unless stockReturns is a vector of tickers.
end
End date in the format "YYYY-MM-DD". This argument is ignored unless stockReturns is a vector of tickers.
recentLast
Set this argument to TRUE if (1) you are using your own data that was not obtained by getReturns and (2) your matrix of returns runs from oldest returns (row 1) to most recent returns (last row).
rawStockPrices
Set to TRUE if (1) you are using your own data that was not obtained by getReturns and (2) your matrix is of stock prices and not of stock returns.

Value

stockModel outputs an object of class "stockModel", which is a list of the following items, many of which might be NA:
model
The model selected.
ticker
A vector of the tickers of the stocks included in the model.
index
The index number, if provided by the user.
theIndex
Ticker of the index.
industry
Industries associated with the stocks.
returns
Return data used to build the model.
marketReturns
Return data of the index.
n
Number of observations per stock.
start
The oldest date for which stock returns are included.
end
The most recent date for which stock returns are included.
period
How frequently stock returns are included in the data.
R
Average returns of the stocks.
COV
Variance-covariance matrix of the stock returns.
sigma
Standard deviation of the returns of the stocks (square root of the diagonal of COV).
shorts
Whether short sales are allowed.
Rf
Risk free return rate.
alpha
Vector of intercepts in the linear model for the single index model.
vAlpha
The square of the standard errors of alpha.
beta
Vector of coefficients in the linear model for the single index model.
vBeta
The square of the standard errors of beta.
betaAdj
Whether the model was adjusted via adjustBeta.
MSE
Variance of error term associated with single index model for each stock.
RM
Mean market return.
VM
Variance of the market return.
rho
Mean correlation or, if using model="MGM", the matrix of averaged correlations. See getCorr.

Details

The multigroup model is the least known of the models presented here. It is similar to the constant correlation model, except that instead of assuming a constant correlation across all stocks, correlations are only dependent on the industry of a stock.

If stocks are dropped using the argument drop, then index must correspond to the position of the index AFTER those stocks are dropped. For instance, if there are seven stocks, the index is in position six, and the fourth stock is dropped, then we should use index=5.

References

Markowitz, Harry. "Portfolio Selection Efficient Diversification of Investments." New York: John Wiley and Sons, 1959.

Elton, Edwin, J., Gruber, Martin, J., Padberg, Manfred, W. "Simple Criteria for Optimal Portfolio Selection," Journal of Finance, XI, No. 5 (Dec. 1976), pp. 1341-1357.

Elton, Edwin, J., Gruber, Martin, J., Padberg, Manfred, W. "Simple Rules for Optimal Portfolio Selection: The Multi Group Case," Journal of Financial and Quantitative Analysis, XII, No. 3 (Sept. 1977), pp. 329-345.

Elton, Edwin, J., Gruber, Martin, J., Padberg, Manfred, W. "Simple Criteria for Optimal Portfolio Selection: Tracing Out the Efficient Frontier," Journal of Finance, XIII, No. 1 (March 1978), pp. 296-302.

See Also

getReturns, adjustBeta, optimalPort, testPort

Examples

Run this code
#===> build four models <===#
data(stock99)
data(stock94Info)
non <- stockModel(stock99, drop=25, model='none', industry=stock94Info$industry)
sim <- stockModel(stock99, model='SIM', industry=stock94Info$industry, index=25)
ccm <- stockModel(stock99, drop=25, model='CCM', industry=stock94Info$industry)
mgm <- stockModel(stock99, drop=25, model='MGM', industry=stock94Info$industry)

#===> build optimal portfolios <===#
opNon <- optimalPort(non)
opSim <- optimalPort(sim)
opCcm <- optimalPort(ccm)
opMgm <- optimalPort(mgm)

#===> test portfolios on 2004-9 <===#
data(stock04)
tpNon <- testPort(stock04, opNon)
tpSim <- testPort(stock04, opSim)
tpCcm <- testPort(stock04, opCcm)
tpMgm <- testPort(stock04, opMgm)

#===> compare performances <===#
plot(tpNon)
lines(tpSim, col=2, lty=2)
lines(tpCcm, col=3, lty=3)
lines(tpMgm, col=4, lty=4)
legend('topleft', col=1:4, lty=1:4, legend=c('none', 'SIM', 'CCM', 'MGM'))

Run the code above in your browser using DataLab