ETFs

Learn more: Example notebooks

Environment

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();

ETF instrument

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:

etf_names = ExchangeTradedFund.get_names()
etf_names[:5]

You can retrieve an individual ETF through the common object API:

agg = sig.obj.get('AGG UP EQUITY')
agg

Another way to list instruments is by retrieving an instrument's group directly:

agg.group().query_instrument_names()[:5]

It is also possible to access an instrument's exchange as an object in its own right:

exchange = sig.obj.get(agg.exchange().name)
exchange

From an exchange you can access market holiday calendar names, for example:

exchange.holidays

Calendars are objects that you can fetch and interrogate:

calendar = sig.obj.get(exchange.holidays)
calendar
calendar.holidays[:5]

To query the time series data from an ETF instrument, use the following API:

agg.history()

Other time series related to the specific instrument are available as well:

agg.history_fields

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:

agg.data_dict()

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 updated

© 2023 SIG Technologies Limited