Skip to content
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

搜索到的最佳因子池在哪个结果文件,如何读入python? #12

Open
jingmouren opened this issue Jul 27, 2023 · 6 comments

Comments

@jingmouren
Copy link

jingmouren commented Jul 27, 2023

你好,
是否最后一个checkout的json里是最佳因子池
如何将json里的字符串因子读入python成可执行的expr,以验证因子计算,对比论文中的结果,
及进一步利用这些因子?

@Nick-houyi
Copy link

+1,期待回复

@xuehongyanL
Copy link
Contributor

直接eval就可以了。这个方法会得到因子的Expression和对应的权重:

from alphagen.data.expression import *
from alphagen_generic.features import *

def load_alpha_pool(raw) -> Tuple[List[Expression], List[float]]:
    exprs_raw = raw['exprs']
    exprs = [eval(expr_raw.replace('$open', 'open_').replace('$', '')) for expr_raw in exprs_raw]
    weights = raw['weights']
    return exprs, weights

因子的线性组合暂时可以参考QLibStockDataCalculator类的实现。

@xuehongyanL
Copy link
Contributor

See THIS METHOD.

@jingmouren
Copy link
Author

jingmouren commented Jul 28, 2023

exprs加载成功了。得到的计算结果是个2301 * 644的向量,怎么对应这个向量的每个元素对应的哪天哪支股票
data是2431天,max_back*_data是100,和这的2301对不上
csi300每天应该是300个左右,和这的644也对不上啊

直接eval就可以了。这个方法会得到因子的Expression和对应的权重:

from alphagen.data.expression import *
from alphagen_generic.features import *

def load_alpha_pool(raw) -> Tuple[List[Expression], List[float]]:
    exprs_raw = raw['exprs']
    exprs = [eval(expr_raw.replace('$open', 'open_').replace('$', '')) for expr_raw in exprs_raw]
    weights = raw['weights']
    return exprs, weights

因子的线性组合暂时可以参考QLibStockDataCalculator类的实现。

@xuehongyanL
Copy link
Contributor

数据中的股票是所有时间的csi300的并集。

可以使用StockData::make_dataframe(data)将向量转换为更可读的pandas dataframe,其中包含日期和股票代码

@jingmouren
Copy link
Author

那每天的归一化是对并集的644支股票作的吗,好像有bug?

数据中的股票是所有时间的csi300的并集。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants