나는 내 포트폴리오 수익률과 개별 주식 기여도를 계산하려고 시도해 왔습니다. 나는 this post을 우연히 발견했는데, 그것은 PerformanceAnalytics를 작성하는 사람에게서 나온 것으로 보인다.PerformanceAnalytics 샌드 박스의 to.period.contributions() 오류
기사 끝에 그는 일부 기능에 대해 link to r-forge with a sandbox file을 게시합니다.
그래서 일일 수익을 to.monthly.contributions()
함수를 통해 합계 월간 수익으로 변환하려고하는데 xts 오류가 발생했습니다! 여기
portfolio.returns$contributions
함께 할 수있는 뭔가가 같은데요
Error in inherits(x, "xts") :
argument "Contributions" is missing, with no default
5. inherits(x, "xts")
4. is.xts(x)
3. checkData(Contributions)
2. to.period.contributions(contributions = contributions, period = "months")
1. to.monthly.contributions(portfolio.returns$contributions)
그러나
library(PerformanceAnalytics)
library(quantmod)
stock.weights <- c(.15, .20, .25, .225, .175)
symbols <- c("GOOG", "AMZN", "BA", "FB", "AAPL")
getSymbols(symbols, src = 'google', from = "2016")
#xts with daily closing of each stock
merged.closing <- merge(GOOG[,4], AMZN[,4], BA[,4], FB[,4], AAPL[,4])
#xts with returns
merged.return <- na.omit(Return.calculate(merged.closing))
# weighted returns rebalanced quartely
portfolio.returns = Return.portfolio(merged.return, weights = stock.weights,
rebalance_on = "quarters", verbose = TRUE)
#to monthly contributions function
to.monthly.contributions(portfolio.returns$contributions)
나는 다음과 같은 오류 메시지가 마지막 줄을 실행할 때 xts가 아닌가요? 하지만 그 문제를 해결하는 방법을 모르겠습니다.
참고로, 월간/분기/년으로 포트폴리오 수익을 계산하는 데 더 좋은 아이디어 나 출처가있는 사람은 기꺼이 듣고 싶습니다. 체중 변화, 재 균형 및 기부금을 고려해야 함을 명심하십시오. 변화에!
'merged.closing'에는 Google이 두 번 있고 Apple이 없습니다. 그게 될 수 있을까요? – lebelinoz
'to.monthly.contributions'을 찾을 수 없습니다. 어떤 패키지가 그 패키지입니까? – lebelinoz
자습서를 재현 할 수 없습니다. 함수에서 날짜를 정의하는 중 오류가 발생하여 동일한 문제가 발생합니다. – Katerina