Back to Community
Use StaticAssets for equities in foreign markets

Hi all,

I have checked out the educational posts both at https://www.quantopian.com/posts/how-to-get-static-assets-in-research and https://www.quantopian.com/posts/doing-pipeline-calculations-only-on-a-number-of-stocks-slash-assets.

I know I can use a list of US equities as a filter by doing:

from quantopian.research import run_pipeline, symbols  
filterSectors = StaticAssets(symbols(["XLF","XLRE","XLE","XLU","XLK","XLB","XLP","XLY","XLI","XLC","XLV"]))  

But I have problems listing equities in foreign markets. Take CN_EQUITIES for example, by running a blank pipeline I get to know how equities are named in the database. An example is:

Equity(1178883501215042 [603516])  

603516 is the widely accepted "name" of a Chinese stock easy to find online. I have no idea what 1178883501215042 is, maybe defined by the data provider? Right now I can only call the equity with the long number by:

StaticAssets(symbols([1178883501215042]))  
# >>> StaticAssets([], 0)  

But calling the short number gives the following error:

StaticAssets(symbols([603516]))  
# >>>  
# NoSuchSymbolsTraceback (most recent call last)  
# <ipython-input-53-7dc395df23f4> in <module>()  
# ----> 1 StaticAssets(symbols([603516]))

# /build/src/qexec_repo/qexec/research/api.py in symbols(symbols, symbol_reference_date, handle_missing)  
#     456             symbol_reference_date=symbol_reference_date,  
#     457             handle_missing=handle_missing,  
# --> 458             readers=readers,  
#     459         )  
#     460  
#  
# /build/src/qexec_repo/qexec/research/_api.pyc in inner_symbols(symbols, symbol_reference_date, handle_missing, readers)  
#     275  
#     276     if len(securities) == 0:  
# --> 277         raise NoSuchSymbols(symbols)  
#     278  
#     279     if symbols_is_scalar:  
#  
# NoSuchSymbols: Failed to find securities matching [603516]  

Running StaticAssets(symbols(['603516'])) gives similar error.

Therefore, how can we know the correspondence between the long number and the market-accepted short names? Or more straightforward, how can we just call the equities with this short number?

3 responses

And, do we have newer data? I just found that only data before 2018-08-18 is available, which makes this post unnecessary ;-(

Currently only US equities can be referenced by name. However, both US and non-US equities can be referenced by their 'security ID' or SID. The SID is a unique number which Quantopian uses to refer to a security. The SID is the long number and the symbol is the short value in the following

 Equity(1178883501215042 [603516])  

To get the SID from either the name or symbol one must first create a dataframe of securities. The pipeline output returns a multi-index dataframe which has the security objects as the level 1 index. Security objects have several attributes including asset_name (check out the docs for a complete description) . This can be used to lookup the SID for any security. However, one must create a pipeline with all the securities for a given domain first. Something like this.


# Research environment functions imports  
from quantopian.research import run_pipeline  
from quantopian.pipeline import Pipeline

from quantopian.pipeline.data import EquityPricing  
from quantopian.pipeline.domain import CN_EQUITIES

# set start and end dates and stock  
start_date='2018-06-18'  
end_date='2018-07-16' 

# Create an 'empty' un-screened pipeline containing all assets for a given domain  
all_cn_assets = run_pipeline(Pipeline(domain=CN_EQUITIES), start_date, end_date)

Next, add columns for the name, symbol, and SID from the security attributes. Something like this

# Create columns for the security name and symbol from attributes of the security object  
all_cn_assets['asset_name'] = [str(asset.asset_name) for asset in all_cn_assets.index.get_level_values(level=1)]  
all_cn_assets['symbol'] = [str(asset.symbol) for asset in all_cn_assets.index.get_level_values(level=1)]  
all_cn_assets['sid'] = [str(asset.sid) for asset in all_cn_assets.index.get_level_values(level=1)]

The resulting dataframe can be searched by name or symbol to find the associated SID.

The FactSet data for global equities typically have a 1 year holdout. So, the newest available data would be 1 year before the current date.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thanks for your reply and the inspirational method. This works fine for me.

Could I turn this post into a feature request for the up-to-date foreign data? I believe that would be really helpful to a lot of people.