quantdata.ncde.voluvol.generate#

NCDE VoluVol data set generator#

This file contains then benchmark generator for the Volume & Volality benchmark.

class quantdata.ncde.voluvol.generate.ExperimentScope(tickers=<factory>, date_range=DateRange(start=datetime.date(2025, 1, 1), end=datetime.date(2025, 1, 31), exclude_half_days=True), forecast_horizon_min=15)[source]#

Bases: object

Definition of the experiment

date_range: DateRange = DateRange(start=datetime.date(2025, 1, 1), end=datetime.date(2025, 1, 31), exclude_half_days=True)#
forecast_horizon_min: float = 15#
quantdata.ncde.voluvol.generate.generate_ticker_day(ticker, d, forecast_horizon_min)[source]#

Generate an experiment entry for a given date d for a given ticker.

  • Converts time stamps into milliseconds since market open.

  • Computes forward floating volume, cash volume and (annualized) volatilities as forecast “targets” for the horizon given by forecast_horizon_min.

  • Drops time stamps within forecast_horizon_min before the close.

This function is cached with HDF5 for fast i/o. All data are return in 32 bit precision.

Parameters:
  • ticker (str) – Ticker symbol, e.g. “AAPL”

  • date (datetime.date) – Date for which to generate the data, e.g. date(2025, 1, 2)

  • forecast_horizon_min (int) – Rolling forecast horizon in minutes, e.g. 15

Returns:

Results – A dictionary containing “trades”, “quotes”, and forward “targets” for the given ticker and date. The schema are:

  • quotes: “time_of_day_ms”, “bid_price”, “bid_size”, “ask_price”, “ask_size”

  • trades: “time_of_day_ms”, “price”, “size”

  • targets: “time_of_day_ms”, “log_volume”, “log_cash_volume”, “volatility”. The latter represent the future values from time_of_day_ms to time_of_day_ms + forecast_horizon_min[ms].

The “time_of_day_ms” column represents the time in milliseconds since the market open, and is aligned across trades, quotes, and targets. The “targets” are forward looking values computed at each trade timestamp for the given forecast horizon.

The “time_of_day_ms” entries are returned as int32 while the other values are returned as float32 for efficient storage and i/o.

Return type:

dict

class quantdata.ncde.voluvol.generate.SampleID(ticker, date)[source]#

Bases: object

Identifier for a sample, consisting of a ticker and a date.

class quantdata.ncde.voluvol.generate.ExperimentLoader(experiment_scope, *, pool_config=<cdxcore.jcpool.JCPoolConfig object>, verbose=<cdxcore.verbose.Context object>)[source]#

Bases: object

Utility class to load experiment data.

property samples: dict[SampleID, dict[str, int]]#

Returns a dictionary of samples, indexed by SampleID, each containing a dictionary with the counts of trades, quotes, and targets.

get_sample_id(sample_id)[source]#

Return the SampleID for a given sample id, typically for an integer index.

get_sample(sample_id, *, cache_only=False)[source]#

Load the data for a given sample id. The data is returned as a dictionary containing “trades”, “quotes”, and “targets” for the given ticker and date. The schema are:

  • quotes: “time_of_day_ms”, “bid_price”, “bid_size”, “ask_price”, “ask_size”

  • trades: “time_of_day_ms”, “price”, “size”

  • targets: “time_of_day_ms”, “log_volume”, “log_cash_volume”, “volatility”. The latter represent the future values from time_of_day_ms to time_of_day_ms + forecast_horizon_min[ms].

The “time_of_day_ms” column represents the time in milliseconds since the market open, and is aligned across trades, quotes, and targets. The “targets” are forward looking values computed at each trade timestamp for the given forecast horizon.

The “time_of_day_ms” entries are returned as int32 while the other values are returned as float32 for efficient storage and i/o.

Parameters:
  • sample_id (SampleID | int) – Either the sample id containing the ticker and date for which to load the data, or an integer index.

  • cache_only (bool) – If True, only load the data from the cache, if available. Default is False.

Returns:

Result – See above.

Return type:

dict