Skip to content

Commit

Permalink
Update ic.py
Browse files Browse the repository at this point in the history
  • Loading branch information
wukan1986 committed Feb 29, 2024
1 parent 73499e5 commit 095418a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions alphainspect/ic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import itertools
from typing import Sequence, Literal

import numpy as np
Expand Down Expand Up @@ -40,6 +41,13 @@ def calc_ic(df_pl: pl.DataFrame, factor: str, forward_returns: Sequence[str]) ->
).sort(_DATE_)


def calc_ic2(df_pl: pl.DataFrame, factors: Sequence[str], forward_returns: Sequence[str]) -> pl.DataFrame:
"""多因子多收益的IC矩阵。方便部分用户统计大量因子信息"""
return df_pl.group_by(_DATE_).agg(
[rank_ic(x, y).alias(f'{x}__{y}') for x, y in itertools.product(factors, forward_returns)]
).sort(_DATE_)


def mutual_info_func(xx):
yx = np.vstack(xx).T
# 跳过nan
Expand Down

0 comments on commit 095418a

Please sign in to comment.