End-of-day pricing and portfolio valuation and Benchmark portfolio performance.
Top pre-market movers
Overview
This example demonstrates how to use the Historical client to retrieve OHLCV-1m bar aggregate data to analyze the largest movers in the Nasdaq pre-market. Equities which are trading in the early pre-market may be reacting to recent events or news announcements, relevant to a single stock, an industry, or an entire sector. This notable pre-market activity usually manifests in large price changes and volume, which significantly exceed the normal range, and may be indicative of subsequent moves after the session open.
For our purposes we'll define the pre-market as 4:00 AM to 9:30 AM in the 'US/Eastern' time zone, which accounts for changes for daylight savings.
You can find more information on Nasdaq trading hours here.
Nasdaq dataset
For this example, we'll use the Nasdaq TotalView-ITCH
dataset, whose dataset ID is XNAS.ITCH
. You'll need to pass this in as the dataset
parameter of any API or client method.
OHLCV-1m schema
The data we need will come from the OHLCV-1m schema.
The OHLCV family of schemas contain the opening, high, low, and closing prices, as well
as the aggregated volume of trades occurring within each time interval. Since we are interested in
a specific market session, we'll use an interval of one minute, which is specified by the
suffix -1m
.
Example
import databento as db
import pandas as pd
# Create a historical client
client = db.Historical(key="YOUR_API_KEY")
# Next, request OHLCV-1m bars for the time range we're interested in
data = client.timeseries.get_range(
dataset="XNAS.ITCH",
schema="ohlcv-1m",
symbols="ALL_SYMBOLS",
start=pd.Timestamp("2023-06-06T04:00", tz="US/Eastern"),
end=pd.Timestamp("2023-06-06T09:30", tz="US/Eastern"),
)
# We need to obtain the symbology mappings for 'ALL_SYMBOLS'
symbology = data.request_symbology(client)
# This allows us to populate the 'symbol' column when we convert to a DataFrame
data.insert_symbology_json(symbology)
# Convert to dataframe with timestamps in the US/Eastern timezone
df = data.to_df(tz="US/Eastern")
# Combine the first open, last close and volume sum into a DataFrame
df_moves = df.groupby("symbol").agg({"open": "first", "close": "last", "volume": "sum"})
# Calculate the change from start to end of pre-market
df_moves["change"] = (df_moves["close"] - df_moves["open"]) / df_moves["open"]
df_moves = df_moves.sort_values(by="change", ascending=False)
# Display the top 10 largest movers
print(df_moves.head(10))
Result
open close volume change
symbol
CRGOW 0.1564 0.3200 1977 1.046036
ZVZZT 13.0200 25.0000 369 0.920123
MLECW 0.0974 0.1798 3394 0.845996
HOTH 2.0300 3.5400 1600550 0.743842
BOAC+ 0.0458 0.0782 700 0.707424
RCRT 0.1918 0.2953 575273 0.539625
ATMCR 0.1489 0.2237 400 0.502351
SBFMW 0.5938 0.8915 305 0.501347
RCRTW 0.0229 0.0302 300 0.318777
TCBPW 0.0436 0.0573 300 0.314220
See also