qlib icon indicating copy to clipboard operation
qlib copied to clipboard

ValueError: instruments not exists for market <ticker> using my converted csv data into Qlib format

Open AnonymousJY opened this issue 5 years ago • 10 comments

❓ Questions and Help

Hi,

I've converted my data for a particular US stock into Qlib format using command from doc python scripts/dump_bin.py dump_all --csv_path ~/.qlib/csv_data/my_data --qlib_dir ~/.qlib/qlib_data/my_data --include_fields open,close,high,low,volume,factor. Should a .txt file be created in ~/.qlib/qlib_data/my_data/instruments? I only see all.txt but the context inside the all.txt changes each time I add another ticker.

I think this is causing an issue for me to run the "train mode" example you provided with my data because I get a ValueError: instruments not exists for market AAPL for example.

Thanks.

AnonymousJY avatar Dec 13 '20 21:12 AnonymousJY

@AnonymousJY Hi, What is the format of the csv file and the "train model" config?

zhupr avatar Dec 14 '20 02:12 zhupr

@AnonymousJY Hi, What is the format of the csv file and the "train model" config?

@zhupr Thanks for asking. The format of the csv file is the following. Screen Shot 2020-12-13 at 22 52 35 The frequency is daily.

The file name is AAPL.csv. After converting the csv file with columns [open, close, high, low, volume], the bin files are saved in ~/.qlib/qlib_data/my_data/features/aapl (e.g., close.day.bin).

The "train model" is the same as one in here. Basically, I tried to change the dataset but run the same workflow example you guys provided.

--Edit-- I think I know what I was doing incorrectly. When I convert a single stock csv file into Qlib format, only all.txt instrument is created. So for the "train model" parameter market and benchmark, I input all. Is this correct? Thanks.

AnonymousJY avatar Dec 14 '20 04:12 AnonymousJY

@AnonymousJY Hi,

The market in config should be the stock list, which is the file in the instruments directory. For example, D.features(["AAPL"], ["$close"]) is correct, D.features(D.instruments("AAPL"), ["$close"]) is wrong. You can set the market in here to all to:market = "all" benchmarket = "AAPL", all is the data set used by train, benchmark is the benchmark for comparison of backtest results (single stock)

zhupr avatar Dec 14 '20 05:12 zhupr

@AnonymousJY Hi,

The market in config should be the stock list, which is the file in the instruments directory. For example, D.features(["AAPL"], ["$close"]) is correct, D.features(D.instruments("AAPL"), ["$close"]) is wrong. You can set the market in here to all to:market = "all" benchmarket = "AAPL", all is the data set used by train, benchmark is the benchmark for comparison of backtest results (single stock)

@zhupr Thanks. After training my data, the output is the following, which I think is not working correctly. Screen Shot 2020-12-14 at 22 44 31

The training code is the exact from this notebook. market=all and benchmarket=AAPL.

The all.txt file only has AAPL.

However, when I run with your given data in cn_data I can get similar results as yours.

Is this something you can point me to the right direction? Thanks.

AnonymousJY avatar Dec 15 '20 04:12 AnonymousJY

@AnonymousJY I think you can set some break points (like import pdb; pdb.set_trace()) before fitting models and check the data.

you-n-g avatar Dec 15 '20 12:12 you-n-g

@AnonymousJY I think you can set some break points (like import pdb; pdb.set_trace()) before fitting models and check the data.

@you-n-g Thanks for the guidance. I think the problem is in the column label. After preparing data using .prepare, it returns label with same float numbers (see below screenshot). Screen Shot 2021-01-04 at 00 00 43

However, I'm not sure why this is the case, because I don't see any issue with the features (see below). Screen Shot 2021-01-04 at 00 03 07

Do you or anyone else might know why the same float numbers are generated? Thanks.

AnonymousJY avatar Jan 04 '21 05:01 AnonymousJY

@AnonymousJY The dataset will use ZScoreNorm processor for label.

https://github.com/microsoft/qlib/blob/main/qlib/data/dataset/processor.py#L196 https://github.com/microsoft/qlib/blob/main/qlib/contrib/data/handler.py#L37

If you only contains 2 stocks. You will get values like you image after cross-sectional zscore normalization.

you-n-g avatar Jan 04 '21 09:01 you-n-g

@AnonymousJY The dataset will use ZScoreNorm processor for label.

https://github.com/microsoft/qlib/blob/main/qlib/data/dataset/processor.py#L196 https://github.com/microsoft/qlib/blob/main/qlib/contrib/data/handler.py#L37

If you only contains 2 stocks. You will get values like you image after cross-sectional zscore normalization.

@you-n-g Thanks for the reply.

So for your working sample in "workflow_by_code.ipynb", the user would need to feed in multiple stock data like the example for the Chinese stocks in cn_data in order for that example model to train. Am I correct?

I was looking for single stock strategy. Thanks.

AnonymousJY avatar Jan 05 '21 04:01 AnonymousJY

@AnonymousJY
Currently, the released strategy examples are for multi-instrument selection (it is the hotest problem in practical Quant research). The trading for single asset get relative low priority. The setting of single asset is similar to high-frequency trading https://github.com/microsoft/qlib/projects/2 We will consider releasing examples for single stock strategy in the future after we release high-frequency trading module.

you-n-g avatar Jan 05 '21 09:01 you-n-g

@AnonymousJY Currently, the released strategy examples are for multi-instrument selection (it is the hotest problem in practical Quant research). The trading for single asset get relative low priority. The setting of single asset is similar to high-frequency trading https://github.com/microsoft/qlib/projects/2 We will consider releasing examples for single stock strategy in the future after we release high-frequency trading module.

@you-n-g Thanks for the reply. I look forward to that release. Closing this ticket.

AnonymousJY avatar Jan 06 '21 03:01 AnonymousJY