The code below depends on some tables in my crsp schema, including crsp.rets, crsp.anncdates, and crsp.trading_dates.
It also depends on a custom aggregate function (product) I have in PostgreSQL.
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag