fitTsfm: Fit a time series factor model using time series regression

View source: R/fitTsfm.R

fitTsfmR Documentation

Fit a time series factor model using time series regression

Description

Fits a time series (a.k.a. macroeconomic) factor 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. Several variable selection options including Stepwise, Subsets, Lars are available as well. An object of class "tsfm" is returned.

Usage

fitTsfm(
  asset.names,
  factor.names,
  mkt.name = NULL,
  rf.name = NULL,
  data = data,
  fit.method = c("LS", "DLS", "Robust"),
  variable.selection = c("none", "stepwise", "subsets", "lars"),
  control = fitTsfm.control(),
  ...
)

## S3 method for class 'tsfm'
coef(object, ...)

## S3 method for class 'tsfm'
fitted(object, ...)

## S3 method for class 'tsfm'
residuals(object, ...)

Arguments

asset.names

vector of syntactically valid asset names, whose returns are the dependent variable in the factor model.

factor.names

vector containing syntactically valid names of the factors.

mkt.name

syntactically valid name of the column for market returns. Default is NULL.

rf.name

syntactically valid name of the column for the risk free rate; if excess returns should be calculated for all assets and factors. Default is NULL.

data

vector, matrix, data.frame, xts, timeSeries or zoo object containing the columns asset.names, factor.names, and optionally, mkt.name and rf.name.

fit.method

the estimation method, one of "LS", "DLS" or "Robust". See details. Default is "LS".

variable.selection

the variable selection method, one of "none", "stepwise","subsets","lars". See details. Default is "none".

control

list of control parameters. Refer to fitTsfm.control for details.

...

arguments passed to fitTsfm.control

object

a fit object of class tsfm which is returned by fitTsfm

Details

Typically, factor models are fit using excess returns. rf.name gives the option to supply a risk free rate variable to subtract from each asset return and factor to compute excess returns.

Estimation method "LS" corresponds to ordinary least squares using lm, "DLS" is discounted least squares (weighted least squares with exponentially declining weights that sum to unity), and, "Robust" is robust regression (using lmrobdetMM).

If variable.selection="none", uses all the factors and performs no variable selection. Whereas, "stepwise" performs traditional stepwise LS or Robust regression (using step or step.lmrobdetMM), that starts from the initial set of factors and adds/subtracts factors only if the regression fit, as measured by the Bayesian Information Criterion (BIC) or Akaike Information Criterion (AIC), improves. And, "subsets" enables subsets selection using regsubsets; chooses the best performing subset of any given size or within a range of subset sizes. Different methods such as exhaustive search (default), forward or backward stepwise, or sequential replacement can be employed. See fitTsfm.control for more details on the control arguments.

variable.selection="lars" corresponds to least angle regression using lars with variants "lasso" (default), "lar", "stepwise" or "forward.stagewise". Note: If variable.selection="lars", fit.method will be ignored.

Argument mkt.name can be used to add market-timing factors to any of the above methods. Please refer to fitTsfmMT, a wrapper to fitTsfm for details.

Data Processing

Note about NAs: Before model fitting, incomplete cases are removed for every asset (return data combined with respective factors' return data) using na.omit. Otherwise, all observations in data are included.

Note about asset.names and factor.names: Spaces in column names of data will be converted to periods as fitTsfm works with xts objects internally and colnames won't be left as they are.

Value

fitTsfm returns an object of class "tsfm" for which print, plot, predict and summary methods exist.

The generic functions coef, fitted and residuals extract various useful features of the fit object. Additionally, fmCov computes the covariance matrix for asset returns based on the fitted factor model.

An object of class "tsfm" is a list containing the following components:

asset.fit

list of fitted objects for each asset. Each object is of class lm if fit.method="LS" or "DLS", class lmrobdetMM if the fit.method="Robust", or class lars if variable.selection="lars".

alpha

N x 1 data.frame of estimated alphas.

beta

N x K data.frame of estimated betas.

r2

length-N vector of R-squared values.

resid.sd

length-N vector of residual standard deviations.

fitted

xts data object of fitted values; iff variable.selection="lars"

call

the matched function call.

data

xts data object containing the asset(s) and factor(s) returns.

asset.names

syntactically valid asset.names as input.

factor.names

syntactically valid factor.names as input.

mkt.name

syntactically valid mkt.name as input

fit.method

fit.method as input.

variable.selection

variable.selection as input.

Where N is the number of assets, K is the number of factors and T is the number of time periods.

Author(s)

Eric Zivot, Sangeetha Srinivasan and Yi-An Chen.

References

Christopherson, J. A., Carino, D. R., & Ferson, W. E. (2009). Portfolio performance measurement and benchmarking. McGraw Hill Professional.

Efron, B., Hastie, T., Johnstone, I., & Tibshirani, R. (2004). Least angle regression. The Annals of statistics, 32(2), 407-499.

Hastie, T., Tibshirani, R., Friedman, J., Hastie, T., Friedman, J., & Tibshirani, R. (2009). The elements of statistical learning (Vol. 2, No. 1). New York: Springer.

See Also

The tsfm methods for generic functions: plot.tsfm, predict.tsfm, print.tsfm and summary.tsfm.

And, the following extractor functions: coef, fitted, residuals, fmCov, fmSdDecomp, fmVaRDecomp and fmEsDecomp.

paFm for Performance Attribution.

Examples

 # load data
data(managers, package = 'PerformanceAnalytics')

fit <- fitTsfm(asset.names = colnames(managers[,(1:6)]),
               factor.names = colnames(managers[,(7:9)]), 
               data=managers)
summary(fit)
fitted(fit)

# plot actual returns vs. fitted factor model returns for HAM1
plot(fit, plot.single=TRUE, asset.name="HAM1", which=1)

# plot(fit) # this presents a menu for group plots
# select desired plot from the menu (auto-looped for multiple plots)

# example using "subsets" variable selection
fit.sub <- fitTsfm(asset.names=colnames(managers[,(1:6)]),
                   factor.names=colnames(managers[,(7:9)]), 
                   data=managers, 
                   variable.selection="subsets", 
                   method="exhaustive", 
                   nvmin=2) 

# example using "lars" variable selection and subtracting risk-free rate
fit.lar <- fitTsfm(asset.names=colnames(managers[,(1:6)]),
                   factor.names=colnames(managers[,(7:9)]), 
                   rf.name="US 3m TR", 
                   data=managers, 
                   variable.selection="lars", 
                   lars.criterion="cv") 

braverock/factorAnalytics documentation built on Dec. 16, 2024, 1:05 p.m.