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

ingest時出現ValueError: Failed to find any assets with country_code 'TW' that traded between 2023-05-05 00:00:00+00:00 and 2023-05-05 00:00:00+00:00. This probably means that your asset db is old or that it has incorrect country/exchange metadata. #6

Closed
tej87681088 opened this issue Sep 7, 2023 · 0 comments
Labels
Pipeline QA for run pipline question Further information is requested

Comments

@tej87681088
Copy link
Contributor

tej87681088 commented Sep 7, 2023

原因

在run_pipeline的start及end期間內bundle至少要一家公司存在。可能是公司未上市,或bundle中沒該段時間的資料。

例如:

  • bundle內只有一家公司2330,且start_date=20190102 end_date=20230731。利用!zipline bundle-info語法可得知下圖資訊:

image

  • 若我執行run_pipeline()run_algorithm()的end_date設定為'2023-08-30',則會拋出以下錯誤:

MicrosoftTeams-image (18)

  • 原因是在20230801~20230830沒有任一家公司存活。

解法

  • 調整run_pipeline()run_algorithm()的start_date或end_date
  • 重新ingest並設定正確的環境變數
    • os.environ['mdate']

    • os.environ['ticker']

  • 或是利用$ zipline update語法更新bundle。

檢查程式

  1. 檢查bundle資訊
 !zipline bundle-info
  1. 檢查單檔個股start_date, end_date
from zipline.data import bundles
bundle_name='tquant'
symbol='1101'
bundle = bundles.load(bundle_name)

asset_=bundle.asset_finder.lookup_symbol(symbol, as_of_date=None)
asset_.start_date,asset_.end_date
  1. 檢查所有個股lifetimes
# 參數
start = '2022-12-16'
end = '2023-08-30'
bundle_name='tquant'
#-----------------------------------------------------------------------

import os
import tejapi

# set tej_key and base
tej_key = <api key>
api_base = <api_base>

os.environ['TEJAPI_KEY'] = tej_key
os.environ['TEJAPI_BASE']= api_base

tejapi.ApiConfig.api_key = tej_key  
tejapi.ApiConfig.api_base = api_base

from zipline.data import bundles
from zipline.data.data_portal import DataPortal
from zipline.pipeline.domain import TW_EQUITIES
import pandas as pd


bundle = bundles.load(bundle_name)
sessions = TW_EQUITIES.all_sessions()
start_idx, end_idx = sessions.slice_locs(start, end)
extra_rows = 0
# Number of extra rows to compute before `start_date`.
# Extra rows are needed by terms like moving averages that require a
# trailing window of data.
            
lifetimes = bundle.asset_finder.lifetimes(
            dates = sessions[start_idx - extra_rows : end_idx],
            include_start_date=False,
            country_codes=('TW',),
        )
count_lifetimes = lifetimes.T.sum()
count_lifetimes_zero = count_lifetimes[count_lifetimes==0]

count_lifetimes_zero.index.min(), count_lifetimes_zero.index.max()
@tej87681088 tej87681088 added question Further information is requested Pipeline QA for run pipline labels Sep 7, 2023
@tej87681088 tej87681088 changed the title ValueError: Failed to find any assets with country_code 'TW' that traded between 2023-05-05 00:00:00+00:00 and 2023-05-05 00:00:00+00:00. This probably means that your asset db is old or that it has incorrect country/exchange metadata. (#76) · Issues · TQuant / Zipline_tquant · GitLab ValueError: Failed to find any assets with country_code 'TW' that traded between 2023-05-05 00:00:00+00:00 and 2023-05-05 00:00:00+00:00. This probably means that your asset db is old or that it has incorrect country/exchange metadata. Sep 7, 2023
@Ricky05250525 Ricky05250525 changed the title ValueError: Failed to find any assets with country_code 'TW' that traded between 2023-05-05 00:00:00+00:00 and 2023-05-05 00:00:00+00:00. This probably means that your asset db is old or that it has incorrect country/exchange metadata. ingest時出現ValueError: Failed to find any assets with country_code 'TW' that traded between 2023-05-05 00:00:00+00:00 and 2023-05-05 00:00:00+00:00. This probably means that your asset db is old or that it has incorrect country/exchange metadata. Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pipeline QA for run pipline question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant