Skip to content

Commit

Permalink
#74 #69 switched out data in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinMShea committed Dec 23, 2021
1 parent d8aefca commit 4491e65
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions inst/tinytest/test-VIF.R
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)

0 comments on commit 4491e65

Please sign in to comment.