我可以获得每日收益,但无法获得更多收益。使用以下代码。
# create list of stock tickers – replace the tickers here with those you want to use in your portfolio
TickerList <- c("T", "GOOG", "CSCO", "MSFT", "JNPR", "AAPL", "AMZN", "GOOGL", "JNJ", "FB", "V", "HD", "VZ", "MA", "INTC")
# read closing prices from Yahoo keeping only the closing prices
ClosingPricesRead <- NULL
for (Ticker in TickerList)
ClosingPricesRead <- cbind(ClosingPricesRead,
getSymbols.yahoo(Ticker,
from="2016-12-31",
to="2019-12-31",
verbose=FALSE,
auto.assign=FALSE)[,4]) # [,6] = keep the adjusted prices
# keep only the dates that have closing prices for all tickers
ClosingPrices <- ClosingPricesRead[apply(ClosingPricesRead,1,function(x) all(!is.na(x))),]
# convert prices to daily returns
returns <- as.timeSeries((tail(ClosingPrices,-1) / as.numeric(head(ClosingPrices,-1)))-1)
建立平均方差边界。
我一直在努力做到这一点,因为我不能使用 fPortafolio 包。我还需要帮助才能获得资本市场线(考虑到美联储的免费风险资产。)