HistoricalFrameworkObject

HistoricalFrameworkObject#

class sigtech.framework.instruments.base.HistoricalFrameworkObject

Baseclasses: AfterHistoryMixin, FrameworkObject

Subclasses: Instrument, MultiDimensionalObjectBase, Fix, IntradayFix, MacroEconomicFix, DividendCurve, Index, BaseCalendar, Universe, SIGMaster, EconomicSeries, Fund, FundShareClass, Quote

A class supporting historical levels on a series of reference dates.

We only allow reference to one field - this will be price for instruments and the reference value for other index levels - e.g. fixes or economic data.

property allowed_clean_sparse_fields

List of fields that are allowed to have na values on clean history.

property asset_description: str

String representing the underlying asset, or None if no assets exist.

property available_data_points: Optional[list[sigtech.framework.infra.data_adapter.common.DataPoint]]

Available data points for this object.

property base_name

Primary name used to identify the object.

property data_format

Return the data format associated with sparse history, i.e. ROWISE or COLUMNAR.

property data_point

Field used when retrieving history.

property data_source

Data provider of the instrument.

property data_source_all: Optional[list[str]]

Available data points for this object.

property default_data_point

Default data point for this object.

property history_fields: list[str]

The fields of history retrieved for this instrument.

property intraday_history_fields: list[str]

The intraday fields of history retrieved for this instrument.

intraday_times: Optional[list]
intraday_tz_str: Optional[str]
price_factor: Optional[float]
property prime_history_field: str

The main history field returned by default.

property prime_intraday_history_field

The main intraday history field returned by default.

property supplementary_fields: list[str]

Additional fields available for the group.

use_price_factor: Optional[bool]
add_custom_history(history: Series, field: str = 'LastPrice', data_point: Optional[DataPoint] = None)

Add custom history data for this object. If multiple, conflicting custom histories are added only the last addition will be returned from history.

Parameters:
  • historypd.Series of custom history with index as tz-naive, pd.DatetimeIndex dates.

  • field – Name of history field to overwrite.

  • data_point – Optional DataPoint to specify timing of custom history.

cache_history(fields: list, data_point: DataPoint, start_dt: datetime = None, end_dt: datetime = None, **kwargs)

Ensure history data is cached

calendar_schedule() Schedule

A calendar schedule - a schedule that is corresponding to a history schedule, but without min and max dates set.

Returns:

Calendar schedule instance for the instrument

data_available(d: Optional[date] = None) bool

Method to indicate if pricing data is available for a given date.

Parameters:

d – Date of interest (optional), if not provided it will take as of date of the environment.

data_df(data_point: DataPoint = None, multi_index: bool = False, drop_nan_cols: bool = False, intraday: bool = False, intraday_period: timedelta = datetime.timedelta(seconds=60), pretty_print: bool = True) DataFrame

Return a DataFrame containing all data available for this object.

Parameters:
  • data_point – Optional data point used to load the object history.

  • multi_index – If set to True, rows are uniquely indexed by a multi index (if applicable). Default is False.

  • drop_nan_cols – If set to True, all-NaN columns are dropped. Default is False.

  • intraday – If set to True, intraday data is returned (if applicable). Default is False.

  • intraday_period – Desired periodicity of intraday data (if applicable). Default is 1 minute.

  • pretty_print – If set to True, formatting is added to columns names and data values. Rates will be represented as percentage number instead of decimal number (e.g. 3.5 instead of 0.035).

Returns:

pandas DataFrame.

data_validation(sparse_series)

Additional data checks can be implemented in sub classes here.

group() any

Group of this object.

has_preloaded_history(fields=None, data_point=None)

Check if the object has preloaded history.

history(field: str = None, adjust_for_delay: bool = False, date_index: bool = False, data_point: Optional[DataPoint] = None, datetime_index: bool = False) Series

Method to retrieve time series for objects overlaid by history schedule and publication delay (optional). If the given field does not exist, an empty series will be returned.

Parameters:
  • field – Optional - Returns time series for field - defaults to prime history field.

  • adjust_for_delay – Optional - Returns adjusted index if there is a publication delay.

  • date_index – Optional - Convert the timestamp index to dates.

  • data_point – data point to retrieve - from self.available_data_points

  • datetime_index – Optional - if True, populate the time and UTC timezone information in the index.

Returns:

pd.Series.

history_dates()

Return all the dates we should have actual history values.

history_dates_actual()

Return all the dates we have actual history values.

history_dates_eventual()

Return all the dates we will eventually have history values.

history_df(fields: list[str] = None, data_point: DataPoint = None, multicolumn: bool = None) deprecated

Return the object history dataframe.

Parameters:
  • fields – list of fields. If not supplied, self.history_fields will be used

  • data_point – optional data point used to load the object history.

  • multicolumn – Deprecated input. This will be removed in future releases.

Returns:

pd.DataFrame.

history_end_date() date

Eventual history end date, truncated to the as of date - the day on which history should end.

history_end_date_actual()

The last date we have an actual value for.

history_end_date_eventual() date

Last date for which data will be available - typically date.max if no end date set.

history_end_timestamp() Timestamp
Returns:

First timestamp for which data should be available

history_schedule() Schedule

Object describing dates on which history is available and the corresponding delivery times.

Returns:

History schedule instance for the instrument.

history_start_date() date

First date for which data should be available.

history_start_timestamp() Timestamp
Returns:

First timestamp for which data should be available

intraday_history(field=None, period=None, start_dt=None, end_dt=None, daily_timeseries_time=None, daily_timeseries_tz=None, filter_by_trading_sessions=False, timezone=None, convert_yield_to_price=True)

Retrieve intraday history for this instrument as a Series.

Parameters:
  • field – field name in self.intraday_history_fields.

  • period – a dtm.timedelta giving the desired periodicity of the data.

  • start_dt – optional tz-aware dtm.datetime giving a desired start point.

  • end_dt – optional tz-aware dtm.datetime giving a desired end point.

  • daily_timeseries_time – if supplied, the intraday data will be down-sampled to daily data snapped at this time.

  • daily_timeseries_tz – timezone for the above. Optional, if not supplied defaults to self.valuation_tzinfo

  • filter_by_trading_sessions – If False ``(default), return all available data. If ``True return data during the main trading session. If a string/list(string), return data during the trading session(s) of that name according to self.group().session_data(). See intraday_trading_sessions() for list of sessions.

  • timezone – set the timezone of the returned series to this value

  • convert_yield_to_price – applies yield to price conversion for yield quoted futures, e.g. AUD bond futures

Returns:

A (possibly sparse) pd.Series with a DateTimeIndex. Times should be tz-aware UTC.

intraday_history_df(fields=None, period=None, start_dt=None, end_dt=None, daily_timeseries_time=None, daily_timeseries_tz=None, filter_by_trading_sessions=False, timezone=None, convert_yield_to_price=True)

Retrieve intraday history for this instrument as a dataframe.

Parameters:
  • fields – a list of field names all in self.intraday_history_fields.

  • period – a dtm.timedelta giving the desired periodicity of the data.

  • start_dt – optional tz-aware dtm.datetime giving a desired start point.

  • end_dt – optional tz-aware dtm.datetime giving a desired end point.

  • daily_timeseries_time – if supplied, the intraday data will be down-sampled to daily data snapped at this time.

  • daily_timeseries_tz – timezone for the above. Optional, if not supplied defaults to self.valuation_tzinfo

  • filter_by_trading_sessions – If False ``(default), return all available data. If ``True return data during the main trading session. If a string/list(string), return data during the trading session(s) of that name according to self.group().session_data()

  • timezone – set the timezone of the returned dataframe to this value

  • convert_yield_to_price – applies yield to price conversion for yield quoted futures, e.g. AUD bond futures

Returns:

A (possibly sparse) pd.DataFrame with a DateTimeIndex. Times should be tz-unaware UTC.

intraday_trading_sessions()

Gets ths list of trading sessions available as per the Copp-Clarke session data for this product group

publication_delay() str

Publication delay of data for this instrument.

realign_history(series)

Realign history series to proper business days.

Parameters:

series – Input series.

Returns:

Realigned history series.

set_preloaded_history(data) None

Set the preloaded history of the object.

Parameters:

data – History data.

set_sparse_history(data) None

Set the sparse history of the object.

Parameters:

data – History data.

trade_schedule() Schedule

Schedule giving trade dates + last time at which we can trade for that date (i.e. notice time for funds).

Returns:

Trade schedule instance for the instrument

wait_for_live_data(period: Optional[Union[datetime, str]] = None)

Waits until live data is collected up to and including env.asofdatetime :param period: period of the live intraday data to wait for (defaults to 1 minute)