Hi, 1) Still not reproducible because we do not have "E.csv" 2) The help list is not for homework questions. Many (most?) professors and/or their TAs offer office hours where they are willing to provide help and guidance (unless, of course, the assignment is meant to encourage you to learn on your own rather than relying on canned solutions) 3) try something like this to track down where the error is:
## This will enable debugging so you can watch the code as each line is executed debug(chart.Regression) ## Now when you run this, a browser will come up for you to examine the code as it is run chart.Regression(MCD,SPX, Rf = .03/12, excess.returns = TRUE, main = "Security Characteristic Line", fit = c("loess", "linear"), legend.loc = "topleft") Also, right after the error occurs, you can run: traceback() to print the call stack leading to the error. This can be useful information and may be enough for you to pin the problem down, but if the real problem occurred a while back, but no errors occurred until later, traceback() may not be sufficient and you'll need to debug. I would read all the documentation pages for ?debug ?browser ?traceback if you have never used them before prior to starting this endeavour. Those tools will definitely get you to the exact point the error occurs. Good luck and do treat education as an opportunity to develop useful skills, not just a way to get some letter grades on a piece of paper. Cheers, Josh On Sun, Jul 10, 2011 at 2:03 PM, finguy <bball3br...@hotmail.com> wrote: > 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. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles https://joshuawiley.com/ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.