InspectWrapper#

class sigtech.framework.strategies.components.inspect_wrapper.InspectWrapper

Interface to inspect Strategy positions and actions.

bottom_cash_df(expand_grouped=True, dts: Optional[Union[str, datetime.datetime, list[datetime.datetime]]] = 'ACTION_PTS', build: bool = True, tzinfo: Optional[pytz.tzinfo.BaseTzInfo] = None)

Generate a DataFrame containing the bottom cash positions.

Options for the dts, as a string, include:

  • 'VALUATION_PTS' - Valuation points.

  • 'ACTION_PTS' - (Default) Every point where the strategy simulation performs an action on any level.

  • 'TOP_ORDER_PTS' - Points where the strategy enters and executes top level orders.

  • 'TOP_POSITION_CHG_PTS' - Points where the strategy’s top level holdings change.

  • 'EXECUTION_PTS' - Points where orders are executed.

  • 'HOLDING_CHG_PTS' - Points where the strategy’s top level holdings change (excluding orders).

Parameters
  • expand_grouped – Expand the bottom level positions (default is True).

  • dts – Datetime, iterable of Datetimes or String to identify times to include.

  • build – Boolean flag to build the strategy first (optional, default is True).

  • tzinfo – Timezone for time display (optional, the default takes the environment’s display timezone).

Returns

pandas Dataframe.

timeline_data(start_dt=None, end_dt=None, include_price_data=False)

Extract the strategy’s timeline data at a point in time or over a range of times.

Parameters
  • start_dt – start tz-aware datetime for data to filter.

  • end_dt – end tz-aware datetime for filter. If None, only data for the start_dt is retrieved.

  • include_price_data – Boolean flag to set whether the valuations and execution prices should be evaluated.

Returns

Dictionary of datetime : data pairs.

tree_df(dt: datetime.datetime, raw: Optional[bool] = False, flatten: Optional[bool] = False, flatten_strategy_orders: Optional[bool] = False)

Generate a DataFrame representation of the strategies contents for a specified datetime.

Parameters
  • dt – Datetime of data.

  • raw – Boolean flag to deactivate conversion to DataFrame. If True, a nested dictionary is generated.

  • flatten – Boolean flag to flatten the strategies and merge the positions.

  • flatten_strategy_orders – Boolean flag to flatten only the strategy orders and merge the positions.

Returns

Strategy contents as a Multi-Indexed DataFrame or nested dictionaries.

bottom_positions_df(expand_grouped=True, dts: Optional[Union[str, datetime.datetime, list[datetime.datetime]]] = 'ACTION_PTS', build: bool = True, tzinfo: Optional[pytz.tzinfo.BaseTzInfo] = None, unit_type: Optional[str] = 'MODEL')

Generate a DataFrame containing the bottom instrument positions.

Options for the dts, as a string, include:

  • 'VALUATION_PTS' - Valuation points.

  • 'ACTION_PTS' - (Default) Every point where the strategy simulation performs an action on any level.

  • 'TOP_ORDER_PTS' - Points where the strategy enters and executes top level orders.

  • 'TOP_POSITION_CHG_PTS' - Points where the strategy’s top level holdings change.

  • 'EXECUTION_PTS' - Points where orders are executed.

  • 'HOLDING_CHG_PTS' - Points where the strategy’s top level holdings change (excluding orders).

The unit type refers to the type of quantity shown, with the options:

  • 'MODEL' - Use the internal model units

  • 'TRADE' - Trade size, the units types vary between instruments and given by their position_type property.

Parameters
  • expand_grouped – Expand the bottom level positions (default is True).

  • dts – Datetime, iterable of Datetimes or String to identify times to include.

  • build – Boolean flag to build the strategy first (optional, default is True).

  • tzinfo – Timezone for time display (optional, the default takes the environment’s display timezone).

  • unit_type – Units used for quantity, defaults to 'MODEL'.

Returns

pandas Dataframe.

positions_df(dts: Optional[Union[str, datetime.datetime, list[datetime.datetime]]] = 'HOLDING_CHG_PTS', build: bool = True, tzinfo: Optional[pytz.tzinfo.BaseTzInfo] = None, unit_type: Optional[str] = 'MODEL')

Generate a DataFrame containing the instrument positions.

Options for the dts, as a string, include:

  • 'VALUATION_PTS' - Valuation points.

  • 'ACTION_PTS' - Every point where the strategy simulation performs an action on any level.

  • 'TOP_ORDER_PTS' - Points where the strategy enters and executes top level orders.

  • 'TOP_POSITION_CHG_PTS' - Points where the strategy’s top level holdings change.

  • 'EXECUTION_PTS' - Points where orders are executed.

  • 'HOLDING_CHG_PTS' - (Default) Points where the strategy’s top level holdings change (excluding orders).

The unit type refers to the type of quantity shown, with the options:

  • 'MODEL' - Use the internal model units

  • 'TRADE' - Trade size, the units types vary between instruments and given by their position_type property.

Parameters
  • dts – Datetime, iterable of Datetimes or String to identify times to include.

  • build – Boolean flag to build the strategy first (optional, default is True).

  • tzinfo – Timezone for time display (optional, the default takes the environment’s display timezone).

  • unit_type – Units used for quantity, defaults to 'MODEL'.

Returns

pandas Dataframe.

weights_df(bottom_level: bool = False, label: Optional[str] = None, dts: Optional[Union[str, datetime.datetime, list[datetime.datetime]]] = 'TOP_POSITION_CHG_PTS', build: bool = True, tzinfo: Optional[pytz.tzinfo.BaseTzInfo] = None) pandas.core.frame.DataFrame

Generate a DataFrame containing the instrument weights.

Options for the dts, as a string, include:

  • 'VALUATION_PTS' - Valuation points.

  • 'ACTION_PTS' - Every point where the strategy simulation performs an action on any level.

  • 'TOP_ORDER_PTS' - Points where the strategy enters and executes top level orders.

  • 'TOP_POSITION_CHG_PTS' - (Default) Points where the strategy’s top level holdings change.

  • 'EXECUTION_PTS' - Points where orders are executed.

  • 'HOLDING_CHG_PTS' - Points where the strategy’s top level holdings change (excluding orders).

Parameters
  • bottom_level – Use positions from the bottom level (default is False).

  • label – Grouping label to apply (default is None).

  • dts – Datetime, iterable of Datetimes or String to identify times to include.

  • build – Boolean flag to build the strategy first (optional, default is True).

  • tzinfo – Timezone for time display (optional, the default takes the environment’s display timezone).

Returns

pandas Dataframe.

cash_df(dts: Optional[Union[str, datetime.datetime, list[datetime.datetime]]] = 'HOLDING_CHG_PTS', build: bool = True, tzinfo: Optional[pytz.tzinfo.BaseTzInfo] = None)

Generate a DataFrame containing the cash positions.

Options for the dts, as a string, include:

  • 'VALUATION_PTS' - Valuation points.

  • 'ACTION_PTS' - Every point where the strategy simulation performs an action on any level.

  • 'TOP_ORDER_PTS' - Points where the strategy enters and executes top level orders.

  • 'TOP_POSITION_CHG_PTS' - Points where the strategy’s top level holdings change.

  • 'EXECUTION_PTS' - Points where orders are executed.

  • 'HOLDING_CHG_PTS' - (Default) Points where the strategy’s top level holdings change (excluding orders).

Parameters
  • dts – Datetime, iterable of Datetimes or String to identify times to include.

  • build – Boolean flag to build the strategy first (optional, default is True).

  • tzinfo – Timezone for time display (optional, the default takes the environment’s display timezone).

Returns

pandas Dataframe.

cash_value_series(dts: Optional[Union[str, datetime.datetime, list[datetime.datetime]]] = 'ACTION_PTS', build: bool = True, tzinfo: Optional[pytz.tzinfo.BaseTzInfo] = None, exclude_offset: bool = False)

Return the valuation of cash holdings in the strategy’s currency.

Options for the dts, as a string, include:

  • 'VALUATION_PTS' - Valuation points.

  • 'ACTION_PTS' - (Default) Every point where the strategy simulation performs an action on any level.

  • 'TOP_ORDER_PTS' - Points where the strategy enters and executes top level orders.

  • 'TOP_POSITION_CHG_PTS' - Points where the strategy’s top level holdings change.

  • 'EXECUTION_PTS' - Points where orders are executed.

  • 'HOLDING_CHG_PTS' - Points where the strategy’s top level holdings change (excluding orders).

Parameters
  • dts – Datetime, iterable of Datetimes or String to identify times to include.

  • build – Boolean flag to build the strategy first (optional, default is True).

  • tzinfo – Timezone for time display (optional, the default takes the environment’s display timezone).

  • exclude_offset – exclude margin valuation offset positions, defaults to False.

Returns

Series of cash valuations.

position_value_series(dts: Optional[Union[str, datetime.datetime, list[datetime.datetime]]] = 'ACTION_PTS', build: bool = True, tzinfo: Optional[pytz.tzinfo.BaseTzInfo] = None, exclude_offset: bool = False)

Return the valuation of position holdings (excluding cash) in the strategy’s currency.

Options for the dts, as a string, include:

  • 'VALUATION_PTS' - Valuation points.

  • 'ACTION_PTS' - (Default) Every point where the strategy simulation performs an action on any level.

  • 'TOP_ORDER_PTS' - Points where the strategy enters and executes top level orders.

  • 'TOP_POSITION_CHG_PTS' - Points where the strategy’s top level holdings change.

  • 'EXECUTION_PTS' - Points where orders are executed.

  • 'HOLDING_CHG_PTS' - Points where the strategy’s top level holdings change (excluding orders).

Parameters
  • dts – Datetime, iterable of Datetimes or String to identify times to include.

  • build – Boolean flag to build the strategy first (optional, default is True).

  • tzinfo – Timezone for time display (optional, the default takes the environment’s display timezone).

  • exclude_offset – exclude margin valuation offset positions, defaults to False.

Returns

Series of position valuations in the strategy currency.

display_holdings(full=False, separate=False, start_dt=None, end_dt=None)

Generate a string representation for the holdings.

Parameters
  • full – If True, all changes in positions are included (in addition to standard order execution points).

  • separate – Separate the strategy order positions/orders from the holdings.

  • start_dt – Start datetime for representation.

  • end_dt – End datetime for representation.

display_run_details(start_dt=None, end_dt=None, build=True)

Generate a detailed string representation for the strategy’s construction.

Parameters
  • start_dt – Start datetime for representation.

  • end_dt – End datetime for representation.

  • build – Ensure the strategy is built first.

evaluate_positions(aum_dict, include_cash=True, include_margin=True)

Generate a dataframe of historic positions and weights or a sequence of times.

Parameters
  • aum_dict – Dictionary of time, aum entries.

  • include_cash – Boolean flag to specify if cash should be included.

  • include_margin – Boolean flag to specify if margin should be included.

Returns

DataFrame of positions.

evaluate_trades(dt, aum=None, formatted=False, size_date=None, include_weights=False, include_cash=False, include_margin=False, tzinfo: Optional[pytz.tzinfo.BaseTzInfo] = None, rounded_units: Optional[bool] = None, summary: Optional[bool] = False, dt_orders_only: Optional[bool] = False)

Calculate a table summarizing the trading positions and orders.

The positions and orders are rounded to discrete quantities.

This can lead to an ambiguity in the place of orders to match positions.

Entries for this are located in the ROUNDING_ADJ column.

Parameters
  • dt – Datetime at which to evaluate the positions and orders.

  • aum – Assets under management to scale for (default is strategies model nav).

  • formatted – Convert values to formatted strings (default is False).

  • size_date – Date to use for portfolio valuation (defaults to the strategy’s size_date on dt’s date).

  • include_weights – Include weights in the table (default is False).

  • include_cash – Include cash in the table (default is False).

  • include_margin – Include margin in the table (default is False).

  • tzinfo – Timezone for time display (optional, the default takes the environment’s display timezone).

  • rounded_units – If True, the trade quantities are rounded (default depend on instrument type).

  • summary – Summarized output with only CURRENT, TARGET and TRADE (default is False).

  • dt_orders_only – Only get the trades on dt.date (excluding the following days) (default is False).

Returns

DataFrame of positions and orders.

historic_positions(dts=None, start_date=None, end_date=None, include_cash=True, include_margin=True, fixed_aum=None, filter_unchanged=False, tzinfo: Optional[pytz.tzinfo.BaseTzInfo] = None)

Generate a dataframe of historic positions and weights.

Options for the dts, as a string, include:

  • ‘VALUATION_PTS’ - Valuation points.

  • ‘ACTION_PTS’ - Every point where the strategy simulation performs an action on any level.

  • ‘TOP_ORDER_PTS’ - Points where the strategy enters and executes top level orders.

  • ‘TOP_POSITION_CHG_PTS’ - Points where the strategy’s top level holdings change.

  • ‘EXECUTION_PTS’ - Points where orders are executed.

  • ‘HOLDING_CHG_PTS’ - Points where the strategy’s top level holdings change (excluding orders).

Parameters
  • dts – Datetime, iterable of Datetimes or String to identify times to include.

  • start_date – start date

  • end_date – end date

  • fixed_aum – fixed AUM float used for position scaling, if None strategy NAV is used.

  • include_cash – boolean flag to specify if cash should be included

  • include_margin – boolean flag to specify if margin should be included

  • filter_unchanged – boolean flag to specify if unchanged units should be excluded.

  • tzinfo – Timezone for time display (optional, the default takes the environment’s display timezone).

Returns

bottom_trades_df(tzinfo: Optional[pytz.tzinfo.BaseTzInfo] = None, net_trades: Optional[bool] = True)

Generate a DataFrame containing the bottom instrument trades at every point they are updated.

Parameters
  • tzinfo – Timezone for time display (optional, the default takes the environment’s display timezone).

  • net_trades – Allow user to net all trades on same asset at same date (optional, True by default).

Returns

pandas Dataframe.

display_sizing_calculation(start_dt: Optional[datetime.datetime] = None, end_dt: Optional[datetime.datetime] = None, build: bool = True)

Print Sizing calculation for decision dt from start_dt to end_dt when specified.

Parameters
  • start_dt – start datetime.

  • end_dt – end datetime.

  • build – Ensure the strategy is built first.

Returns

trade_timings_df(tzinfo: typing.Optional[pytz.tzinfo.BaseTzInfo] = <UTC>)

Generate a DataFrame containing the decision, execution and default size time for each trade in the strategy. The size time will only be correct if not overridden by the strategy when placing the position.

Parameters

tzinfo – Timezone for time display (optional, the default is UTC).

Returns

pandas Dataframe.

bottom_trades_pnl_df(tzinfo: Optional[pytz.tzinfo.BaseTzInfo] = None, closing_only: Optional[bool] = False)

Generate a dataframe with pnl generated by each trade from bottom_trade_df. The table contains the following data: * instrument_name: instrument ticker. * trade_start_dt: opening datetime of the position affected by the trade. * transaction_type: outright, roll … * trade_side: long or short * trade_size: quantity traded on that position * trade_price: price at which quantity was traded. * trade_value: value of the trade. * event_type: open, close, increase, decrease * position_size: size of the position after the trade. * position_value: value of the position after the trade. * breakeven_price: required price to breakeven the position. * pnl: profit and loss of the position since last trade. * pnl_cum: cumulated profit and loss of the position since opening trade. * perf: performance of the position since last trade. * perf_cum: cumulated performance of the position since opening trade.

Parameters
  • tzinfo – Timezone for time display (optional, the default takes the environment’s display timezone).

  • closing_only – if true, the method returns only the closing trades data. False by default.

Returns

pandas Dataframe.