Skip to content

fix microsoft/qlib#1893 #1898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qlib/backtest/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def fill_stock_value(self, start_time: Union[str, pd.Timestamp], freq: str, last
freq=freq,
disk_cache=True,
).dropna()
price_dict = price_df.groupby(["instrument"]).tail(1).reset_index(level=1, drop=True)["$close"].to_dict()
price_dict = price_df.groupby(["instrument"], group_keys=False).tail(1)["$close"].to_dict()

if len(price_dict) < len(stock_list):
lack_stock = set(stock_list) - set(price_dict)
Expand Down
6 changes: 3 additions & 3 deletions qlib/contrib/eva/alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ def calc_long_short_prec(
if dropna:
df.dropna(inplace=True)

group = df.groupby(level=date_col)
group = df.groupby(level=date_col, group_keys=False)

def N(x):
return int(len(x) * quantile)

# find the top/low quantile of prediction and treat them as long and short target
long = group.apply(lambda x: x.nlargest(N(x), columns="pred").label).reset_index(level=0, drop=True)
short = group.apply(lambda x: x.nsmallest(N(x), columns="pred").label).reset_index(level=0, drop=True)
long = group.apply(lambda x: x.nlargest(N(x), columns="pred").label)
short = group.apply(lambda x: x.nsmallest(N(x), columns="pred").label)

groupll = long.groupby(date_col)
l_dom = groupll.apply(lambda x: x > 0)
Expand Down
2 changes: 1 addition & 1 deletion qlib/contrib/report/analysis_position/parse_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _calculate_day_value(g_df: pd.DataFrame):
g_df["excess_return"] = g_df[_label_name] - g_df[_label_name].mean()
return g_df

return df.groupby(level="datetime").apply(_calculate_day_value)
return df.groupby(level="datetime", group_keys=False).apply(_calculate_day_value)


def get_position_data(
Expand Down
2 changes: 1 addition & 1 deletion qlib/contrib/report/analysis_position/rank_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _get_figure_with_position(
)

res_dict = dict()
_pos_gp = _position_df.groupby(level=1)
_pos_gp = _position_df.groupby(level=1, group_keys=False)
for _item in _pos_gp:
_date = _item[0]
_day_df = _item[1]
Expand Down
4 changes: 2 additions & 2 deletions qlib/utils/paral.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def datetime_groupby_apply(

def _naive_group_apply(df):
if isinstance(apply_func, str):
return getattr(df.groupby(axis=axis, level=level), apply_func)()
return df.groupby(axis=axis, level=level).apply(apply_func)
return getattr(df.groupby(axis=axis, level=level, group_keys=False), apply_func)()
return df.groupby(axis=axis, level=level, group_keys=False).apply(apply_func)

if n_jobs != 1:
dfs = ParallelExt(n_jobs=n_jobs)(
Expand Down
Loading