Last active
July 30, 2021 15:40
-
-
Save JoostImpink/bbad7a5c339ef6315d42ca357f2b31a3 to your computer and use it in GitHub Desktop.
Intraday return for SEC filings
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
## For each SEC filing stock return in the interval [time - before, time + after] is measured | |
# Set constants | |
before <- 0 | |
after <- 7200 | |
# load Grokit Nanex library | |
library(gtNanex) | |
# Load dataset with 8-K filings (symbol and timestamp)s | |
events <- Load(SECFilings) | |
# Load trades data | |
trades <- Load(nanex_trades)[Type == "Equity"] | |
# Create time and date variable from timestamp | |
events <- Generate(events, Date = Date(Time), Seconds = base::Time(Time)$as_seconds(), .overwrite = TRUE) | |
# Join on symbol-day | |
trades <- Join(trades, c(Symbol, Date), events, c(Symbol, Date)) | |
# Compute difference between filing timestamp and trading timestamp | |
trades <- Generate(trades, difference = Seconds - MsOfDay %/% 1000) | |
# Keep trades in event window | |
trades <- trades[.(-before) <= difference && difference <= .(after)] | |
# Construct variables for each event | |
info <- GroupBy(trades, c(ID, Time), | |
NumTrades = Count(), | |
SumVolume = Sum(Size), | |
SumRevenue = Sum(Size * Price), | |
OrderBy(LastTime = dsc(MsOfDay), inputs = c(LastPrice = Price, LastSize = Size), limit = 1), | |
OrderBy(FirstTime = asc(MsOfDay), inputs = c(FirstPrice = Price, FirstSize = Size), limit = 1)) | |
# Export | |
WriteCSV(info, "/data/SEC_filing_return.csv"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment