# Research environment functions imports
from quantopian.research import run_pipeline
# Pipeline imports
from quantopian.pipeline.data import EquityPricing # OHLCV data for Global equity
from quantopian.pipeline.data import factset # FactSet data set
from quantopian.pipeline.domain import IN_EQUITIES # Indian equities
from quantopian.pipeline import Pipeline
# Other libraries imports
import matplotlib.pyplot as plt
import pandas as pd
# Select time period to inspect
start_period = '2015-01-15'
end_period= '2016-01-15'
# Pipeline definition
pipe=Pipeline(
columns={ 'price':EquityPricing.close.latest,
'volume':EquityPricing.volume.latest,
'mkt_cap':factset.Fundamentals.mkt_val.latest,
'economy':factset.RBICSFocus.l1_name.latest,
'sector':factset.RBICSFocus.l2_name.latest,
'subsector':factset.RBICSFocus.l3_name.latest,
'listing exchange':factset.EquityMetadata.primary_fsym_security_id.latest,
'listing currency':factset.EquityMetadata.listing_currency.latest,
'security type':factset.EquityMetadata.security_type.latest
},
domain=IN_EQUITIES)
# Pipeline execution
result= run_pipeline(
pipe,
start_period,
end_period)
result.loc['2016-01-15',:][result['security type']=='ETF_ETF']
# The index level=1 contains the security or asset object
# It has several attributes. Lets see what they are by looking at the docstr
first_security = result.index.get_level_values(level=1)[0]
help(first_security)
Some interesting attributes are | asset_name | exchange | exchange_full | symbol | sid
# Create columns to expose these attributes
result['asset_name'] = [str(asset.asset_name) for asset in result.index.get_level_values(level=1)]
result['exchange'] = [str(asset.exchange) for asset in result.index.get_level_values(level=1)]
result['exchange_full'] = [str(asset.exchange_full) for asset in result.index.get_level_values(level=1)]
result['symbol'] = [str(asset.symbol) for asset in result.index.get_level_values(level=1)]
result['sid'] = [str(asset.sid) for asset in result.index.get_level_values(level=1)]
# Look at the new dataframe and see how the different exchanges handle symbols
result.groupby('exchange').first()
# From above it can be seen that the BOM exchange uses numbers for tickers but the NSE uses alpha characters
# To reference a given asset one can use the standard 'symbols' method
# However, use the SID rather than the ticker. The ticker only works for US securities.
# Don't put the sid in quotes
argawals = symbols(1178883482794310)
argawals
# check it's the right one by lookiing at the name
argawals.asset_name
# a little trick to remove the preceding 'u'...
# change the value to an ascii string rather than unicode
str(argawals.asset_name)
So, referencing a global security is identical to a US security except use the SID rather than the ticker.