From 4491e65d6c4925700c7316b91c836b8a246ca6e4 Mon Sep 17 00:00:00 2001 From: JustinMShea Date: Wed, 22 Dec 2021 23:39:31 -0600 Subject: [PATCH] #74 #69 switched out data in unit test --- inst/tinytest/test-VIF.R | 48 ++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/inst/tinytest/test-VIF.R b/inst/tinytest/test-VIF.R index 7b0c7b14..7c05d0c8 100644 --- a/inst/tinytest/test-VIF.R +++ b/inst/tinytest/test-VIF.R @@ -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) \ No newline at end of file