Return-attribution sample weights

q.label.sample_weights attributes each log return equally among labels active at that observation, accumulates the attributed return over each event lifetime, and takes its absolute value.

Normalization is enabled by default and scales nonzero weights to unit mean.

import pandas as pd

import qrt as q

observations = pd.date_range("2026-01-01", periods=7, name="datetime")
prices = pd.Series([100, 102, 103, 101, 105, 108, 107], index=observations)
end_times = pd.Series(
    observations[[3, 5, 6]],
    index=observations[[0, 1, 4]].rename("event_time"),
)
raw = q.label.sample_weights(prices, end_times, normalize=False)
normalized = q.label.sample_weights(prices, end_times)
pd.DataFrame({"end_time": end_times, "raw_weight": raw, "normalized_weight": normalized})
end_time raw_weight normalized_weight
event_time
2026-01-01 2026-01-04 0.004975 0.220600
2026-01-02 2026-01-06 0.038481 1.706235
2026-01-05 2026-01-07 0.024203 1.073165

These are outcome-based weights and therefore are not point-in-time features. Combine them with uniqueness, time decay, or class balance only through an explicit training policy.

Back to top