Instrument

Instrument#

class sigtech.framework.instruments.base.Instrument

Baseclasses: HistoricalFrameworkObject

Subclasses: TradableInstrument, StrategyInstrument, Cash, Cashflow

A class representing any object that can be held within a portfolio. May not be directly tradable.

property alias: Optional[str]

Return an alias string used to represent the instrument in the portfolio table or other widgets.

currency: str
db_sector: Optional[str]
property expiry_date: date

Date when the contract expires, or last date on which we can trade.

property expiry_dt: datetime

Datetime when the contract expires, or last datetime at which we can trade.

property order_rounding

The value to which the units should be rounded to when calculating target units. Eg, 1000 would round to the nearest thousand :return: order rounding factor

ticker: Optional[str]
property trade_name: str

String identifier used for order/trade generation.

property valuation_time

Valuation time.

property valuation_tzinfo

Valuation timezone info.

get_valuation_data_point_and_source(dt: Union[datetime, date])

Method to get the data_point and data_source used for valuation :param dt: Input date/datetime.

Returns:

(date/datetime, data_point, data_source).

is_cash() bool

Return True if the instrument represents a cash/margin amount.

is_exchange_traded() bool

Return True if this instrument is traded on an exchange.

is_expandable() bool

Return True if the instrument can be expressed in terms of a portfolio of other instruments.

is_margin() bool

Check if the instrument represents a margin amount.

is_margin_accountable() bool

Check if an artificial margin is created to account for price changes in instruments that do not require immediate payment, but have a nominal value, e.g. futures. The actual P&L is computed through this artificial margin for such instruments.

is_notional_exposure_calc_needed() bool

Check if the notional exposure weight should be computed and included in the interactive portfolio table, e.g. for options, FX forwards, IR swaps.

is_option() bool

Return True if the instrument is an option.

is_otc() bool

Is this instrument OTC traded?

is_strategy() bool

Return True if this object is a strategy.

order_class() Any

Return the order class for timeline processing.

positions_to_units(position, dt)

Strategy scaling function: convert positions to number of units.

Parameters:
  • position – Number of positions.

  • dt – Input scaling date.

Returns:

Number of units.

positions_to_units_multiplier(dt)

Strategy scaling function: multiplier to convert positions to number of units.

Parameters:

dt – Input scaling date.

Returns:

multiplier

rounded_units(units, dt, to_trade=True)

The number of units allowed to trade for a specified target number of units, at the provided time.

This should be overwritten for instrument specific rounding logic.

The ‘to_trade’ flag switches between the use case of rounding the position for trade execution or for analysis The trading case can be different because the position is held for an extended time, while in the case of analysis you can consider the instantaneous amount of rounding allowed. An example of this applied is for the strategies where the underlying positions change over time.

Parameters:
  • units – Target number of units.

  • dt – Datetime.

  • to_trade – Boolean flag to switch between allowed to open for an extended time (True) or at that instant.

sizing_price(sizing_dt: datetime, ccy: Optional[str] = None, execution_dt: Optional[datetime] = None) float

On the base class this is just the valuation price, but can be overwritten in derived classes For specific instrument, price on sizing date (eg T-1), isn’t necessarily the best approximation for today’s price if the market doesn’t move.

For instance, for bonds, if coupon is to be paid on Settlement(T), then today’s price would be approximately yesterday price - coupon.

Parameters:
  • sizing_dt – Sizing datetime

  • ccy – Currency string identifier

  • execution_dt – Execution datetime

Returns:

Sizing price used in weight to model unit calculations

trade_price(trade_dt: datetime, trade_sign: float, include_trading_costs: Optional[bool] = True, transaction_type: Optional[str] = None, currency: Optional[str] = None, cache_trade_date: Optional[bool] = True) float

Price Traded - gives either bid or ask depending on trade type.

Parameters:
  • trade_dt – Trading datetime

  • trade_sign – Integer/float to determine if it is a buy or sell

  • include_trading_costs – If True will apply trading cost adjustment otherwise ignores it

  • transaction_type – String identifier to indicate type of transaction, e.g. ‘outright’, ‘roll’

  • currency – Currency string stub

  • cache_trade_date – Optional parameter to cache trading dates of instrument

Returns:

Trade/fill price

trade_price_adjustment(d: datetime, include_trading_costs: Optional[bool] = True, transaction_type: Optional[str] = None, cache_trade_date: Optional[bool] = True) float

Trade price adjustment (TPA) formula:

\[TPA_t = \alpha * S_t^{Mid} + \beta\]
Parameters:
  • d – Trading date

  • include_trading_costs – If True will apply trading cost adjustment otherwise ignores it

  • transaction_type – String identifier to indicate type of transaction, e.g. ‘outright’, ‘roll’

  • cache_trade_date – Optional parameter to cache trading dates of instrument

Returns:

Trade price adjustment

trade_price_adjustment_add(d: datetime, transaction_type: Optional[str] = None, cache_trade_date: Optional[bool] = True) float

Absolute adjustment to the mid price value in the trade price adjustment.

Parameters:
  • d – Trade date

  • transaction_type – String identifier to indicate type of transaction, e.g. ‘outright’, ‘roll’

  • cache_trade_date – Optional parameter to cache trading dates of instrument

trade_price_adjustment_multiply(d: datetime, transaction_type: Optional[str] = None, cache_trade_date: Optional[bool] = True) float

Multiplier to the mid price value in the trade price adjustment

Parameters:
  • d – Trade date

  • transaction_type – String identifier to indicate type of transaction, e.g. ‘outright’, ‘roll’

  • cache_trade_date – Optional parameter to cache trading dates of instrument

trade_price_ask(trade_dt: datetime, include_trading_costs: Optional[bool] = True, transaction_type: Optional[str] = None, currency: Optional[str] = None, cache_trade_date: Optional[bool] = True) float

Ask price at a point in time.

Parameters:
  • trade_dt – Trading datetime

  • include_trading_costs – If True will apply trading cost adjustment otherwise ignores it

  • transaction_type – String identifier to indicate type of transaction, e.g. ‘outright’, ‘roll’

  • currency – Currency string stub

  • cache_trade_date – Optional parameter to cache trading dates of instrument

Returns:

Ask trade price

trade_price_bid(trade_dt: datetime, include_trading_costs: Optional[bool] = True, transaction_type: Optional[str] = None, currency: Optional[str] = None, cache_trade_date: Optional[bool] = True) float

Bid price at a point in time.

Parameters:
  • trade_dt – Trading datetime

  • include_trading_costs – If True will apply trading cost adjustment otherwise ignores it

  • transaction_type – String identifier to indicate type of transaction, e.g. ‘outright’, ‘roll’

  • currency – Currency string stub

  • cache_trade_date – Optional parameter to cache trading dates of instrument

Returns:

Bid trade price

units_to_positions(units, dt)

Strategy scaling function: convert number of units to positions.

Parameters:
  • units – Number of units.

  • dt – Input scaling date.

Returns:

Number of positions.

valuation_dt(d: date) datetime

Valuation dt - datetime for a given valuation date.

valuation_point() str

Valuation Point - from this we can infer the field, time and timezone for the valuation.

valuation_price(dt: datetime, ccy: Optional[str] = None) float

Price on given valuation date.

Parameters:
  • dt – Input valuation date

  • ccy – Currency string identifier

Returns:

Valuation price for given input date dt

valuation_price_base(dt: Union[datetime, date]) float

Return the price in base currency on a given valuation date.

Parameters:

dt – Input date/datetime.

Returns:

float.

valuation_price_history(ccy: Optional[str] = None, field: Optional[str] = None, history_fill: Optional[bool] = None) DataFrame

Return a history of valuation (available for each weekday) prices.

Parameters:
  • ccy – Currency string identifier.

  • field – History field.

  • history_fill – Should gaps in history be forward filled?

Returns:

Valuation history.

valuation_price_series(dts: list[datetime.datetime], ccy: Optional[str] = None, intraday_data: Optional[bool] = True) Series

Series of prices at the gives date-times.

Parameters:
  • dts – List of date times

  • ccy – Currency string identifier

  • intraday_data – Use intraday data (optional, default True).

Returns:

Valuation price series