Skip to main content

Python interface to financial data provided by Norgate Data

Project description

alt text

Python interface to financial market data provided by Norgate Data.

Table of Contents

Basics

Requirements

  • Python 3.5+ (has been tested with 3.5, 3.6, 3.7, 3.8, 3.9, 3.10)
  • Microsoft Windows
  • Packages: pandas, numpy, requests and logbook (these will be installed by pip, or you can install them prior to installing this package)
  • Active Norgate Data subscription
  • Norgate Data Updater software installed and running
  • Writable local user folder named .norgatedata - ie. C:\Users<your username>.norgatedata (or you can specify your own folder using environment variable NORGATEDATA_ROOT)

Note: The "Norgate Data Updater" application (NDU) is a Windows-only application. NDU must be running for this Python package to work.

Installation

pip install norgatedata

Upgrades

To receive upgrades/updates

pip install norgatedata --upgrade

Usage

import norgatedata

Price and Volume Data

Price data is provided in multiple formats: NumPy recarray, NumPy ndarray or Pandas DataFrame. This is determined through the format parameter. If not specified, the default is NumPy recarray.

Dates are determined by passing in any (or none) of the following named parameters:

# start_date and end_date can be provided as a string (YYYY-MM-DD or YYYYMMDD format), 
# datetime, Pandas Timestamp, or NumPy datetime64.  All types work!
start_date = '1990-01-01'   # If not specified, the start date is the start of the history for that symbol
end_date = '2000-01-01'   # If not specified, the end date is today
limit = 50  # This provides the last X records, by date in descending order.  If not specified, all records are returned
interval = 'D' # D=Daily, W=Weekly, M=Monthly - Note: the date given is the last date of the interval 

Price & Volume adjustment allows you to adjust historical stock prices and volumes to account for the effect of capital events and dividends.

priceadjust = norgatedata.StockPriceAdjustmentType.NONE
priceadjust = norgatedata.StockPriceAdjustmentType.CAPITAL
priceadjust = norgatedata.StockPriceAdjustmentType.CAPITALSPECIAL
priceadjust = norgatedata.StockPriceAdjustmentType.TOTALRETURN # Default

Date padding allows you to repeat the prior close on days where no price record would otherwise exist.

padding_setting = norgatedata.PaddingType.NONE  # Default
padding_setting = norgatedata.PaddingType.ALLMARKETDAYS
padding_setting = norgatedata.PaddingType.ALLWEEKDAYS
padding_setting = norgatedata.PaddingType.ALLCALENDARDAYS  # This can be useful to obtain an end-of-motnh or end-of-quarter value

Columns returned include Date, Open, High, Low, and Close. For certain instruments, additional columns are provided where applicable including: Volume (Stocks, some Indices, some Indicators, Futures), Turnover (Stocks, some Indices, some Indicators), Unadjusted Close (Stocks), Dividend (Stocks), Open Interest (Futures, ASX Exchange Traded Options), Delivery Month (Continuous Futures).

Examples

import norgatedata
priceadjust = norgatedata.StockPriceAdjustmentType.TOTALRETURN 
padding_setting = norgatedata.PaddingType.NONE   
symbol = 'AAPL'
start_date = '1990-01-01'
timeseriesformat = 'numpy-recarray'

# Provides data on GOOG from 1990 until today in 
# a NumPy recarray format, with explicitly set stock price 
# adjustment and padding settings
pricedata_recarray = norgatedata.price_timeseries(
    symbol,
    stock_price_adjustment_setting = priceadjust,
    padding_setting = padding_setting,
    start_date = start_date,
    timeseriesformat=timeseriesformat,
)

# Now in a Pandas-compatible format
import pandas as pd
timeseriesformat = 'pandas-dataframe'
start_date = pd.Timestamp('1900-01-01') # we can also provide dates as a Pandas Timestamp
pricedata_dataframe = norgatedata.price_timeseries(
    symbol,
    stock_price_adjustment_setting = priceadjust,
    padding_setting = padding_setting,
    start_date = start_date,
    timeseriesformat=timeseriesformat,
)

# Weekly data instead
timeseriesformat = 'pandas-dataframe'
start_date = pd.Timestamp('1900-01-01') # we can also provide dates as a Pandas Timestamp
pricedata_dataframe = norgatedata.price_timeseries(
    symbol,
    stock_price_adjustment_setting = priceadjust,
    padding_setting = padding_setting,
    start_date = start_date,
    timeseriesformat=timeseriesformat,
    interval='W'
)

# Now in a Numpy Ndarray
import numpy as np
timeseriesformat = 'numpy-ndarray'
start_date = np.datetime64('1900-01-01') # we can also provide dates as a Numpy datetime64
pricedata_ndarray = norgatedata.price_timeseries(
    symbol,
    stock_price_adjustment_setting = priceadjust,
    padding_setting = padding_setting,
    start_date = start_date,
    timeseriesformat=timeseriesformat,
)

# Now limiting results to final 500 bars
pricedata_dataframe = norgatedata.price_timeseries(
    symbol,
    stock_price_adjustment_setting = priceadjust,
    padding_setting = padding_setting,
    limit=500,
    timeseriesformat=timeseriesformat,
)
                          
# Now limiting results to a specific date range
end_date='1999-12-31'
pricedata_dataframe = norgatedata.price_timeseries(
    symbol,
    stock_price_adjustment_setting = priceadjust,
    padding_setting = padding_setting,
    start_date = start_date,
    end_date = end_date,
    timeseriesformat=timeseriesformat,
)

# Now using a numerical unchanging assetid instead of a symbol
timeseriesformat = 'pandas-dataframe'
assetid = 136817
pricedata_dataframe = norgatedata.price_timeseries(
    assetid,
    limit=500,
    timeseriesformat=timeseriesformat,
)

Datetime formats

By default, NumPy ndarray and recarray provides datetime64 formattted as '<M8[D]' (daily dates) as timezone naive. Pandas dataframes default to use datetime64 formattted as '[ns]' to match Pandas Timestamp, as timezone naive.

These can be altered with the following parameters:

datetimeformat='<desired format>'

allowed values are:

  • 'datetime' : Provides Python datetime.datetime objects
  • 'date' : Provides Python datetime.date objects
  • 'datetime64ns': Provides timezone-naive NumPy datetime64 in 'datetime64[ns]' format
  • 'datetime64ms': Provides timezone-naive NumPy 'datetime64[ms]' format
  • 'm8d': Provides timezone-naive NumPy datetime64 in '<M8[D]' format
timezone='<desired timezone>'

This will allocate the dates into the timezone as shown on any of the time series functions. Times will still be shown as 00:00:00. Accepts a string with valid timezones such as 'UTC', 'US/Eastern' etc.

Dividend Notes

Dividends shown in the price_timeseries Dividend column depending on whether or not they have already been accounted for in the data by the "Price Adjustment" method.

  • If the data is adjusted for capital reconstructions only, then the sum of both special and ordinary dividends for that day are shown.
  • If the data is adjusted for capital reconstructions and special dividends, then only the sum of ordinary dividends for that day are shown.
  • If the data is adjusted for capital reconstructions, special dividends and ordinary dividends, then no information is shown.

Dividend/Distribution information is shown as of the day before the ex-date - i.e. if you are holding the security at the close, you will be entitled to the dividend/distribution.


Time Series Data

Index Constituents

To determine whether a stock was an index constituent on a particular date, you can use the index constituent timeseries function. You can also pass in an existing NumPy ndarray or Pandas Dataframe and a new column will be added and returned.

Note: Access to historical index constituents requires a Norgate Data Stocks subscription at the Platinum or Diamond level.

symbol = 'AAPL'
indexname = 'Russell 3000'
indexname = 'S&P 500'  # Can also be an index symbol, such as $SPX, $RUI etc.

idx = norgatedata.index_constituent_timeseries(
    symbol,
    indexname,
    timeseriesformat = "numpy-recarray",
)

# Timeseries against a specific symbol starting from start_date in numpy-ndarray format

idx = norgatedata.index_constituent_timeseries(
    symbol,
    indexname,
    padding_setting = padding_setting,
    start_date = start_date,
    timeseriesformat  = "numpy-ndarray",
)

# Timeseries against a specific symbol starting from start_date in pandas dataframe format

idx = norgatedata.index_constituent_timeseries(
    symbol,
    indexname,
    padding_setting = padding_setting,
    start_date = start_date,
    timeseriesformat  = "pandas-dataframe",
)

# Let's pass in data from a recarray for TWTR

import norgatedata
import pandas as pd
priceadjust = norgatedata.StockPriceAdjustmentType.TOTALRETURN
padding_setting = norgatedata.PaddingType.NONE
symbol='TWTR'
timeseriesformat = 'numpy-recarray'
priceadjust = norgatedata.StockPriceAdjustmentType.TOTALRETURN
padding_setting = norgatedata.PaddingType.NONE
pricedata_recarray = norgatedata.price_timeseries(
    symbol,
    stock_price_adjustment_setting = priceadjust,
    padding_setting = padding_setting,
    timeseriesformat = timeseriesformat,
)

# and now make the call to index_constituent_timeseries
pricedata_recarray2 = norgatedata.index_constituent_timeseries(
    symbol,
    indexname,
    padding_setting = padding_setting,
    numpy_recarray = pricedata_recarray,
    timeseriesformat = timeseriesformat,
)

# Alternative using pandas dataframes instead:

import norgatedata
import pandas as pd
priceadjust = norgatedata.StockPriceAdjustmentType.TOTALRETURN
padding_setting = norgatedata.PaddingType.NONE
symbol='TWTR'
timeseriesformat = 'pandas-dataframe'
priceadjust = norgatedata.StockPriceAdjustmentType.TOTALRETURN
padding_setting = norgatedata.PaddingType.NONE
pricedata_df = norgatedata.price_timeseries(
    symbol,
    stock_price_adjustment_setting = priceadjust,
    padding_setting = padding_setting,
    timeseriesformat = timeseriesformat,
)

# and now make the call to index_constituent_timeseries
pricedata_df2 = norgatedata.index_constituent_timeseries(
    symbol,
    indexname,
    padding_setting = padding_setting,
    pandas_dataframe = pricedata_df,
    timeseriesformat = timeseriesformat,
)

Major Exchange Listed

majexch = norgatedata.major_exchange_listed_timeseries(
    symbol,
    timeseriesformat = "numpy-recarray")

Provides indication about US stocks on whether they are listed on a major exchange (e.g. NYSE, Nasdaq, NYSE American, NYSE Arca, Cboe BZX, IEX) (value = 1) or as an OTC/Pink Sheet stock (value = 0) for each trading date is available for all Equities and ETPs.

Note: Data is only available for this item from 2000 onwards.

Note: Access to major exchange listing requires a Norgate Data Stocks subscription at the Platinum or Diamond level.

Blank Check Company

majexch = norgatedata.blank_check_company_timeseries(
    symbol,
    timeseriesformat = "numpy-recarray")

Show periods when the company is regarded to be a blank check company.

Note: Access to blank check company requires a Norgate Data Stocks subscription at the Platinum or Diamond level.

Capital Event

capevent = norgatedata.capital_event_timeseries(
    symbol,
    timeseriesformat = "numpy-recarray")

This indicator will show when a capital event occurred. Effective on holding the security at the close on the day prior to the ex-date. Events include splits, reverse splits, bonus issues, stock dividends (dividends paid as stock) and complex reorganizations of capital (value = 1, otherwise if there is no event, value = 0)

Dividend Yield

divyield = norgatedata.dividend_yield_timeseries(
    symbol,
    timeseriesformat = "numpy-recarray",
)

This indicator uses a trailing 12 month sum of all split-adjusted ordinary dividends and is calculated daily against the close price. New dividends are incorporated on the entitlement date (the trading day prior to the ex-dividend date) after which the trailing 12 month sum of dividends is recalculated. Special dividends, distributions and spin-offs are not included. The lookback period is adaptive to take into account slight variations in ex-dividend dates from year-to-year.

Padding Status

paddingstatus = norgatedata.padding_status_timeseries(
    symbol,
    timeseriesformat = "numpy-recarray",
)

This indicator will show when a price record has been padded in accordance with the Date Padding setting. If the Date Padding is set to "No padding" then this indicator will not return any values.

Unadjusted Close

This is not normally needed, as Unadjusted Close is provided in the price timeseries.
It is provided here to be used as a helper routine for other Python libraries such as zipline-norgatedata.

unadjclose = norgatedata.unadjusted_close_timeseries(
    symbol,
    timeseriesformat = "numpy-recarray",
)

Single Value Data

Metadata

Security information

Assetid / Symbol Translation

symbol = 'AMZN'
assetid = norgatedata.assetid(symbol)

Provides a unique unchanging ID generated by Norgate.

assetid = 129769 
symbol = norgatedata.symbol(assetid)

Translates assetid to the current symbol.

Domicile

domicile = norgatedata.domicile(symbol)

Provides the country code for the domicile of the company.

Currency

currency = norgatedata.currency(symbol)

Currency that the security trades in.

Short Exchange Name

exchange_name = norgatedata.exchange_name(symbol)

Short name of the exchange for the security (e.g. NYSE, Nasdaq, NYSE Arca, NYSE American, ASX etc.)

Full Exchange Name

exchange_name_full = norgatedata.exchange_name_full(symbol)

Provides long name of the exchange (e.g. New York Stock Exchange, Australian Securities Exchange etc.)

Security Name

security_name = norgatedata.security_name(symbol)

Provides the name of the security. e.g. GE would return General Electric Co Common.

Base Type

base_type = norgatedata.base_type(symbol)

Provides the base type of a security. Values include Stock Market, Futures Market, Commodity Cash & Forwards, Foreign Exchange, Economic.

Subtype1

subtype1 = norgatedata.subtype1(symbol)

Provides subtype1 of the security. Values include Equity, Hybrid, Derivative, Debt, Exchange Traded Product, Business Activity, Employment, Prices, Money, National Accounts, Index, Currency Cross, Bullion Cross, Cryptocurrency.

Subtype2

subtype2 = norgatedata.subtype2(symbol)

Provides subtype2 of the security. Values include Operating/Holding Company, Investment Company, Special Purpose Company, Exchange Traded Note, Structured Product, Exchange Traded Fund, Exchange Traded Managed Fund, Third Party Trust Preferred, Corporate Unit, Convertible Corporate Unit, Convertible Preferred, Preferred, Convertible Debt, Exchange Traded Option, Right, Company Option, Warrant, Senior Debt, Junior Debt, Coin, Token.

Subtype3

subtype3 = norgatedata.subtype3(symbol)

Provides subtype3 of the security. Values include Master Limited Partnership, Royalty Trust, Infrastructure Fund, Closed End Fund, Other Listed Managed Investment, Business Development Company/Pooled Development Fund, Other Listed Investment Vehicle, Absolute Return Fund, Equity Unit, Right, Contingent Value Right, Litigation Trust, Liquidation Trust, Special Purpose Acquisition Company.

Financial Summary

financial_summary = norgatedata.financial_summary(symbol)

Provides a few paragraphs summarising the current financial status of the company.

Business Summary

business_summary = norgatedata.business_summary(symbol)

Provides a few paragraphs summarising the operations of the company.

First Quoted Date

first_quoted_date = norgatedata.first_quoted_date(symbol)
first_quoted_date = norgatedata.first_quoted_date(symbol,datetimeformat = 'iso')
first_quoted_date = norgatedata.first_quoted_date(symbol,datetimeformat = 'pandas-timestamp')
first_quoted_date = norgatedata.first_quoted_date(symbol,datetimeformat = 'numpy-datetime64')
first_quoted_date = norgatedata.first_quoted_date(symbol,datetimeformat = 'datetime')

Provides a date for the first day the security traded.By default the datetimeformat is an ISO string (YYYY-MM-DD), but you can also specify other formats too.

Last Quoted Date

last_quoted_date = norgatedata.last_quoted_date(symbol)
last_quoted_date = norgatedata.last_quoted_date(symbol,datetimeformat = 'iso')
last_quoted_date = norgatedata.last_quoted_date(symbol,datetimeformat = 'pandas-timestamp')
last_quoted_date = norgatedata.last_quoted_date(symbol,datetimeformat = 'numpy-datetime64')
last_quoted_date = norgatedata.last_quoted_date(symbol,datetimeformat = 'datetime')

Provides a date for the last day of trading that have a finite lifespan (such as futures). For delisted instruments, this provides the final day of trading. By default the format is an ISO string (YYYY-MM-DD), but you can also specify other formats too. Will provide None if there is no last quoted date.

Second Last Quoted Date

second_last_quoted_date = norgatedata.second_last_quoted_date(symbol)
second_last_quoted_date = norgatedata.second_last_quoted_date(symbol,datetimeformat = 'iso')
second_last_quoted_date = norgatedata.second_last_quoted_date(symbol,datetimeformat = 'pandas-timestamp')
second_last_quoted_date = norgatedata.second_last_quoted_date(symbol,datetimeformat = 'numpy-datetime64')
second_last_quoted_date = norgatedata.second_last_quoted_date(symbol,datetimeformat = 'datetime')

Provides a date for the second last day of trading that have a finite lifespan (such as futures). For delisted instruments, this provides the trading day prior to the last quoted day. Will provide None if there is no last quoted date.

Classifications

Mechanisms are provided to obtain the most detailed classification, classification at a level and an industry index that corresponds to the given symbol.

Classification

schemename = 'NorgateDataFuturesClassification'
schemename = 'TRBC'
schemename = 'GICS'
classificationresulttype = 'ClassificationId'
classificationresulttype = 'Name'
classification = norgatedata.classification(
    symbol,
    schemename,
    classificationresulttype,
)

Provides the classification for a given security as a string. Returns None if there is no classification available.

Classification At Level

schemename = 'TRBC'
schemename = 'GICS'
classificationresulttype = 'ClassificationId'
classificationresulttype = 'Name'
level = 1
level = 4
classificationatlevel = norgatedata.classification_at_level(
    symbol,
    schemename,
    classificationresulttype,
    level,
)

Provides the classification for a given security, at a given level of the classification scheme as a string. Returns None if there is no classification available.

Corresponding Industry Index

symbol='GE'
indexfamilycode = '$SPX'
indexfamilycode = '$SP1500'
level = 3
indexreturntype = 'PR'
indexreturntype = 'TR'
indexsymbol = norgatedata.corresponding_industry_index(
    symbol,
    indexfamilycode,
    level,
    indexreturntype,
)

Provides the symbol of a corresponding index, at a given level of the classification scheme. Returns None if there is no classification for the current symbol or no currently-trading index that matches.

Shares Outstanding / Shares Float

symbol='GE'
sharesout,sharesoutdate = norgatedata.sharesoutstanding(symbol)
sharesout,sharesoutdate = norgatedata.sharesoutstanding(symbol,datetimeformat = 'iso')
sharesout,sharesoutdate = norgatedata.sharesoutstanding(symbol,datetimeformat = 'pandas-timestamp')
sharesout,sharesoutdate = norgatedata.sharesoutstanding(symbol,datetimeformat = 'numpy-datetime64')
sharesout,sharesoutdate = norgatedata.sharesoutstanding(symbol,datetimeformat = 'datetime')

Provides the number of shares outstanding and date on which this was last modified for a given security. By default, the date is provided as a string in YYYY-MM-DD format, but other date formats can be specified.

symbol='GE'
sharesfloat,sharesfloatdate = norgatedata.sharesfloat(symbol)
sharesfloat,sharesfloatdate = norgatedata.sharesfloat(symbol,datetimeformat = 'iso')
sharesfloat,sharesfloatdate = norgatedata.sharesfloat(symbol,datetimeformat = 'pandas-timestamp')
sharesfloat,sharesfloatdate = norgatedata.sharesfloat(symbol,datetimeformat = 'numpy-datetime64')
sharesfloat,sharesfloatdate = norgatedata.sharesfloat(symbol,datetimeformat = 'datetime')

Provides the number of free float shares and date on which this was last modified for a given security. By default, the date is provided as a string in YYYY-MM-DD format, but other date formats can be specified.

Futures metadata

Tick size

Provides the current tick value (i.e. the change in value of one contract for a single tick that the futures contract moves.) for a given market.

symbol='CL-2017X'
tick_size = norgatedata.tick_size(symbol)

Point Value

symbol='CL-2017X'
point_value = norgatedata.point_value(symbol)

Provides the point value (i.e. the change in value of one contract for whole point that the futures contract moves.) for a given futures market.

Margin

symbol='CL-2017X'
margin = norgatedata.margin(symbol)

Provides the current margin for a given futures contract, futures market session symbol or futures market symbol.

First Notice Date

symbol='CL-2017X'
first_notice_date = norgatedata.first_notice_date(symbol)
first_notice_date = norgatedata.first_notice_date(symbol,datetimeformat = 'iso')
first_notice_date = norgatedata.first_notice_date(symbol,datetimeformat = 'pandas-timestamp')
first_notice_date = norgatedata.first_notice_date(symbol,datetimeformat = 'numpy-datetime64')
first_notice_date = norgatedata.first_notice_date(symbol,datetimeformat = 'datetime')

For deliverable commodity contracts that permit delivery prior to the end of trading, this is the first date that delivery notices can be provided for a given futures contract. For futures contracts that are not deliverable (or only deliverable at the end of trading) then None is provided.

Lowest Ever Tick Size

symbol='CL-2017X'
lowest_ever_tick_size = norgatedata.lowest_ever_tick_size(symbol)

Provides the lowest ever tick size for a given futures market.

Session Type

symbol='FDAX-2019Z'
sessiontype = norgatedata.session_type(symbol)
# Returns "Electronic"

symbol='FDAX9-2019Z'
sessiontype = norgatedata.session_type(symbol)
# Returns "Electronic (Last)"

session_symbol='FDAX9'
sessiontype = norgatedata.session_type(session_symbol)
# Returns "Electronic (Last)"

Returns the session type for a given symbol or session symbol.

Market Name

market_symbol='CL'
marketname = norgatedata.futures_market_name(market_symbol)
# Returns "Crude Oil"

Provides the name of the futures market

Futures Market Session Name

session_symbol='FDAX9'
session_name = norgatedata.futures_market_session_name(session_symbol)
# Returns "DAX (L)"

Provides the name of the futures market session

Futures Market Session Symbol

symbol='FDAX9-2020Z'
session_symbol = norgatedata.futures_market_session_symbol(symbol)
# Returns "FDAX9"

Provides the session symbol for a given futures contract

Futures Market Symbol

symbol='FDAX9-2020Z'
session_symbol = norgatedata.futures_market_symbol(symbol)
# Returns "FDAX"

Provides the market symbol for a given futures contract.

Futures Market Session Contracts

session_symbol='FDAX9'
session_symbol = norgatedata.futures_market_session_contracts(session_symbol)
# Returns a list ['FDAX9-2005Z', 'FDAX9-2006H', ..., 'FDAX9-2021M']

Provides all contracts (active and expired) for a given futures session symbol.

Futures Market Symbols

market_symbols = norgatedata.futures_market_symbols()
# Returns a list ['6A', '6B', ... 'FCE', 'FDAX', 'FESX', 'FGBL',  ... 'ZT', 'ZW']'

Provides a list of all futures market symbols.

Futures Market Session Symbols

session_symbols = norgatedata.futures_market_session_symbols()
# Returns a list ['6A', '6B', ... 'FCE', 'FDAX', 'FDAX9', 'FESX', 'FEX9', 'FGBL',  ...  'ZT', 'ZW']'

Provides a list of all futures market session symbols.

Notes

Note: For all futures metadata the "symbol" can be individual futures contract, a continuous contract symbol, the futures market session symbol or the futures market symbol. (e.g. FDAX9-2019Z, &FDAX9, FDAX9, FDAX respectively). The only exception to this is any date-related metadata, which can only be performed on the individual futures contract.

Fundamental data

symbol = 'GE'
# A selection of field examples - many more are available
fieldname = 'mktcap'
fieldname = 'ttmepsxlcx'
fieldname = 'peexclxor'
fieldname = 'projepsq'
fieldname = 'sharesoutstanding'
fieldname = 'sharesfloat'
fundavalue,fundadate = norgatedata.fundamental(symbol,fieldname)
fundavalue,fundadate = norgatedata.fundamental(symbol,fieldname,datetimeformat = 'iso')
fundavalue,fundadate = norgatedata.fundamental(symbol,fieldname,datetimeformat = 'pandas-timestamp')
fundavalue,fundadate = norgatedata.fundamental(symbol,fieldname,datetimeformat = 'numpy-datetime64')
fundavalue,fundadate = norgatedata.fundamental(symbol,fieldname,datetimeformat = 'datetime')

Provides the current fundamentals

Returns the field and the date applicable to the field (e.g. the last day of the quarter to which it applies, or for current ratios the most recent date of change). By default, the date is provided as a string in YYYY-MM-DD format, but other date formats can be specified.

Returns None,None if the fieldname is not available for that security.


Security lists

Watchlists

Python can retrieve the contents of any watchlist that exists in NDU's WatchList Library

When you create a watchlist, you can make it as broad or narrow as you like. To have a dynamic watchlist for the entire "Stock Market", don't apply any filters.

The symbols of a watchlist can be retrieved into a Python list using the watchlist_symbols() and watchlist() functions.

Watchlist Symbols

watchlistname = 'S&P 500'
symbols = norgatedata.watchlist_symbols(watchlistname)

watchlistname = 'Russell 3000 Current & Past'
symbols = norgatedata.watchlist_symbols(watchlistname)

Watchlist Securities

If you want the symbol, assetid and name of each security, use the watchlist function

watchlistname = 'Russell 3000 Current & Past'
wlcontents = norgatedata.watchlist(watchlistname)

Available Watchlists

To retrieve the names of all of the watchlists within Norgate Data's watchlist library, use the watchlists() function

allwatchlistnames = norgatedata.watchlists()

Databases

Python can retrieve the contents of any database available in a subscription. You can see which databases are available by opening NDU and clicking on the "Database" tab.

As an example, a subscriber to US Stocks at the Platinum level should see the following databases in the "Database List": 'US Equities', 'US Equities Delisted', 'US Indices', 'World Indices','Economic', 'Forex Spot', and 'Futures Continuous'.

Database Symbols

databasename = 'US Equities'
symbols = norgatedata.database_symbols(databasename)

databasename = 'World Indices'
symbols = norgatedata.database_symbols(databasename)

Database Securities

If you want the symbol, assetid and name of each security provided, use the database function:

databasename = 'AU Equities'
databasecontents = norgatedata.database(databasename)

Available Databases

To retrieve the names of all available databases, use the databases() function.

alldatabasenames = norgatedata.databases()

Futures Symbols

See Futures Market Symbols and Futures Market Session Symbols above.


Other informational functions

  • norgatedata.last_database_update_time(database) - returns a datetime object when price-related information was updated for a given database, where database is the shortened form for each database. Database names include au, aueto, auwarrant, auindex, ca, caindex, us, usindex, cashcommodity, economic, future, forex, contfuture, worldindex. The datetime object provided is the local PC time when the database was last updated (it does not refer to the latest price date in the databse).

  • norgatedata.last_price_update_time(symbol) datetime when price-related information was last updated for the given symbol. The datetime object provided is the local PC time when the database was last updated (it does not refer to the latest price date in the databse).

  • norgatedata.status() - shows whether NDU is running (returns True if running, or False if not)


Additional notes

Accessing data by assetid instead of symbol

Instead of using a security's symbol, you can obtain its unique Norgate-provided identity known as assetid. This is an unchanging number and is therefore useful when storing positions/orders into data files where the symbol may change in the future.

All of the calls above that reference 'symbol' (as a string) can also take an assetid (as an integer). For example, symbol MSFT = assetid 134016. symbol AMZN = assetid 129769.

Error Handling

If an invalid symbol or invalid parameters are specified, then the ValueError exception will be raised.

The logger module will also output human-interpretable detail relating to the error.

If there is no data available (for example, a informational or fundamental field that is not reported for that company), then None is returned, except in the case where multiple values are expected eg. (None, None).

Multithreading / Multiprocessing compatibility

The norgatedata package is compatible with multithreading and multiprocessing libraries/packages, to take advantage of multiple CPU cores. This can result in a significant reduction in runtime by running operations in parallel, depending upon workload.


Python Quant/Backtesting Package Integration

All of the routines developed in this module provide the data that can be used for backtesting/scanning of data. There are many backtesting packages developed that use Python. In this section, we provide more information about how to use with popular backtesting python packages with sample code and/or links to Norgate-developed integration packages.

Zipline

The package: zipline-norgatedata provides a tight integration between Zipline and Norgate Data

Key Features

  • Survivorship bias-free bundles
  • Incorporates time series data such as historical index membership and dividend yield into Zipline's Pipeline mechanism
  • No modifications to the Zipline code base (except to fix problems with installation and obsolete calls that crash Zipline)
  • Simple bundle creation
  • Easy ingestion of equities data into Zipline with a simple list of symbols you want to incorporate and/or import your own symbol lists and/or use pre-built or user-created watchlists from Norgate Data
  • Easy ingestion of futures data into Zipline with a simple list of symbols you want to incorporate, futures market sessions you want to incorporate, and/or use pre-built or user-created watchlists from Norgate Data

Backtrader

Backtrader is a Python framework for backtesting and trading.

To create a "data feed" of a given symbol:

import backtrader as bt
import norgatedata

# ... your code here ...
cerebro = bt.Cerebro()  # create a "Cerebro" engine instance
# ... your code here ...

# Obtain a Pandas dataframe for a given security from Norgate Data
priceadjust = norgatedata.StockPriceAdjustmentType.TOTALRETURN 
padding_setting = norgatedata.PaddingType.NONE   
symbol = 'AAPL'
start_date = '2010-01-01'
timeseriesformat = 'pandas-dataframe'
pricedata_dataframe = norgatedata.price_timeseries(
    symbol,
    stock_price_adjustment_setting = priceadjust,
    padding_setting = padding_setting,
    start_date = start_date,
    timeseriesformat=timeseriesformat,
)

# Rename columns to suit Backtrader
pricedata_dataframe.rename(
    columns={ 'Open':'open',  'High':'high', 'Low':'low', 'Close':'close', 'Volume':'volume', 'Open Interest':'open interest'},
    inplace=True)

# Backtrader can convert this dataframe into its own internal format with:
data = bt.feeds.PandasData(dataname=pricedata_dataframe)
cerebro.adddata(data)  # Add the data feed
# ... your code here ...

pybacktest

pybacktest is a backesting package for simple backtests against a single security. It is no longer maintained by its author but it is still functional.

Pre-requisites:

  • Python 3.5-3.9
  • Git
  • Virtual Environment (e.g. Anaconda)

Here's how we installed it:

Install the 64 bit MiniConda or Anaconda Distribution.

Install the 64 bit version of Git and used all default options at install time.

Start an Anaconda (base) prompt, create an environment and install the appropriate versions of packages as follows:

conda create -n pybacktest39 python=3.9
conda activate pybacktest39
pip install git+https://github.com/ematvey/pybacktest.git
pip install pandas_datareader
pip install norgatedata

Here's a sample piece of code that uses data from Norgate data.

import norgatedata
import pybacktest
import pandas

# Obtain data from Norgate Data first, in Pandas dataframe format
priceadjust = norgatedata.StockPriceAdjustmentType.TOTALRETURN 
padding_setting = norgatedata.PaddingType.NONE   
symbol = 'AAPL'
start_date = '2010-01-01'
timeseriesformat = 'pandas-dataframe'
ohlc = norgatedata.price_timeseries(
    symbol,
    stock_price_adjustment_setting = priceadjust,
    padding_setting = padding_setting,
    start_date = start_date,
    timeseriesformat=timeseriesformat,
)

# Change column names
ohlc.rename(
    columns={'Open':'O', 'High':'H', 'Low':'L', 'Close':'C', 'Volume':'V'},
    inplace=True)

# sample pybacktest code:
ms = ohlc.C.rolling(50).mean()
ml = ohlc.L.rolling(100).mean()
buy = cover = (ms > ml) & (ms.shift() < ml.shift())
sell = short = (ms < ml) & (ms.shift() > ml.shift())

backtestresults = pybacktest.Backtest(locals())

Tensorflow

Tensorflow

Use the convert_to_tensor() function to convert a Numpy Array for use with the TensorFlow machine learning platform

Also: TF Quant Finance

Keras

Keras

Use the tensorflow.keras.backend.variable() to convert a Numpy Array for use with the Keras deep learning library

More Python Quant/Backtesting/Machine Learning/Neural Network Packages

Here is a list of Python packages that might be worthwhile examining to incoroporate data from Norgate Data. Some of these might be abandonware too. Let us know if there's more worthy of integration.


Support

Norgate Data support

Recent Version History

v1.0.57 20210421 Fix typo on capitalevent parameter
v1.0.58 20210421 Fix datetime decode
v1.0.59 20210427 Fix timezone routines on Pandas dataframes
v1.0.60 20210918 Fix datetime conversion routines, and provide error on unknown type
v1.0.61 20220204 Bump to documentation to show Python 3.10 compatibility (no other changes)
v1.0.62 20220422 Handle version check file with unparseable json
v1.0.63 20221027 Better docs
v1.0.64 20221129 Fix datetimeformat=date/datetime in pandas-dataframe from being returned as a tupled object due to astype changes in numpy
v1.0.65 20230207 Better checking of .norgatedata storage folder and error message
v1.0.66 20230310 Use random filename during init routines to prevent multiple instances from having an issue
v1.0.67 20230501 Make decode_date have a default parameter for timezone of UTC, but tz=None can be passed in to make it naive.  This is an enhancement to support datetime changes in Zipline 2.4
v1.0.68 20230619 Documentation fixes - hyperlinks test
v1.0.69 20230619 Documentation fixes - pypi hyperlinks now work!
v1.0.70 20230619 Documentation fixes - pypi hyperlinks now work!!
v1.0.71 20230619 Documentation fixes - pypi hyperlinks now work!!!
v1.0.72 20230619 Documentation fixes - pypi hyperlinks now work!!!!
v1.0.73 20230710 Documentation now includes recent change log and upgrade warning is made more visible
v1.0.74 20231004 Blank Check Company Time Series added

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

norgatedata-1.0.74-py3-none-any.whl (37.2 kB view details)

Uploaded Python 3

File details

Details for the file norgatedata-1.0.74-py3-none-any.whl.

File metadata

  • Download URL: norgatedata-1.0.74-py3-none-any.whl
  • Upload date:
  • Size: 37.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.65.0 CPython/3.10.10

File hashes

Hashes for norgatedata-1.0.74-py3-none-any.whl
Algorithm Hash digest
SHA256 64ead3ca75f983d4d6c3caad4436d2a00cddc935c84fcfd3a82d4b7df34d7a20
MD5 deb435063652bc72f2662d789051d166
BLAKE2b-256 a087dba780e74d9a8737241e62ebc210667b350ee1c35c6feabd4234d269382a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page