-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
d8aefca
commit 4491e65
Showing
1 changed file
with
34 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,39 @@ | ||
#Load the data | ||
data("factorDataSetDjia5Yrs") | ||
|
||
#Fit a Ffm | ||
fit <- fitFfm(data=factorDataSetDjia5Yrs, asset.var="TICKER", ret.var="RETURN", | ||
date.var="DATE", exposure.vars="SECTOR") | ||
# load data | ||
data(stocksCRSP) | ||
data(factorsSPGMI) | ||
|
||
stocks_factors <- selectCRSPandSPGMI(stocks = stocksCRSP, factors = factorsSPGMI, | ||
dateSet = c("2006-01-31", "2010-12-31"), | ||
stockItems = c("Date", "TickerLast", | ||
"CapGroup", "Sector", | ||
"Return", "Ret13WkBill", | ||
"mktIndexCRSP"), | ||
factorItems = c("BP", "LogMktCap", "SEV"), | ||
capChoice = "SmallCap", | ||
Nstocks = 20) | ||
|
||
# fit a fundamental factor model with style variables BP and LogMktCap | ||
|
||
fundamental_model <- fitFfm(data = stocks_factors, | ||
asset.var = "TickerLast", | ||
ret.var = "Return", | ||
date.var = "Date", | ||
exposure.vars = c("BP", "LogMktCap") | ||
) | ||
|
||
#test for output lengths | ||
out <- vif(fundamental_model) | ||
expect_equal(length(out), 2) | ||
|
||
# Fit a Fundamental Sector Factor Model with Intercept | ||
sector_model <- fitFfm(data = stocks_factors, | ||
asset.var = "TickerLast", | ||
ret.var = "Return", | ||
date.var = "Date", | ||
exposure.vars = "Sector", | ||
addIntercept = TRUE) | ||
|
||
#Test for errors when less than 2 exploratory variables are used to fit model. | ||
expect_error(vif(fit),"At least 2 continous variables required to find VIF") | ||
expect_error(vif(sector_model),"At least 2 continous variables required to find VIF") | ||
|
||
#Fit a Ffm | ||
fit.1 <- fitFfm(data=factorDataSetDjia5Yrs, asset.var="TICKER", ret.var="RETURN", | ||
date.var="DATE", exposure.vars=c("SECTOR", "P2B", "SIZE", "MKTCAP", "ENTVAL")) | ||
|
||
|
||
#test for output lengths | ||
out <- vif(fit.1) | ||
expect_equal(length(out), 2) |