Skip to content

Commit

Permalink
Related to #50 & #51, add check if Risk-free rate is used
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinMShea committed Aug 21, 2021
1 parent b1573ec commit ce4c6dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 2 additions & 0 deletions R/fitTsfmMT.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ https://stackoverflow.com/questions/9195718/variable-name-restrictions-in-r")
# extract variables to be used in the time series regression
dat.xts <- merge(data.xts[,asset.names], data.xts[,mkt.name])

if (!is.null(rf.name)) {
# Note `Return.excess` will modify variable names, so change back
dat.xts.names <- colnames(dat.xts)
dat.xts <- PerformanceAnalytics::Return.excess(R = dat.xts,
Rf = data.xts[ ,rf.name])
colnames(dat.xts) <- dat.xts.names
}
# mkt-timing factors: down.market=max(0,Rf-Rm), market.sqd=(Rm-Rf)^2

down.market <- dat.xts[ ,mkt.name]
Expand Down
21 changes: 11 additions & 10 deletions R/fitTsfmUpDn.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @title Fit a up and down market factor model using time series regression
#'
#' @description This is a wrapper function to fits a up and down market model for one
#' or more asset returns or excess returns using time series regression.
#' @description This is a wrapper function to fits a up and down market model
#' for one or more asset returns or excess returns using time series regression.
#' Users can choose between ordinary least squares-LS, discounted least
#' squares-DLS (or) robust regression. An object of class
#' \code{"tsfmUpDn"} is returned.
Expand All @@ -12,13 +12,13 @@
#' The goal of up and down market model is to capture two different market Betas in the up and down markets.
#'
#'
#' @param asset.names vector containing names of assets, whose returns or
#' excess returns are the dependent variable.
#' @param mkt.name name of the column for market returns. It
#' is required for a up/down market model.
#' @param rf.name name of the column of risk free rate variable to calculate
#' excess returns for all assets (in \code{asset.names}) and the market factor (in
#' \code{mkt.name}). Default is \code{NULL}, and no action is taken.
#' @param asset.names Vector containing syntactically valid names of assets,
#' whose returns or excess returns are the dependent variable.
#' @param mkt.name Syntactically valid name for market returns. Required for an
#' up/down market model.
#' @param rf.name Syntactically valid name of the risk free rate to calculate
#' excess returns for all assets (in \code{asset.names}) and the market factor
#' (in \code{mkt.name}). Default is \code{NULL}, and no action is taken.
#' @param data vector, matrix, data.frame, xts, timeSeries or zoo object
#' containing column(s) named in \code{asset.names}, \code{factor.names} and
#' optionally, \code{mkt.name} and \code{rf.name}.
Expand Down Expand Up @@ -115,12 +115,13 @@ fitTsfmUpDn <- function(asset.names, mkt.name, rf.name=NULL,
# extract columns to be used in the time series regression
dat.xts <- merge(data.xts[,asset.names], data.xts[,mkt.name])

if (!is.null(rf.name)) {
# Note `Return.excess` will modify variable names, so change back
dat.xts.names <- colnames(dat.xts)
dat.xts <- PerformanceAnalytics::Return.excess(R = dat.xts,
Rf = data.xts[ ,rf.name])
colnames(dat.xts) <- dat.xts.names

}
mkt <- dat.xts[ ,mkt.name]
# up market
dataUp.xts <- dat.xts[mkt >= 0]
Expand Down

0 comments on commit ce4c6dd

Please sign in to comment.