Skip to content

Commit

Permalink
Align cay quarterly dates properly with other monthly variables
Browse files Browse the repository at this point in the history
  • Loading branch information
eloualiche committed Aug 27, 2019
1 parent 72c9aec commit cafb1aa
Show file tree
Hide file tree
Showing 10 changed files with 369 additions and 357 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ tmp

# Specific files
docs/dividendpriceratio.tex
input/msi.sas7bdat
input/msi.sas7bdat

# Sources
src/paymon.R
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Makefile for PREDICTING THE EQUITY RISK PREMIUM
#
# Created on June 04th 2019
# Last modified on April 04th 2019
# Last modified on June 14th 2019
## --------------------------------------------------------------------------------------------------------


Expand All @@ -14,10 +14,12 @@ all: output/predict.csv readme.md
## DOWNLOAD THE DATA FROM WRDS
input/msi.sas7bdat:
rsync -aPvzh --stats --human-readable XXXX@wrds-cloud.wharton.upenn.edu:/wrds/crsp/sasdata/a_stock/msi.sas7bdat ./input/
@echo

## GENERATE PREDICTORS
tmp/predict.csv: src/import_predictors.R input/cay_current.csv input/msi.sas7bdat
R CMD BATCH $(R_OPTS) src/import_predictors.R log/import_predictors.log.R
@echo

## RUN REGRESSIONS
output/predict.csv: src/rp_measure.R tmp/predict.csv
Expand All @@ -27,6 +29,7 @@ output/predict.csv: src/rp_measure.R tmp/predict.csv
## OUTPUT RESULTS
readme.md: src/readme_in.md
cat src/readme_in.md tmp/reg_update.txt > readme.md
@echo

##
## --------------------------------------------------------------------------------------------------------
Expand Down
56 changes: 28 additions & 28 deletions log/R-session-info.log.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
ui X11
language (EN)
collate en_US.UTF-8
tz America/New_York
date 2019-06-10
tz Europe/Paris
date 2019-08-27

package * version date source
alfred * 0.1.6 2018-04-06 CRAN (R 3.5.1)
Expand All @@ -19,14 +19,14 @@
base * 3.5.1 2018-08-05 local
colorspace 1.3-2 2016-12-14 CRAN (R 3.5.1)
compiler 3.5.1 2018-08-05 local
crayon * 1.3.4 2019-05-19 Github (gaborcsardi/crayon@84be620)
data.table * 1.12.3 2019-06-03 local
crayon * 1.3.4 2019-07-10 Github (gaborcsardi/crayon@84be620)
data.table * 1.12.3 2019-07-02 local
datasets * 3.5.1 2018-08-05 local
devtools * 1.13.6 2018-06-27 CRAN (R 3.5.1)
digest 0.6.15 2018-01-28 CRAN (R 3.5.1)
dplyr * 0.8.0.9010 2019-03-31 Github (tidyverse/dplyr@6832c62)
dplyr * 0.8.3.9000 2019-07-05 Github (tidyverse/dplyr@b1b79b9)
forcats 0.3.0 2018-02-19 CRAN (R 3.5.1)
ggplot2 3.1.0.9000 2019-03-31 Github (tidyverse/ggplot2@230e8f7)
ggplot2 3.2.0.9000 2019-07-10 Github (tidyverse/ggplot2@125cc5f)
glue 1.3.0 2018-07-17 CRAN (R 3.5.1)
graphics * 3.5.1 2018-08-05 local
grDevices * 3.5.1 2018-08-05 local
Expand All @@ -43,24 +43,24 @@
methods * 3.5.1 2018-08-05 local
munsell 0.5.0 2018-06-12 CRAN (R 3.5.1)
parallel 3.5.1 2018-08-05 local
pillar 1.4.0.9002 2019-05-19 Github (r-lib/pillar@5ded57f)
pkgconfig 2.0.2 2019-05-19 Github (r-lib/pkgconfig@5453f79)
pillar 1.4.2.9000 2019-07-10 Github (r-lib/pillar@a6aa768)
pkgconfig 2.0.2 2019-07-10 Github (r-lib/pkgconfig@5453f79)
purrr 0.2.5 2018-05-29 CRAN (R 3.5.1)
R6 2.2.2 2017-06-17 CRAN (R 3.5.0)
Rcpp 1.0.1.3 2019-05-19 Github (RcppCore/Rcpp@6062d56)
Rcpp 1.0.1.3 2019-07-10 Github (RcppCore/Rcpp@d04eae8)
RcppRoll * 0.3.0 2018-06-05 CRAN (R 3.5.1)
rlang 0.3.4.9003 2019-05-19 Github (r-lib/rlang@6a232c0)
scales 1.0.0.9000 2019-03-31 Github (r-lib/scales@c374014)
rlang 0.4.0.9000 2019-07-10 Github (r-lib/rlang@a3d7e47)
scales 1.0.0.9000 2019-07-10 Github (r-lib/scales@7f6f4a5)
statar * 0.6.5 2017-07-06 CRAN (R 3.5.1)
stats * 3.5.1 2018-08-05 local
stringi 1.2.4 2018-07-20 CRAN (R 3.5.1)
stringr * 1.3.1 2018-05-10 CRAN (R 3.5.1)
tibble 2.1.1.9000 2019-05-19 Github (tidyverse/tibble@71b8ff6)
tibble 2.1.3.9000 2019-07-10 Github (tidyverse/tibble@f0d0106)
tidyr 0.8.3.9000 2019-05-19 Github (tidyverse/tidyr@b6ec78b)
tidyselect 0.2.5.9000 2019-05-19 Github (tidyverse/tidyselect@19150c0)
tidyselect 0.2.5.9000 2019-07-05 Github (tidyverse/tidyselect@013a51a)
tools 3.5.1 2018-08-05 local
utils * 3.5.1 2018-08-05 local
vctrs 0.1.0.9003 2019-05-19 Github (r-lib/vctrs@b1e6b81)
vctrs 0.2.0.9000 2019-07-10 Github (r-lib/vctrs@9c5b2cc)
withr 2.1.2 2018-03-15 CRAN (R 3.5.1)
zeallot 0.1.0 2018-01-28 CRAN (R 3.5.1)

Expand All @@ -74,22 +74,22 @@
ui X11
language (EN)
collate en_US.UTF-8
tz America/New_York
date 2019-06-10
tz Europe/Paris
date 2019-08-27

package * version date source
assertthat 0.2.0 2017-04-11 CRAN (R 3.5.1)
backports 1.1.2 2017-12-13 CRAN (R 3.5.1)
base * 3.5.1 2018-08-05 local
colorspace 1.3-2 2016-12-14 CRAN (R 3.5.1)
compiler 3.5.1 2018-08-05 local
crayon * 1.3.4 2019-05-19 Github (gaborcsardi/crayon@84be620)
data.table * 1.12.3 2019-06-03 local
crayon * 1.3.4 2019-07-10 Github (gaborcsardi/crayon@84be620)
data.table * 1.12.3 2019-07-02 local
datasets * 3.5.1 2018-08-05 local
devtools * 1.13.6 2018-06-27 CRAN (R 3.5.1)
digest 0.6.15 2018-01-28 CRAN (R 3.5.1)
dplyr 0.8.0.9010 2019-03-31 Github (tidyverse/dplyr@6832c62)
ggplot2 * 3.1.0.9000 2019-03-31 Github (tidyverse/ggplot2@230e8f7)
dplyr 0.8.3.9000 2019-07-05 Github (tidyverse/dplyr@b1b79b9)
ggplot2 * 3.2.0.9000 2019-07-10 Github (tidyverse/ggplot2@125cc5f)
glue 1.3.0 2018-07-17 CRAN (R 3.5.1)
graphics * 3.5.1 2018-08-05 local
grDevices * 3.5.1 2018-08-05 local
Expand All @@ -105,25 +105,25 @@
methods * 3.5.1 2018-08-05 local
munsell 0.5.0 2018-06-12 CRAN (R 3.5.1)
parallel 3.5.1 2018-08-05 local
pillar 1.4.0.9002 2019-05-19 Github (r-lib/pillar@5ded57f)
pkgconfig 2.0.2 2019-05-19 Github (r-lib/pkgconfig@5453f79)
pillar 1.4.2.9000 2019-07-10 Github (r-lib/pillar@a6aa768)
pkgconfig 2.0.2 2019-07-10 Github (r-lib/pkgconfig@5453f79)
purrr 0.2.5 2018-05-29 CRAN (R 3.5.1)
R6 2.2.2 2017-06-17 CRAN (R 3.5.0)
Rcpp 1.0.1.3 2019-05-19 Github (RcppCore/Rcpp@6062d56)
rlang 0.3.4.9003 2019-05-19 Github (r-lib/rlang@6a232c0)
Rcpp 1.0.1.3 2019-07-10 Github (RcppCore/Rcpp@d04eae8)
rlang 0.4.0.9000 2019-07-10 Github (r-lib/rlang@a3d7e47)
sandwich * 2.4-0 2017-07-26 CRAN (R 3.5.1)
scales 1.0.0.9000 2019-03-31 Github (r-lib/scales@c374014)
scales 1.0.0.9000 2019-07-10 Github (r-lib/scales@7f6f4a5)
stargazer * 5.2.2 2018-05-30 CRAN (R 3.5.1)
statar * 0.6.5 2017-07-06 CRAN (R 3.5.1)
stats * 3.5.1 2018-08-05 local
stringi 1.2.4 2018-07-20 CRAN (R 3.5.1)
stringr * 1.3.1 2018-05-10 CRAN (R 3.5.1)
tibble 2.1.1.9000 2019-05-19 Github (tidyverse/tibble@71b8ff6)
tibble 2.1.3.9000 2019-07-10 Github (tidyverse/tibble@f0d0106)
tidyr 0.8.3.9000 2019-05-19 Github (tidyverse/tidyr@b6ec78b)
tidyselect 0.2.5.9000 2019-05-19 Github (tidyverse/tidyselect@19150c0)
tidyselect 0.2.5.9000 2019-07-05 Github (tidyverse/tidyselect@013a51a)
tools 3.5.1 2018-08-05 local
utils * 3.5.1 2018-08-05 local
vctrs 0.1.0.9003 2019-05-19 Github (r-lib/vctrs@b1e6b81)
vctrs 0.2.0.9000 2019-07-10 Github (r-lib/vctrs@9c5b2cc)
wesanderson * 0.3.6 2018-04-20 CRAN (R 3.5.1)
withr 2.1.2 2018-03-15 CRAN (R 3.5.1)
zeallot 0.1.0 2018-01-28 CRAN (R 3.5.1)
Expand Down
53 changes: 28 additions & 25 deletions log/import_predictors.log.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Type 'q()' to quit R.
Log file for code executed at

> message(format(Sys.time(), "%a %b %d %X %Y"))
Mon Jun 10 11:42:28 2019
Tue Aug 27 21:49:24 2019
> ##################################################################################
>
>
Expand Down Expand Up @@ -93,7 +93,7 @@ The following objects are masked from ‘package:lubridate’:

The following objects are masked frompackage:dplyr:

between, first, last
between, coalesce, first, last

>
> check_file = file.exists("log/R-session-info.log.R")
Expand All @@ -117,20 +117,22 @@ Packages ----------------------------------------------------------------------
> ##################################################################################
> # 2. CAY
> dt_cay <- fread("./input/cay_current.csv", skip=1, header=T)
> dt_cay <- dt_cay[, .(dateym=as.integer(str_sub(date, 1, 6)), cay=cay) ]
> dt_cay <- dt_cay[, .(date_y=as.integer(str_sub(date, 1, 4)),
+ quarter=as.integer(str_sub(date, 5, 6)), cay=cay) ]
> dt_cay <- dt_cay[, .(dateym=date_y*100+quarter*3, cay) ]
> dt_cay
dateym cay
1: 195201 0.01646544
2: 195202 0.02551783
3: 195203 0.01633620
4: 195204 0.02542006
5: 195301 0.02543387
1: 195203 0.01646544
2: 195206 0.02551783
3: 195209 0.01633620
4: 195212 0.02542006
5: 195303 0.02543387
---
259: 201603 -0.02916950
260: 201604 -0.02042846
261: 201701 -0.02529660
262: 201702 -0.02655350
263: 201703 -0.02760623
259: 201609 -0.02916950
260: 201612 -0.02042846
261: 201703 -0.02529660
262: 201706 -0.02655350
263: 201709 -0.02760623
> ##################################################################################
>
>
Expand Down Expand Up @@ -203,20 +205,21 @@ Packages ----------------------------------------------------------------------
> dt_predict <- merge(dt_dp, dt_tbill, by = c("dateym"))
> dt_predict <- merge(dt_predict, dt_rmrf, by = c("dateym"), all.x = T)
> dt_predict <- merge(dt_predict, dt_cay, by = c("dateym"), all.x = T)
> dt_predict <- dt_predict[ !is.na(rmrf_y3) & !is.na(cay) ]
> dt_predict <- dt_predict[ !is.na(rmrf_y3) ]
> dt_predict <- dt_predict[ !is.na(cay) ]
> dt_predict[]
dateym dp rf rmrf_y3 cay
1: 195201 0.05812871 0.0157 0.17701996 0.01646544
2: 195202 0.05899675 0.0154 0.19964326 0.02551783
3: 195203 0.05817138 0.0159 0.18092953 0.01633620
4: 195204 0.05847809 0.0157 0.21473395 0.02542006
5: 195301 0.05472504 0.0196 0.21110181 0.02543387
1: 195203 0.05817138 0.0159 0.18092953 0.01646544
2: 195206 0.05739649 0.0170 0.21642173 0.02551783
3: 195209 0.05709103 0.0171 0.23193277 0.01633620
4: 195212 0.05522191 0.0209 0.22202729 0.02542006
5: 195303 0.05455042 0.0201 0.26058722 0.02543387
---
252: 201404 0.02159773 0.0003 0.08441447 -0.02747550
253: 201501 0.02090927 0.0003 0.12632351 -0.03462231
254: 201502 0.02098770 0.0002 0.09072934 -0.03462943
255: 201503 0.02111608 0.0003 0.08734601 -0.02656083
256: 201504 0.02109137 0.0002 0.08565438 -0.03519129
252: 201412 0.02094913 0.0003 0.09787760 -0.02747550
253: 201503 0.02111608 0.0003 0.08734601 -0.03462231
254: 201506 0.02111542 0.0002 0.09928718 -0.03462943
255: 201509 0.02153820 0.0002 0.15268617 -0.02656083
256: 201512 0.02191271 0.0023 0.07465740 -0.03519129
>
> fwrite(dt_predict, "./tmp/predict.csv")
> ##################################################################################
Expand All @@ -237,4 +240,4 @@ Packages ----------------------------------------------------------------------
>
> proc.time()
user system elapsed
1.670 0.187 2.484
1.400 0.153 2.169
Loading

0 comments on commit cafb1aa

Please sign in to comment.