-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy path40_PlaceboPorts.R
83 lines (67 loc) · 1.91 KB
/
40_PlaceboPorts.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Computes placebo portfolios
# Andrew Chen 2020 01
# ==== ENVIRONMENT AND DATA ====
crspinfo = read.fst(
paste0(pathProject,'Portfolios/Data/Intermediate/crspminfo.fst')
) %>% # me, screens,
setDT()
crspret = read.fst(
paste0(pathProject,'Portfolios/Data/Intermediate/crspmret.fst')
) %>% # returns
setDT()
######################################################################
### SELECT SIGNALS
######################################################################
strategylist0 <- alldocumentation %>% filter(Cat.Signal == "Placebo")
strategylist0 <- ifquickrun()
#####################################################################
### COMPUTE PORTFOLIOS
#####################################################################
portmonth <- loop_over_strategies(
strategylist0
)
## EXPORT
writestandard(
portmonth,
pathDataPortfolios,
"PlaceboPortsFull.csv"
)
# SUMMARY STATS BY SIGNAL -------------------------------------------------
sumbase <- sumportmonth(
portmonth,
groupme = c("signalname", "port", "samptype"), Nstocksmin = 20
) %>%
left_join(
strategylist0 %>%
select(
sweight, q_cut, q_filt, portperiod, startmonth, filterstr,
everything()
),
by = "signalname"
)
## export
write_xlsx(
list(
ls_insamp_only = sumbase %>%
filter(
samptype == "insamp",
port == "LS"
) %>%
arrange(tstat),
full = sumbase
),
paste0(pathDataPortfolios, "PlaceboSummary.xlsx")
)
# FEEDBACK ON ERRORS -------------------------------------------------
tempsum <- sumportmonth(
portmonth,
groupme = c("signalname", "port", "samptype"), Nstocksmin = 20
)
print("The following ports are computed succesfully")
print(
tempsum %>% filter(port == "LS", samptype == "insamp") %>% arrange(tstat) %>% as.data.frame()
)
print("The following ports failed to compute")
print(
tempsum %>% filter(is.na(port)) %>% arrange(tstat) %>% as.data.frame()
)