forked from simonyanchen/ChinaEquityRiskModel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModel.R
28 lines (26 loc) · 984 Bytes
/
Model.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#Model
Model.Regression <-
function(Input.Data)
{
FactorRet <- matrix(0, nrow = length(Input.Data), ncol = length(names(Input.Data[[1]]))-1,
dimnames = list(names(Input.Data),c(names(Input.Data[[1]])[-1])))
RSquared <- matrix(0, nrow = length(Input.Data), ncol = 1,
dimnames = list(names(Input.Data),"RSquared"))
for(i in c(1:length(Input.Data))){
Test <- Input.Data[[i]]
Test[is.na(Test)] <- 0
#Temporary replace NA with zero
#TBD
FitResult <- lm(Return~.-1,data = Test)
FitResult.Summary <- summary(FitResult)
FactorRet[i,] <- FitResult$coefficients
RSquared[i,] <- FitResult.Summary$r.squared
}
FactorRet <- as.data.frame(FactorRet)
RSquared <- as.data.frame(RSquared)
Result <- list()
Result[["FactorRet"]] <- FactorRet
Result[["FactorRetCum"]] <- cumprod(FactorRet / 100 + 1)
Result[["RSquared"]] <- RSquared
return(Result)
}