Skip to content
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: 2 additions & 0 deletions qlib/backtest/profit_attribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def get_stock_group(stock_group_field_df, bench_stock_weight_df, group_method, g
group_n=group_n,
)
return new_stock_group_df
else:
raise ValueError(f"Unknown group_method: {group_method}. Expected 'category' or 'bins'.")


def brinson_pa(
Expand Down
1 change: 1 addition & 0 deletions qlib/backtest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def get(self, infra_name: str) -> Any:
return getattr(self, infra_name)
else:
warnings.warn(f"infra {infra_name} is not found!")
return None

def has(self, infra_name: str) -> bool:
return infra_name in self.get_support_infra() and hasattr(self, infra_name)
Expand Down
1 change: 1 addition & 0 deletions qlib/contrib/data/utils/sepdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def apply_each(self, method: str, skip_align=True, *args, **kwargs):
inplace = True
if not inplace:
return SepDataFrame(df_dict=df_dict, join=self.join, skip_align=skip_align)
return None

def sort_index(self, *args, **kwargs):
return self.apply_each("sort_index", True, *args, **kwargs)
Expand Down
2 changes: 2 additions & 0 deletions qlib/contrib/model/pytorch_adarnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ def forward(self, source, target):
YX = torch.mean(kernels[batch_size:, :batch_size])
loss = torch.mean(XX + YY - XY - YX)
return loss
else:
raise ValueError(f"Unknown kernel_type: {self.kernel_type}. Expected 'linear' or 'rbf'.")


class Mine_estimator(nn.Module):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,6 @@ def model_performance_graph(

if show_notebook:
BarGraph.show_graph_in_notebook(figure_list)
return None
else:
return figure_list
1 change: 1 addition & 0 deletions qlib/contrib/report/analysis_position/cumulative_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,6 @@ def cumulative_return_graph(
_figures = _get_figure_with_position(position, report_normal, label_data, start_date, end_date)
if show_notebook:
BaseGraph.show_graph_in_notebook(_figures)
return None
else:
return _figures
1 change: 1 addition & 0 deletions qlib/contrib/report/analysis_position/rank_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,6 @@ def rank_label_graph(
_figures = _get_figure_with_position(position, label_data, start_date, end_date)
if show_notebook:
ScatterGraph.show_graph_in_notebook(_figures)
return None
else:
return _figures
1 change: 1 addition & 0 deletions qlib/contrib/report/analysis_position/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,6 @@ def report_graph(report_df: pd.DataFrame, show_notebook: bool = True) -> [list,
fig_list = _report_figure(report_df)
if show_notebook:
BaseGraph.show_graph_in_notebook(fig_list)
return None
else:
return fig_list
3 changes: 2 additions & 1 deletion qlib/contrib/report/analysis_position/risk_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _get_monthly_risk_analysis_figure(report_normal_df: pd.DataFrame) -> Iterabl
# if report_normal_df is None and report_long_short_df is None:
# return []
if report_normal_df is None:
return []
return

# if report_normal_df is None:
# report_normal_df = pd.DataFrame(index=report_long_short_df.index)
Expand Down Expand Up @@ -293,5 +293,6 @@ def risk_analysis_graph(
)
if show_notebook:
ScatterGraph.show_graph_in_notebook(_figure_list)
return None
else:
return _figure_list
1 change: 1 addition & 0 deletions qlib/contrib/report/analysis_position/score_ic.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ def score_ic_graph(pred_label: pd.DataFrame, show_notebook: bool = True, **kwarg
).figure
if show_notebook:
ScatterGraph.show_graph_in_notebook([_figure])
return None
else:
return (_figure,)
2 changes: 2 additions & 0 deletions qlib/contrib/strategy/optimizer/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def _optimize(self, S: np.ndarray, r: Optional[np.ndarray] = None, w0: Optional[
warnings.warn("`r` is set but will not be used for `rp` portfolio")
return self._optimize_rp(S, w0)

raise ValueError(f"Unknown optimization method: {self.method}")

def _optimize_inv(self, S: np.ndarray) -> np.ndarray:
"""Inverse volatility"""
vola = np.diag(S) ** 0.5
Expand Down
1 change: 1 addition & 0 deletions qlib/data/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ def _dataset(
)
data.to_pickle(cache_file)
return self.cache_to_origin_data(data, fields)
return None


class DatasetURICache(DatasetCache):
Expand Down
2 changes: 2 additions & 0 deletions qlib/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,8 @@ def _uri(self, type, **kwargs):
return Inst._uri(**kwargs)
elif type == "feature":
return DatasetD._uri(**kwargs)
else:
raise ValueError(f"Unknown type: {type}. Expected 'calendar', 'instrument', or 'feature'.")

def features_uri(self, instruments, fields, start_time, end_time, freq, disk_cache=1):
"""features_uri
Expand Down
1 change: 1 addition & 0 deletions qlib/utils/index_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ def isna(self):
def fillna(self, value=0.0, inplace: bool = False):
if inplace:
self.data = np.nan_to_num(self.data, nan=value)
return None
else:
return self.__class__(np.nan_to_num(self.data, nan=value), *self.indices)

Expand Down
2 changes: 1 addition & 1 deletion qlib/workflow/exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def _get_recorder(self, recorder_id=None, recorder_name=None):
raise ValueError(
"No valid recorder has been found, please make sure the input recorder id is correct."
) from mlflow_exp
elif recorder_name is not None:
else: # recorder_name is not None (guaranteed by assert above)
logger.warning(
f"Please make sure the recorder name {recorder_name} is unique, we will only return the latest recorder if there exist several matched the given name."
)
Expand Down
2 changes: 1 addition & 1 deletion qlib/workflow/expm.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def _get_exp(self, experiment_id=None, experiment_name=None):
raise ValueError(
"No valid experiment has been found, please make sure the input experiment id is correct."
) from e
elif experiment_name is not None:
else: # experiment_name is not None (guaranteed by assert above)
try:
exp = self.client.get_experiment_by_name(experiment_name)
if exp is None or exp.lifecycle_stage.upper() == "DELETED":
Expand Down
3 changes: 2 additions & 1 deletion qlib/workflow/online/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def update(self, dataset: DatasetH = None, write: bool = True, ret_new: bool = F
self.logger.info(
f"The data in {self.record.info['id']} are latest ({self.last_end}). No need to update to {self.to_date}."
)
return
return None

# load dataset
if dataset is None:
Expand All @@ -246,6 +246,7 @@ def update(self, dataset: DatasetH = None, write: bool = True, ret_new: bool = F
self.record.save_objects(**{self.fname: updated_data})
if ret_new:
return updated_data
return None

@abstractmethod
def get_update_data(self, dataset: Dataset) -> pd.DataFrame:
Expand Down
6 changes: 3 additions & 3 deletions qlib/workflow/record_temp.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ def generate(self, *args, **kwargs):
pass # continue to generating metrics
else:
logger.info("The results has previously generated, Generation skipped.")
return
return None

try:
self.check()
except FileNotFoundError:
logger.warning("The dependent data does not exists. Generation skipped.")
return
return None
artifact_dict = self._generate(*args, **kwargs)
if isinstance(artifact_dict, dict):
self.save(**artifact_dict)
Expand Down Expand Up @@ -320,7 +320,7 @@ def _generate(self, label: Optional[pd.DataFrame] = None, **kwargs):
label = self.load("label.pkl")
if label is None or not isinstance(label, pd.DataFrame) or label.empty:
logger.warning(f"Empty label.")
return
return None
ic, ric = calc_ic(pred.iloc[:, 0], label.iloc[:, self.label_col])
metrics = {
"IC": ic.mean(),
Expand Down