Skip to content

Context

qcs.Context

Bases: BaseModel

Context for risk service computation.

Parameters:

Name Type Description Default
date date

The reference date for the context. Can be given as a string in YYYY-MM-DD format or as a python datetime.date.

required
horizon Literal['1d', '1w', '2w', '4w', '1m']

The time horizon for the risk assessment.

required
local_db LocalDb

An instance of LocalDb containing assets and histories relevant to the context.

required

Examples:

>>> context = Context(
...     date="2023-10-19",
...     horizon="1d",
...     local_db=LocalDb(assets=[], histories=[])
... )

qcs.LocalDb

Bases: BaseModel

Local database for storing assets and histories.

Parameters:

Name Type Description Default
assets List[Asset]

A list of Asset instances representing financial assets with possible pricing formulas.

required
histories List[History]

A list of History instances representing historical data for assets.

required

Examples:

>>> local_db = LocalDb(
...     assets=[Asset(...), Asset(...)],
...     histories=[History(...), History(...)]
... )

qcs.Asset

Bases: BaseModel

Asset in asset table. In the parameters below are just the most used asset fields. For full list of 60+ fields see detailed documentation.

Parameters:

Name Type Description Default
code str

Unique identifier for the asset.

required
label str | None

Human-readable label for the asset.

None
type str | None

The type of the asset (e.g., "EQT", "BND").

None
currency str | None

The currency in which the asset is denominated.

None
alias1 str | None

An alias for the asset.

None
formula str | None

A formula for pricing the asset.

None

Examples:

>>> equity68 = Asset(
...     code="<EQUITYEUR68>",
...     label="Equity EUR n. 68",
...     type="EQT",
...     currency="EUR",
...     alias1="EQUITYEUR68",
...     formula="RTHST([CODE],[LABEL],[CURRENCY],[HISTORY],'116',[OTHER])",
...     country="USA",
...     sector="Materials",
...     history="EQUITYEUR68",
... )

qcs.History

Bases: BaseModel

Historical data for a financial instrument or factor.

Parameters:

Name Type Description Default
code str

Unique identifier for the historical time series.

required
currency Literal

The currency (3 letter code) in which the financial instrument is denominated.

required
time_series List[HistoryDataPoint]

A list of time series data representing the value of the financial instrument over time. Given as object with date : date The date of the time series entry. Python datetime.date object or YYYY-MM-DD string. value : float The value of the financial instrument on the given date.

required
label str | None

Human-readable label for the financial instrument.

None

Examples:

>>> history_msft = History(
...     code="MSFT",
...     currency="USD",
...     time_series=[
...         {"date": "2021-09-27", "value": 283.11},
...         {"date": "2021-09-28", "value": 284.00},
...         {"date": "2021-09-29", "value": 283.52},
...     ],
...     label="Microsoft Corporation",
... )

qcs.HistoryDataPoint

Bases: BaseModel

Single time series data point.

Parameters:

Name Type Description Default
date date

The date of the time series entry. Python datetime.date object or YYYY-MM-DD string.

required
value float

The value of the financial instrument on the given date.

required

Examples:

>>> data_point = HistoryDataPoint(date="2021-09-27", value=800.1)