<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
try this:<br>
<b>> colnames(SMALLCAP.RET)<br>
[1] "MODI" "MGF" "MEE" "FCEL" "OII" "SEB" "RML"
"AEOS" "BRC" "CTC" <br>
[11] "TNL" "IBC" "KWD" "TOPP" "RARE" "HAR" "BKE"
"GG" "GYMB" "KRON" <br>
[21] "MARKET" "T90"<br>
<br>
</b>If you try that and you see that same output above, GOOG, MSFT and
JNJ are not in the pre-canned SMALLCAP.RET dataset.<br>
<br>
You could try the following to create a dataset for use below<br>
<br>
library(quantmod)<br>
getSymbols("GOOG;MSFT;JNJ", from="2007-01-01")<br>
GOOG.ret = CalculateReturns(GOOG, method="simple")<br>
MSFT.ret = CalculateReturns(MSFT, method="simple")<br>
JNJ.ret = CalculateReturns(JNJ, method="simple")<br>
Data = GOOG.ret['::2009-08-13',4] # I subset the date to the 13th to
remove the last day NA<br>
Data = merge(Data, MSFT.ret['::2009-08-13',4])<br>
Data = merge(Data, JNJ.ret['::2009-08-13',4])<br>
<br>
<br>
Then, continue on<br>
<br>
Data = as.timeSeries(Data)<br>
Spec = portfolioSpec()<br>
setEstimator(Spec) = "covMcdEstimator"<br>
setNFrontierPoints(Spec) = 20<br>
Estimator = covMcdEstimator(Data)<br>
Frontier = portfolioFrontier(data=Data, spec=Spec)<br>
<br>
tailoredFrontierPlot(Frontier, mText = "A Frontier", risk="Sigma")<br>
<br>
HTH,<br>
cj<br>
<br>
PS: There's probably a better way to construct a large set of returns,
but this was a quick and dirty way...I *highly* recommend the book
cited in the help page:<br>
Wuertz, D., Chalabi, Y., Chen W., Ellis A. (2009); Portfolio
Optimization with R/Rmetrics, Rmetrics eBook, Rmetrics Association and
Finance Online, Zurich.<br>
<br>
There should be a sample copy online which should get you going...<br>
<br>
<br>
R. Vince wrote:
<blockquote cite="mid:3A91D0C1D0284652988AB11A29CC5DBC@XP1" type="cite">I
too have been trying to use some of the efficient frontier functions
(in package fPortfolio). I must be doing something very stupd. Working
from the example (from the help file page, included herein below), when
I go to create the Data object, I get:
<br>
<br>
<blockquote type="cite">Data = SMALLCAP.RET
<br>
Data = Data[, c("GOOG", "MSFT", "JNJ")]
<br>
</blockquote>
Error: subscript out of bounds
<br>
<br>
I'm truly at a loss here. Can someone please point me in the right
direction as to how to create the Data Object? I think there must be a
mistake in the help file, or I'm just very confused about it. Thanks,
RVince
<br>
<br>
------ Help File Page I am working from:------------------
<br>
<br>
efficientPortfolio(fPortfolio) R Documentation
<br>
<br>
Efficient Portfolios
<br>
Description
<br>
Returns efficient portfolios.
<br>
<br>
Usage
<br>
efficientPortfolio(data, spec = portfolioSpec(), constraints =
"LongOnly")
<br>
<br>
maxratioPortfolio(data, spec = portfolioSpec(), constraints =
"LongOnly")
<br>
tangencyPortfolio(data, spec = portfolioSpec(), constraints =
"LongOnly")
<br>
<br>
minriskPortfolio(data, spec = portfolioSpec(), constraints =
"LongOnly")
<br>
minvariancePortfolio(data, spec = portfolioSpec(), constraints =
"LongOnly")
<br>
<br>
maxreturnPortfolio(data, spec = portfolioSpec(), constraints =
"LongOnly")
<br>
<br>
Arguments
<br>
constraints a character string vector, containing the constraints of
the form
<br>
"minW[asset]=percentage" for box constraints resp.
<br>
"maxsumW[assets]=percentage" for sector constraints.
<br>
data a multivariate time series described by an S4 object of class
timeSeries. If your timeSerie is not a timeSeries object, consult the
generic function as.timeSeries to convert your time series.
<br>
spec an S4 object of class fPFOLIOSPEC as returned by the function
portfolioSpec.
<br>
<br>
Details
<br>
Efficient Portfolio:
<br>
<br>
An efficient portfolio is a portfolio which lies on the efficient
frontier. The efficientPortfolio function returns the properties of the
efficient portfolio as an S4 object of class fPORTFOLIO.
<br>
<br>
Minumum Risk or Tangency Portfolio:
<br>
<br>
The function tangencyPortfolio returns the portfolio with the highest
return/risk ratio on the efficient frontier. For the Markowitz
portfolio this is the same as the Sharpe ratio. To find this point on
the frontier the return/risk ratio calculated from the target return
and target risk returned by the function efficientPortfolio.
<br>
<br>
Global minimum risk or Minimum Variance Portfolio:
<br>
<br>
The function minvariancePortfolio returns the portfolio with the
minimal risk on the efficient frontier. To find the minimal risk point
the target risk returned by the function efficientPortfolio is
minimized.
<br>
<br>
Maximum Return Portfolio:
<br>
<br>
The function maxreturnPortfolio returns the portfolio with the maximal
return for a fixed target risk.
<br>
<br>
Value
<br>
returns an S4 object of class "fPORTFOLIO".
<br>
<br>
References
<br>
Wuertz, D., Chalabi, Y., Chen W., Ellis A. (2009); Portfolio
Optimization with R/Rmetrics, Rmetrics eBook, Rmetrics Association and
Finance Online, Zurich.
<br>
<br>
Examples
<br>
## data -
<br>
Data = SMALLCAP.RET
<br>
Data = Data[, c("BKE", "GG", "GYMB", "KRON")]
<br>
Data
<br>
<br>
## spec -
<br>
Spec = portfolioSpec()
<br>
setTargetReturn(Spec) = mean(colMeans(Data))
<br>
Spec
<br>
<br>
## constraints -
<br>
Constraints = "LongOnly"
<br>
Constraints
<br>
<br>
## efficientPortfolio -
<br>
efficientPortfolio(Data, Spec, Constraints)
<br>
<br>
## tangency Portfolio -
<br>
tangencyPortfolio(Data, Spec, Constraints)
<br>
<br>
## minvariancePortfolio -
<br>
minvariancePortfolio(Data, Spec, Constraints)
<br>
<br>
_______________________________________________
<br>
<a class="moz-txt-link-abbreviated" href="mailto:R-SIG-Finance@stat.math.ethz.ch">R-SIG-Finance@stat.math.ethz.ch</a> mailing list
<br>
<a class="moz-txt-link-freetext" href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance">https://stat.ethz.ch/mailman/listinfo/r-sig-finance</a>
<br>
-- Subscriber-posting only.
<br>
-- If you want to post, subscribe first.
<br>
</blockquote>
<br>
</body>
</html>