[R] help with Code
finguy
bball3brian at hotmail.com
Sun Jul 10 23:03:01 CEST 2011
R version 2.13.0 (2011-04-13)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-mingw32/i386 (32-bit)
Thanks for responding Josh. I got all the codes from my professor. Here is
what was required
##Load fPortfolio, PerformanceAnalytics, fOptions and all other components
associated with these programs
#Load Data (CSV File)
Data = read.table(file="E.csv",header=T,sep=",",row.names="Date")
Data = readSeries(file="E.csv",header=T,sep=",",format="%Y-%m-%d")
options(max.print=5.5E5)
setRmetricsOptions(max.print="5.5E5")
#Label Data Parameters
SPX = Data[, c("SPX")]
Riskfree = Data[, c("USGG10yr")]
MCD = Data[, c("MCD")]
BA = Data[, c("GE")]
MSFT = Data[, c("MSFT")]
CVX = Data[, c("CVX")]
DIS = Data[, c("DIS")]
CORP = Data[, c("196298GR8")]
GOVT = Data[, c("000369CA")]
HY = Data[, c("812026BA")]
CPI = Data[, c("CPIINDX")]
JOB = Data[, c("USMMMNCH")]
CC = Data[, c("CONSSENT")]
SPX USGG10yr MCD GE MSFT CVX DIS 000369CA 196298GR8
812026BA CPIINDX USMMMNCH CONSSENT
##Summary of Statisitics
table.Stats(Data[,1:13])
t(table.Stats(Data))
result=t(table.Stats(Data))
require("Hmisc")
textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE,
cdec=c(rep(1,2),rep(3,14))), rmar = 0.8, cmar = 1.5, max.cex=.9, halign =
"center", valign = "top", row.valign="center", wrap.rownames=10,
wrap.colnames=10, mar = c(0,0,3,0)+0.1)
title(main="Statistics for FIN 355 Project Data")
#Correlation Matrix with Distribution and SCL
chart.Correlation(Data, histogram=TRUE, pch="+")
chart.Correlation(Data[,1:10], histogram=TRUE, pch="+")
# CAPM, Efficient Frontier
PData = Data[,3:10]
Spec = portfolioSpec()
setTargetReturn(Spec) = mean(colMeans(PData))
Constraints = "LongOnly"
efficientPortfolio(PData, Spec, Constraints)
Frontier = portfolioFrontier(PData)
frontierPlot(Frontier, col = c("orange", "orange"), pch = 19)
minvarport = minvariancePoints(Frontier, pch = 19, col = "red")
minvariancePortfolio(PData)
cmlp = tangencyPoints(Frontier, pch = 19, col = "blue")
cml = tangencyLines(Frontier, col = "blue")
tangencyPortfolio(PData)
ew = equalWeightsPoints(Frontier, pch = 15, col = "green")
sap = singleAssetPoints(Frontier, pch = 25, cex = 2.0, col = topo.colors(8))
#Single Factor Index Model - Regression
BetaCoVariance(MCD,SPX)
BetaCoVariance(GE,SPX)
BetaCoVariance(MSFT,SPX)
BetaCoVariance(CVX,SPX)
BetaCoVariance(DIS,SPX)
**EXTRA CREDIT**
Frontier, time series, time date
##Securities Characteristic Line
chart.Regression(MCD,SPX, Rf = .03/12, excess.returns = TRUE, main =
"Security Characteristic Line", fit = c("loess", "linear"), legend.loc =
"topleft")
Everything works until i get to the securities Characteristic Line. I get
the following:
> chart.Regression(MCD,SPX, Rf = .03/12, excess.returns = TRUE, main =
> "Security Characteristic Line", fit = c("loess", "linear"), legend.loc =
> "topleft")
Error in as.vector(data[, i]) : subscript out of bounds
I don't know much about R but I'm hoping somebody can find the error in the
code or provide the package I need. Thanks
--
View this message in context: http://r.789695.n4.nabble.com/help-with-Code-tp3658134p3658242.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list