1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-13 07:46:53 +08:00

recorder refine; signalTemp; fixbug

This commit is contained in:
Young
2020-11-21 15:20:47 +00:00
parent a0fe6941d2
commit e5923333f5
6 changed files with 133 additions and 79 deletions

View File

32
qlib/contrib/eva/alpha.py Normal file
View File

@@ -0,0 +1,32 @@
'''
Here is a batch of evaluation functions.
The interface should be redesigned carefully in the future.
'''
import pandas as pd
def calc_ic(pred: pd.Series, label: pd.Series, date_col='datetime', dropna=False) -> (pd.Series, pd.Series):
"""calc_ic.
Parameters
----------
pred :
pred
label :
label
date_col :
date_col
Returns
-------
(pd.Series, pd.Series)
ic and rank ic
"""
df = pd.DataFrame({'pred': pred, 'label': label})
ic = df.groupby(date_col).apply(lambda df: df['pred'].corr(df['label']))
ric = df.groupby(date_col).apply(lambda df: df['pred'].corr(df['label'], method='spearman'))
if dropna:
return ic.dropna(), ric.dropna()
else:
return ic, ric

View File

@@ -64,7 +64,7 @@ class LGBModel(ModelFT):
def predict(self, dataset):
if self.model is None:
raise ValueError("model is not fitted yet!")
x_test = dataset.prepare("test", col_set="feature")
x_test = dataset.prepare("test", col_set="feature", data_key=DataHandlerLP.DK_I)
return pd.Series(self.model.predict(np.squeeze(x_test.values)), index=x_test.index)
def finetune(self, dataset: DatasetH, num_boost_round=10, verbose_eval=20):