Skip to content

Instantly share code, notes, and snippets.

@JoostImpink
Last active July 30, 2021 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JoostImpink/bbad7a5c339ef6315d42ca357f2b31a3 to your computer and use it in GitHub Desktop.
Save JoostImpink/bbad7a5c339ef6315d42ca357f2b31a3 to your computer and use it in GitHub Desktop.
Intraday return for SEC filings
## 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