Code Monkey home page Code Monkey logo

hist's People

Contributors

dependabot[bot] avatar jxkd123 avatar wentao-xu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hist's Issues

Model artitecture problem

Dear authors,

I have some questions about the differences between codes and formula in the part of predefined concept module. It seems that in the paper, we use market capital as the initial weight of the predefined concepts. I can understand these steps in code:

        market_value_matrix = market_value.reshape(market_value.shape[0], 1).repeat(1, concept_matrix.shape[1])
        stock_to_concept = concept_matrix * market_value_matrix
        
        stock_to_concept_sum = torch.sum(stock_to_concept, 0).reshape(1, -1).repeat(stock_to_concept.shape[0], 1)
        stock_to_concept_sum = stock_to_concept_sum.mul(concept_matrix)

        stock_to_concept_sum = stock_to_concept_sum + (torch.ones(stock_to_concept.shape[0], stock_to_concept.shape[1]).to(device))
        stock_to_concept = stock_to_concept / stock_to_concept_sum
        hidden = torch.t(stock_to_concept).mm(x_hidden)
        
        hidden = hidden[hidden.sum(1)!=0]

But i cant understand the following steps, which i cant find in the paper formula,

        stock_to_concept = x_hidden.mm(torch.t(hidden))
        # stock_to_concept = cal_cos_similarity(x_hidden, hidden)
        stock_to_concept = self.softmax_s2t(stock_to_concept)
        hidden = torch.t(stock_to_concept).mm(x_hidden)

Does It aim to modify the weight of stock to concept? but i dont find the answer in the paper, can you give me some hints about this?
I'll appreciate your responses.

run ERROR need help

Detail:
[1972:MainThread](2024-05-11 12:05:43,533) ERROR - qlib.workflow - [utils.py:41] - An exception has been raised[AttributeError: Please run qlib.init() first using qlib].
File "learn_zhushi.py", line 490, in
main(args) # 调用主函数进行训练与评估
File "learn_zhushi.py", line 272, in main
train_loader, valid_loader, test_loader = create_loaders(args) # 创建数据加载器
File "learn_zhushi.py", line 196, in create_loaders
dataset = DatasetH(hanlder, segments) # 创建数据集
File "/root/miniconda3/envs/AIQI/lib/python3.7/site-packages/qlib/qlib/data/dataset/init.py", line 119, in init
self.handler: DataHandler = init_instance_by_config(handler, accept_types=DataHandler)
File "/root/miniconda3/envs/AIQI/lib/python3.7/site-packages/qlib/qlib/utils/mod.py", line 174, in init_instance_by_config
return klass(**cls_kwargs, **try_kwargs, **kwargs)
File "/root/miniconda3/envs/AIQI/lib/python3.7/site-packages/qlib/contrib/data/handler.py", line 85, in init
**kwargs
File "/root/miniconda3/envs/AIQI/lib/python3.7/site-packages/qlib/data/dataset/handler.py", line 468, in init
super().init(instruments, start_time, end_time, data_loader, **kwargs)
File "/root/miniconda3/envs/AIQI/lib/python3.7/site-packages/qlib/data/dataset/handler.py", line 100, in init
self.setup_data()
File "/root/miniconda3/envs/AIQI/lib/python3.7/site-packages/qlib/data/dataset/handler.py", line 610, in setup_data
super().setup_data(**kwargs)
File "/root/miniconda3/envs/AIQI/lib/python3.7/site-packages/qlib/data/dataset/handler.py", line 144, in setup_data
self._data = lazy_sort_index(self.data_loader.load(self.instruments, self.start_time, self.end_time))
File "/root/miniconda3/envs/AIQI/lib/python3.7/site-packages/qlib/data/dataset/loader.py", line 137, in load
for grp, (exprs, names) in self.fields.items()
File "/root/miniconda3/envs/AIQI/lib/python3.7/site-packages/qlib/data/dataset/loader.py", line 137, in
for grp, (exprs, names) in self.fields.items()
File "/root/miniconda3/envs/AIQI/lib/python3.7/site-packages/qlib/data/dataset/loader.py", line 209, in load_group_df
instruments = D.instruments(instruments, filter_pipe=self.filter_pipe)
File "/root/miniconda3/envs/AIQI/lib/python3.7/site-packages/qlib/utils/init.py", line 812, in getattr
raise AttributeError("Please run qlib.init() first using qlib")
AttributeError: Please run qlib.init() first using qlib

Could you tell me how to solve this problem?Thx.

about alpha360 in your paper , Need help!

Dear athor,the data source from cndata(csi300) as you refered in paer.
x is (290,360),290 is the number of node,360 is the alpha 360.
I transform alpha360 (290,360) into (290,6,60) like this:
src_seq = x.reshape(len(x), 6, -1) # [N, F, T]
src_seq = src_seq.permute(0, 2, 1) # [N, T, F]
why the day close0 column are zero?Not the closing price of the last 60 days? Why is it 0 the day(close0 ).
image

About calculate the cos similarity

i_shared_info, hidden in model.py line 116, are you calculate the same tensor? it seems hidden is equal to i_shared_info, even if i debug and step in cal_cos_similarity, the two paramters of cal_cos_similarity function is the same

Hidden Concept Module

    i_shared_info = x_hidden - e_shared_back
    hidden = i_shared_info
    i_stock_to_concept = cal_cos_similarity(i_shared_info, hidden)

random shuffle v.s. daily shuffle

Dear authors,

It is a nice job. I noticed that by default, all the methods employ the batch_size = -1, which corresponds to the daily shuffling. I understand daily shuffling is used because HIST hinges on the date-specific graph. But I still wonder if it makes a difference to use random shuffling --- random shuffling can break the intra-correlation within a day, and (might) improve the performance.

A feasible but less efficient way for random shuffling is to sample a few dates and make the associated graphs, the associated concept embeddings, and the corrected, hidden, individual stock representations, then sample part of the representations for training. Have you ever explored such an idea or related directions? I'm very curious about whether random shuffling can help.

In addition, other methods might not be restricted to the daily shuffling. Have you tried random shuffling on them and seen different results from the daily shuffling?

I'll appreciate your responses.

Does Predefined Concept Data provided in 'csi300_stock2concept.npy' contain future information?

Dear authors,

The paper mentioned that the change of stocks’ industry and businesses causes the number of predefined concepts change dynamically. However, it seems like that the same predefined concept data was used in training and testing process. if stock2concept_matrix is created using data from 01/01/2007 to 12/31/2020, with training set (from 01/01/2007 to 12/31/2014), validation set (from 01/01/2015 to 12/31/2016), and test set (from 01/01/2017 to 12/31/2020), there is a problem that the training process is influenced by future information from stock2concept_matrix.
I would appreciate that you could provide the extraction process of the stock-to-predefined concept data.

RuntimeError: Device index must not be negative

Dear author @Wentao-Xu ,

I can reproduce the Baselines without error, however RuntimeError appeared when I ran the HIST model. I have set all the package to the according version as mentioned in the requirements.txt. But error keeps appearing when it starts training.

我可以复现Baselines的模型,但是在跑HIST的时候会出现RuntimeError报错。我已经把要求的库都降级到相应的版本,但是仍然出现如下报错。

[2022-02-17 11:43:15] - Running 0 Epoch: 0
[2022-02-17 11:43:15] - training...
0%|
[2364:MainThread](2022-02-17 11:43:15,750) ERROR - qlib.workflow - [utils.py:38] - An exception has been raised[RuntimeError: Device index must not be negative].
File "learn.py", line 450, in
main(args)
File "learn.py", line 288, in main
train_epoch(epoch, model, optimizer, train_loader, writer, args, stock2concept_matrix)
File "learn.py", line 116, in train_epoch
pred = model(feature, stock2concept_matrix[stock_index], market_value)
File "D:\anaconda3\envs\qlib\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "D:\Codes\HIST\model.py", line 79, in forward
device = torch.device(torch.get_device(x+1))
RuntimeError: Device index must not be negative

I wonder why it is the case and how can I fix it? Thank you for your time!

请问应该怎么解决这一问题呢?谢谢!

Questions on backtesting

Hi! I'm really interested in your work, and tried to reproduce the results myself. Using the given code I can reproduce the reported IC/Rank IC scores, but I'm failing to reproduce the backtest results reported in your paper. All the methods (the baselines and HIST itself) seem to perform worse than the benchmark (CSI 300 Index) and none of them could get a positive information ratio against the benchmark. Do you mind sharing the backtesting code as well?

I would really appreciate it if you could reply soon!

What does Precision@N mean?

Dear author:

Thanks for your work! I read your paper but I have some questions about the evaluation metrics. I am confused about Precision@N. According to Appendix A.2., “The Precision@N is the proportion of top N predictions on each day with the positive label.” I don't understand what that means, maybe sometimes almost all stocks have negative labels, in addition I find the recall metrics are not satisfactory.

Looking forward to your reply!

AttributeError: 'float' object has no attribute 'mean'

Hi. I have encountered an error when running the code. I wonder whether anyone else also have this kind of problems. Thanks.

[16114:MainThread](2022-08-04 11:56:34,338) ERROR - qlib.workflow - [utils.py:41] - An exception has been raised[AttributeError: 'float' object has no attribute 'mean'].
File "learn.py", line 458, in
main(args)
File "learn.py", line 349, in main
name, ic.mean(), rank_ic.mean()))
AttributeError: 'float' object has no attribute 'mean'

为什么不计算余弦相似度而是用 stock_to_concept = x_hidden.mm(torch.t(hidden))?

Predefined Concept Module

    market_value_matrix = market_value.reshape(market_value.shape[0], 1).repeat(1, concept_matrix.shape[1])
    stock_to_concept = concept_matrix * market_value_matrix
    
    stock_to_concept_sum = torch.sum(stock_to_concept, 0).reshape(1, -1).repeat(stock_to_concept.shape[0], 1)
    stock_to_concept_sum = stock_to_concept_sum.mul(concept_matrix)

    stock_to_concept_sum = stock_to_concept_sum + (torch.ones(stock_to_concept.shape[0], stock_to_concept.shape[1]).to(device))
    stock_to_concept = stock_to_concept / stock_to_concept_sum
    hidden = torch.t(stock_to_concept).mm(x_hidden)
    
    hidden = hidden[hidden.sum(1)!=0]

#################以下为疑问点####################
stock_to_concept = x_hidden.mm(torch.t(hidden))
# stock_to_concept = cal_cos_similarity(x_hidden, hidden)
stock_to_concept = self.softmax_s2t(stock_to_concept)
hidden = torch.t(stock_to_concept).mm(x_hidden)
为什么不用stock_to_concept = cal_cos_similarity(x_hidden, hidden),而是用stock_to_concept = x_hidden.mm(torch.t(hidden)),按照论文来说不是应该计算余弦相似度吗?希望得到您的解答!

What is the meaning of market_value?

❓ Questions and Help

Dear authors,
In the training code of HIST, I noticed the input of DataLoader includes df_train['market_value']. I didn't find this in the training of other models. Could you please tell me what it stands for? Is it the price of the stock?
`

slc = slice(pd.Timestamp(args.train_start_date), pd.Timestamp(args.train_end_date))
df_train['market_value'] = df_market_value[slc]
df_train['market_value'] = df_train['market_value'].fillna(df_train['market_value'].mean())
df_train['stock_index'] = 733
df_train['stock_index'] = df_train.index.get_level_values('instrument').map(stock_index).fillna(733).astype(int)
train_loader = DataLoader(df_train["feature"], df_train["label"], df_train['market_value'], df_train['stock_index'], batch_size=args.batch_size, pin_memory=args.pin_memory, start_index=start_index, device = device)

`

Thank you for your kind reply!

Whether the training loss converges normally?

Hello, I have attempted to reproduce the Hist model using my dataset, but I am encountering oscillating and non-converging training loss. I was wondering if the training loss in your experiment converges normally.

How to change dataset from CSI300 to CSI00

Dear authors,

I am really interested about your paper, but there are some problems when I tried to make some change to the dataset.

The publiced data file only contains data from CSI300, but now I want to change dataset from CSI300 to CSI100. How can I get data like "csi300_market_value_07to20", "csi300_market_value_07to20", etc.

Thank you for your help

All NAN value

hi ,when I try to train your model , I find that after the x_hidden ware put into the GRU, it changed into all NAN values. what can I do to fix it?
1

Question About Predefined Concept Module

Hi, thanks for sharing this great work! I'm a little bit confusing about line 97 to line 101, why calculate hidden twice? What's the purpose of this part? Thanks!

95  hidden = torch.t(stock_to_concept).mm(x_hidden)

97  hidden = hidden[hidden.sum(1)!=0]
98  stock_to_concept = x_hidden.mm(torch.t(hidden))
99  # stock_to_concept = cal_cos_similarity(x_hidden, hidden)
100 stock_to_concept = self.softmax_s2t(stock_to_concept)
101 hidden = torch.t(stock_to_concept).mm(x_hidden)

103 concept_to_stock = cal_cos_similarity(x_hidden, hidden) 

some questions,need help

Dear authors,

I am really interested about your paper, your idea is cool。but there are some question when I reading your paper .

1、Are the 735 stocks in the data set due to the annual adjustment of CSI300 stocks?

2、in the paper "For each stock on date 𝑡, Alpha360 looks back 60 days to construct a 360-dimensional historical stock data as a stock feature of this stock at date 𝑡. We use the features of stocks in CSI 100 and CSI 300 both from" . So the feature input in GRU-encorder is 360-dimensional historical stock data which looks back 60 days ?

3、I'm Interested in your stock2concept process, can you briefly describe how it was obtained?

I would appreciate it if you could reply as soon as possible.
Thank you for your help,Best wish~

Stuck when creating loader

When I was running "python learn.py --model_name MLP --data_set csi100 --hidden_size 512 --num_layers 3 --outdir ./output/csi100_MLP", it took several hours for "create loaders" but still remained unfinished. I found it stuck when executing "init_instance_by_config". Is there any solution for this? Thanks!

Accepted for Publication?

Dear Author,

Interesting work! I wonder if this paper is already accepted by a top conference or not. Could you please reveal some information about the publication? Thanks a lot.

Best regards,
Shaun

no scripts folder

python scripts/get_data.py qlib_data --target_dir ~/.qlib/qlib_data/cn_data --region cn --version v2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.