RFPriceIndex

RFPriceIndex#

class sigtech.framework.indices.rf_price_index.RFPriceIndex

Baseclasses: AfterBuildMixin, CalculatedIndex

A class implementing rolling future indices. An RFPriceIndex tracks the performance of an index future and rolls the exposure during the rolling period.

The prices from the individual futures are weighted using the contract information.

Keyword arguments:

  • contract_code: Contract code.

  • contract_sector: Contract sector.

  • rolling_rule: Rolling rule. See RollSchedule for a list of available rules.

  • front_offset: Only required if rolling_rule is set to front, format is ‘-n,-m’, with n >= m.

  • front_offset_from_expiry: Specify to use expiry date as contract expiry date regardless of first notice day.

  • month_end_offset: Only required if rolling_rule set to prev_month. Defines how many business days before end of month to start and finish the roll (identical syntax to front_offset).

  • contract_offset: Offset to add to roll table. 1 for 1st month, 2 for 2nd month, etc. Optional, defaults to 0 meaning no offset from the raw roll table.

  • monthly_roll_days: Defines which business day of the month to roll the contracts on. Only required if rolling_rule not set to front or prev_month, defaults to None. If None, will default to 5:9 unless rici rule is used (see sigtech.framework.schedules.roll_schedules.methods.rolling_rici for more information). Note that 5,9 syntax is available for that field and will become the norm.

  • direction: long or short, defaults to long, this simply flips the sign of the weights

  • value_before_roll: Flag setting the contract rolled out to be used for daily valuation, defaults to False.

  • custom_roll_table: Allows passing of a custom roll table. The custom_roll_table can be of two types :

    • 'roll_table' is a list of strings of month codes to hold with key 0 (this year) or 1 (next year), e.g. ['H[0]', 'K[0]', 'K[0]', 'N[0]', 'N[0]', 'U[0]', 'U[0]', 'X[0]', 'X[0]', 'F[1]', 'F[1]', 'H[1]'] where the columns are Jan-Dec and correspond to the month during which to hold the said month code. E.g. F[1] in the 10th column means the strategy will hold next year’s Jan contract in October of this year. This will set rolling_rule to 'custom_roll'.

    • 'rolling_table' is a dataframe where the index is a datetime index and the and the columns are rolled_in_contract, rolled_out_contract, rolled_in_weight, rolled_out_weight and first_execution_date. This will set rolling_rule to 'custom_table'.

  • custom_roll_override: Pass a dict {year: roll schedule} to override custom_roll_table for particular years, otherwise custom_roll_table applies. This will set rolling_rule to 'custom_roll'.

  • back_adjusted: If True, calculate the back-adjusted price index by eliminating the price difference between the rolled-out and rolled-in contracts.

  • back_adjustment_type: If back_adjusted is true, user can choose between calculating the back adjustment by difference or by ratio. By default, the difference is used.

  • allow_roll_adjustments: If set to False, rolling adjustments to accommodate specific contract expirations are not allowed. If adjustments are allowed, warnings explaining the nature of the adjustments will be provided. Default is True.

Example of object creation:

import datetime as dtm

pi = sig.RFPriceIndex(
    currency='USD',
    start_date=dtm.date(2019, 1, 10),
    end_date=dtm.date(2020, 6, 4),
    rolling_rule='front',
    contract_code='C ',
    contract_sector='Comdty',
    front_offset='-10,-6'
)

h = pi.history()

returns = h / h.shift(1) - 1
allow_roll_adjustments: Optional[bool]
back_adjusted: Optional[bool]
back_adjustment_type: Optional[Literal['ratio', 'diff']]
contract_code: str
contract_offset: Optional[int]
contract_sector: str
custom_roll_override: Optional[dict]
custom_roll_table: Optional[Union[DataFrame, Series, list[str]]]
direction: Literal['short', 'long']
execution_time_input: Optional[time]
execution_timezone_input: Optional[str]
front_offset: Optional[str]
front_offset_from_expiry: Optional[bool]
month_end_offset: Optional[str]
monthly_roll_days: Optional[str]
roll_on_calendar_days: Optional[bool]
property roll_table

Strategy roll table.

rolling_rule: Optional[str]
property rolling_table

Strategy roll table.

value_before_roll: Optional[bool]
build(progress=False)

Calculate rolling table, weights and underlying returns.

build_rolling_table()

Builds the strategy’s rolling table.

Returns:

Built rolling table as a pandas DataFrame.

build_weight_df() deprecated

Build a dataframe of weights where future contracts are the columns.

calculate_underlying_history(weight_df, field=None, data_point=None)

Return a dataframe of underlying returns for given day.

Parameters:
  • weight_df – Weights Dataframe.

  • field – Name of field used.

  • data_point – Data point retrieved.

Returns:

pandas Series.

calculation_start_date()

Adjusted start date for any calculations.

earliest_start_date()

Earliest possible date where all dependencies can be computed.

get_rolling_future_strategy()

Returns an Rolling Future Strategy object with same parameters as RF Price Index

rolling_schedule()

Determine the dates to trade on.

schedule_information()

Return the schedule information for this instrument.

spot_dv01()

Returns a Series of spot_dv01 values for the underlying future that is currently part of the index