Created
May 7, 2016 14:45
-
-
Save iangow/7c88670ce1bccb6decc5159b16967003 to your computer and use it in GitHub Desktop.
Code to illustrate calculation of returns in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sys.setenv(PGHOST="iangow.me", PGDATABASE="crsp") | |
devtools::source_url(paste0("https://raw.githubusercontent.com/iangow/", | |
"acct_data/master/code/getEventReturnsDaily.R")) | |
sql <- " | |
SELECT DISTINCT permno, comnam, gvkey, rdq | |
FROM crsp.stocknames AS a | |
INNER JOIN crsp.ccmxpf_linktable AS b | |
ON a.permno=b.lpermno | |
INNER JOIN comp.fundq | |
USING (gvkey) | |
WHERE siccd=3571 AND datadate BETWEEN '2009-09-01' AND '2009-12-31' | |
LIMIT 100" | |
library(RPostgreSQL) | |
pg <- dbConnect(PostgreSQL()) | |
events <- dbGetQuery(pg, sql) | |
rs <- dbDisconnect(pg) | |
rets <- getEventReturns(events$permno, events$rdq, days.before=0, days.after=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment