27 lines
749 B
Python
27 lines
749 B
Python
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
import pandas as pd
|
|
|
|
from qfr.factors import winsorize_by_date, zscore_by_date
|
|
from qfr.metrics import information_coefficient
|
|
|
|
|
|
def main() -> None:
|
|
dates = pd.to_datetime(["2026-01-01", "2026-01-02", "2026-01-03"])
|
|
assets = ["A", "B", "C", "D"]
|
|
idx = pd.MultiIndex.from_product([dates, assets], names=["date", "asset"])
|
|
|
|
rng = np.random.default_rng(42)
|
|
factor = pd.Series(rng.normal(size=len(idx)), index=idx)
|
|
fwd_ret = pd.Series(rng.normal(scale=0.01, size=len(idx)), index=idx)
|
|
|
|
factor2 = zscore_by_date(winsorize_by_date(factor))
|
|
ic = information_coefficient(factor2, fwd_ret)
|
|
|
|
print("IC mean:", float(ic.mean()))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|