Skip to content

Snapshot

AllocationSnapshot class holds information about a portfolio's currency, positions, and other optional data. It is used to store the state of a portfolio at a specific point in time.

Creating a snapshot

Let's create a simple snapshot with currency tickers.

from qcs import AllocationSnapshot

currency = "EUR"
positions = [
    {"ticker": "EUR", "size": 100.0},
    {"ticker": "GBP", "size": 200.0},
]

snapshot = AllocationSnapshot(currency=currency, positions=positions)

Alternatively we can specify the positions by using allocation in portfolio currency

positions = [
    {"ticker": "EUR", "allocation": 10000.0},
    {"ticker": "GBP", "allocation": 10000.0},
]

Benchmark

If we want to see relative indicators like tracking error, we need to specify a benchmark snapshot.

benchmark_snapshot = AllocationSnapshot(currency=currency, positions=positions)
snapshot = AllocationSnapshot(
    currency=currency, positions=positions, benchmark=benchmark_snapshot
)

Assets and histories

Depending on user's subscription, Quarisma can provide several risk factors, such as currencies, yield curves, credit spreads or indices, and assets.

We can extend the risk factors universe and also create custom assets: we then need to specify them and their histories, and use them in the context.

from qcs import Asset, History, Context

assets = [
    {
        "code": "<MSFT>",
        "label": "Microsoft",
        "type": "EQT",
        "currency": "USD",
        "alias1": "MSFT",
        "formula": "RTHST([CODE],[LABEL],[CURRENCY],[HISTORY],'116',[OTHER])",
        "country": "USA",
        "sector": "Technology",
        "history": "MSFT",
    },
]

histories = [
    {
        "code": "MSFT",
        "label": "Microsoft",
        "currency": "USD",
        "time_series": [
            # Usually 3 year of daily history is recommended
            {"date": "2021-10-01", "value": 289.10},
            {"date": "2021-10-08", "value": 294.85},
            {"date": "2021-10-15", "value": 304.21},
        ],
    }
]

context = Context(
    date="2023-10-19",
    horizon="1d",
    local_db={"assets": assets, "histories": histories},
)

We can also import assets and histories from csv

assets = qcs.import_assets_from_csv("examples/assets.csv", sep=",")
histories = qcs.import_histories_from_csv(
    "examples/histories.csv", sep=",", date_format="%Y-%m-%d"
)

Methods

List of methods that can be called on an AllocationSnapshot object.

Risk analysis

  • pivot_view: Returns a pivot view of the snapshot.

Top factors for Multivariate beta