MCPcopy
hub / github.com/microsoft/qlib / _agg_data

Method _agg_data

qlib/backtest/high_performance_ds.py:184–204  ·  view source on GitHub ↗

Agg data by specific method.

(data: IndexData, method: str)

Source from the content-addressed store, hash-verified

182
183 @staticmethod
184 def _agg_data(data: IndexData, method: str) -> Union[IndexData, np.ndarray, None]:
185 """Agg data by specific method."""
186 # FIXME: why not call the method of data directly?
187 if method == "sum":
188 return np.nansum(data)
189 elif method == "mean":
190 return np.nanmean(data)
191 elif method == "last":
192 # FIXME: I've never seen that this method was called.
193 # Please merge it with "ts_data_last"
194 return data[-1]
195 elif method == "all":
196 return data.all()
197 elif method == "ts_data_last":
198 valid_data = data.loc[~data.isna().data.astype(bool)]
199 if len(valid_data) == 0:
200 return None
201 else:
202 return valid_data.iloc[-1]
203 else:
204 raise ValueError(f"{method} is not supported")
205
206
207class BaseSingleMetric:

Callers 1

get_dataMethod · 0.95

Calls 2

isnaMethod · 0.80
allMethod · 0.45

Tested by

no test coverage detected