weighted_sum(*frames, weights, name=None, metadata=None)

Apply weighted_sum to long-form panel inputs.

Parameters

frames : Panel | Graph
One or more numeric Panel or single-output Graph inputs. weights : Sequence[float]
One numeric weight for each input frame. name : str | None, default None
Optional graph-node name. A generated name is used when omitted. metadata : Mapping[str, Any] | None, default None
Optional metadata stored on the graph node.

Returns

Graph
Lazy single-output graph. Call .compute() to materialize a Panel.

Examples

import polars as pl

from bagelquant_core import Domain, Panel
from bagelquant_core.composer import weighted_sum

domain = Domain(calendar=["2024-01-02", "2024-01-03", "2024-01-04"], universe=["a", "b"])
left = Panel.from_domain(
    pl.DataFrame({
        "time": ["2024-01-02", "2024-01-03", "2024-01-04"] * 2,
        "asset_id": ["a"] * 3 + ["b"] * 3,
        "value": [1.0, 2.0, 4.0, 2.0, 3.0, 8.0],
    }),
    domain,
)
right = Panel.from_domain(
    pl.DataFrame({
        "time": ["2024-01-02", "2024-01-03", "2024-01-04"] * 2,
        "asset_id": ["a"] * 3 + ["b"] * 3,
        "value": [1.0, 1.0, 2.0, 1.0, 2.0, 4.0],
    }),
    domain,
)

result = weighted_sum(left, right, weights=[0.25, 0.75]).compute().data
print(result)

Notes

Inputs are aligned by (time, asset_id) before the operation runs.