qis.HistoricalScenarioSelection

class qis.HistoricalScenarioSelection(factor='Equity', start_date='2006-01-01', count=10, end_date=None, ascending=True, return_type=ReturnTypes.LOG)[source]

Bases: object

Select the worst monthly returns of a named factor and replay full vectors.

Missing ranking history or missing co-factors on a selected date raise an error rather than substituting a less severe month. The fitting history is owned by the caller and does not determine this scenario window.

Variables:
  • factor (str) – Factor whose declared change determines selection, not portfolio P&L.

  • start_date (str) – Inclusive first scenario month; no prior opening return is used.

  • count (int) – Requested number of months, ordered by factor loss.

  • end_date (str | None) – Optional upper date, capped by the portfolio risk date.

  • ascending (bool) – Select smallest changes first; False selects largest increases.

  • return_type (qis.perfstats.config.ReturnTypes) – Declared LOG or DIFFERENCE units used for audit labels.

Parameters:
__init__(factor='Equity', start_date='2006-01-01', count=10, end_date=None, ascending=True, return_type=ReturnTypes.LOG)
Parameters:
Return type:

None

Methods

__init__([factor, start_date, count, ...])

metadata(window)

Describe the actual selection window for reports and provenance.

select(history, cutoff)

Return complete factor vectors in loss order, with chronological ties.

window(history, cutoff)

Return completed monthly vectors on the requested calendar window.

Attributes

factor: str = 'Equity'
start_date: str = '2006-01-01'
count: int = 10
end_date: str | None = None
ascending: bool = True
return_type: ReturnTypes = 'Log'
window(history, cutoff)[source]

Return completed monthly vectors on the requested calendar window.

Parameters:
  • history (DataFrame) – Unique month-end log-return panel for the complete model.

  • cutoff – Latest allowed model date.

Returns:

Calendar-reindexed vectors with complete ranking-factor observations.

Return type:

DataFrame

select(history, cutoff)[source]

Return complete factor vectors in loss order, with chronological ties.

Parameters:
  • history (DataFrame) – Month-end factor log returns including the requested window.

  • cutoff – Latest allowed model date.

Returns:

Selected vectors ordered by the ranking factor’s ascending return.

Return type:

DataFrame

metadata(window)[source]

Describe the actual selection window for reports and provenance.

Parameters:

window (DataFrame) – Validated calendar window returned by window().

Returns:

Portable ranking policy, dates and observation count.

Return type:

dict