ETFs
Setting up your environment takes three steps:
- Import the relevant internal and external libraries
- Configure the environment parameters
- Initialise the environment
import sigtech.framework as sig
from sigtech.framework.instruments.equities import ExchangeTradedFund
import pandas as pd
import seaborn as sns
sns.set(rc={'figure.figsize': (18, 6)})
sig.config.init();
We can list available ETFs in a similar way to indices, by calling
get_names
on the relevant class. In this case, it is done on the ExchangeTradedFund
class:Input
Output
etf_names = ExchangeTradedFund.get_names()
etf_names[:5]
['AGG UP EQUITY',
'BIL UP EQUITY',
'BND UP EQUITY',
'BNDX UP EQUITY',
'DBC UP EQUITY']
You can retrieve an individual ETF through the common object API:
Input
Output
agg = sig.obj.get('AGG UP EQUITY')
agg
AGG UP EQUITY <class 'sigtech.framework.instruments.equities.ExchangeTradedFund'>[139953121183952]
Another way to list instruments is by retrieving an instrument's group directly:
Input
Output
agg.group().query_instrument_names()[:5]
['AGG UP EQUITY',
'BIL UP EQUITY',
'BND UP EQUITY',
'BNDX UP EQUITY',
'DBC UP EQUITY']
It is also possible to access an instrument's exchange as an object in its own right:
Input
Output
exchange = sig.obj.get(agg.exchange().name)
exchange
NYSEARC(T) EXCHANGE GROUP <class 'sigtech.framework.instruments.base.Exchange'>[139953149826448]
From an exchange you can access market holiday calendar names, for example:
Input
Output
exchange.holidays
'NYSEARC(T) CALENDAR'
Calendars are objects that you can fetch and interrogate:
Input
Output
calendar = sig.obj.get(exchange.holidays)
calendar
NYSEARC(T) CALENDAR <class 'sigtech.framework.infra.cal.calendar.Calendar'>[139953149818576]
Input
Output
calendar.holidays[:5]
[datetime.date(1973, 1, 1),
datetime.date(1973, 1, 25),
datetime.date(1973, 1, 25),
datetime.date(1973, 2, 19),
datetime.date(1973, 4, 20)]
To query the time series data from an ETF instrument, use the following API:
Python
Output
agg.history()
2003-09-29 102.17
2003-09-30 102.70
2003-10-01 102.65
2003-10-02 102.49
2003-10-03 101.75
...
2021-02-23 115.51
2021-02-24 115.47
2021-02-25 114.41
2021-02-26 115.34
2021-03-01 115.09
Name: (LastPrice, EOD, AGG UP EQUITY), Length: 4385, dtype: float64
Other time series related to the specific instrument are available as well:
Input
Output
agg.history_fields
['OPEN', 'HIGH', 'LOW', 'LastPrice', 'Volume']
By passing in one of the different
history_fields
values as a parameter in the .history()
, different times series can be queried:df_agg = pd.concat({
'High': agg.history('HIGH').loc['2020':],
'Low': agg.history('LOW').loc['2020':]
}, axis=1)
df_agg.plot(title='AGG UP Equity High / Low');

volume_agg = agg.history('Volume').loc['2021':]
volume_agg.index = [x.date() for x in volume_agg.index]
volume_agg.plot(title='AGG UP EQUITY Volume', kind='bar');

Apart from the time series data, a specific instrument also holds static data:
Input
Output
agg.data_dict()
{'instrument_id': None,
'data_source_all': [],
'available_data_points': ['EOD'],
'default_data_point': 'EOD',
'price_factor': 1.0,
'use_price_factor': True,
'intraday_times': [],
'intraday_tz_str': 'UTC',
'currency': 'USD',
'db_ticker': None,
'db_sector': None,
'exchange_code': None,
'activity_fields': ['Volume'],
'group_name': None,
'description': None,
'db_history_end_date': datetime.date(9999, 12, 31),
'market_impact': 0.02,
'issuer': 'NYSEARC(T)',
'liquid_date': Timestamp('1677-09-21 00:12:43.145225'),
'delist_date': datetime.date(9999, 12, 31),
'eq_identifier': 'AGG UP',
'company_name': 'iShares Core U.S. Aggregate Bond ETF',
'country': 'US',
'currency_multiplier': 1,
'isin': 'US4642872265',
'cusip': '464287226',
'us_ric': 'AGG.P',
'primary_bbg_ticker': 'AGG UP Equity',
'composite_bbg_ticker': 'AGG US Equity',
'bbg_unique_id': 'EQ0000000000737315',
'primary_us_bbg_ticker': 'AGG UP Equity',
'composite_us_bbg_ticker': 'AGG US Equity',
'sec_code': '',
'region_code': '1',
'corporate_actions_override': None,
'sec_master_id': None,
'fungible_id': None,
'company_id': None,
'underlying_index_ticker': 'LBUSTRUU Index',
'total_expenses': 0.05,
'prime_history_field': 'LastPrice'}
To compare several ETFs, the following example shows that the platform is highly compatible with, and makes use of, the Python Pandas library:
ptf_etfs = ['SPY UP EQUITY', 'QQQ UP EQUITY', 'VEA UP EQUITY',
'AGG UP EQUITY', 'VWO UP EQUITY']
etf_histories = pd.concat({
x: sig.obj.get(x).history() for x in ptf_etfs
}, axis=1).dropna()
etf_histories.columns = [x.split('_')[0] for x in etf_histories.columns]
etf_histories.tail()

(etf_histories / etf_histories.iloc[0]).plot(title='ETF Performance');

Last modified 1yr ago