Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option returnWeights to FAAreturns #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion R/FAAreturns.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#'The 'best' argument chooses the best ranked asset by the momentum and volatility weights, while the 'default' method starts with
#'the initial lowest-correlated asset. (Default 'best')
#'@param geometric whether or not to use geometric compounding for returns (default TRUE)
#'@param returnWeights if TRUE, returns a length-two list of weights and returns (default FALSE)
#'@return a single xts of strategy returns
#'@references \url{http://quantstrattrader.wordpress.com/2014/10/31/combining-faa-and-stepwise-correlation/}
#'\cr \url{http://papers.ssrn.com/sol3/papers.cfm?abstract_id=2193735}
Expand All @@ -25,7 +26,7 @@
weightMom = 1, weightVol = .5, weightCor = .5,
riskFreeName = NULL, bestN = 3,
stepCorRank = FALSE, stepStartMethod = c("best", "default"),
geometric = TRUE) {
geometric = TRUE, returnWeights=FALSE) {
stepStartMethod <- stepStartMethod[1]
if(is.null(riskFreeName)) {
prices$zeroes <- 0
Expand Down Expand Up @@ -120,5 +121,8 @@
weights[, riskFreeCol] <- weights[, riskFreeCol] + 1-rowSums(weights)
strategyReturns <- Return.rebalancing(R = returns, weights = weights, geometric = geometric)
colnames(strategyReturns) <- paste(monthLookback, weightMom, weightVol, weightCor, sep="_")
if(returnWeights) {
return(list(weights, strategyReturns))
}
return(strategyReturns)
}