Code Examples

Install & Upgrade

The following installation and upgrade code examples assumes that Python version 3.11 or later is currently installed on the user's device.   Visit the following page below for information on downloading Python:

Python Downloads

Installation

Open a terminal and run:

pip install quickfin

Upgrade

After initial installation open a terminal and run the following to get the latest version of Quick Fin:

pip install --upgrade quickfin

PriceData Class

The PriceData class provides instant access to live and historical stock market price data and automated Plotly data visualization generators.

Import Quick Fin & Create a PriceData Class Instance

Once an instance of the PriceData class has been created, it can be used anywhere throughout a python module. At a minimum, this only needs to be done once.

Import Quick Fin and create an instance of the PriceData class:

from quickfin import *

price_data = PriceData()

PriceData Methods

The following examples provide brief descriptions for each method available in the `PriceData` class and will utilize the class instance assigned to the `price_data` variable from the example above.

current(symbol)

The `current` method is used to retrieve a payload containing the most recent stock price data available for the stock symbol passed to the `symbol` parameter.

Method will return live market price quotes during trading hours.

PAYLOAD CONTENTS:

Object

data = price_data.current("MSFT")

print(data) # Print object assigned to `data` variable
Output:
{
'info': {
  'industry': 'Software - Infrastructure',
  'name': 'Microsoft Corporation',
  'sector': 'Technology',
  'symbol': 'MSFT'
},
'current': {
  'Adj Close': 424.57,
  'Change Amount': -0.62,
  'Change Rate': -0.0,
  'Close': 424.57,
  'Date': '2024-04-01',
  'Day Range': 5.67,
  'High': 427.89,
  'Low': 422.22,
  'Open': 423.95,
  'Volume': 16298900
}
}

history(symbol)

The `history` method is used to retrieve a payload containing all historical stock price data available for the stock symbol passed to the `symbol` parameter.

data = price_data.history("META")

print(data)
Output:
{
'info': {
  'industry': 'Internet Content & Information',      
  'name': 'Meta Platforms, Inc.',
  'sector': 'Communication Services',
  'symbol': 'META'
},
'current': {
  'Adj Close': 491.35,
  'Change Amount': -4.15,
  'Change Rate': -0.01,
  'Close': 491.35,
  'Date': '2024-04-01',
  'Day Range': 15.65,
  'High': 497.43,
  'Low': 481.78,
  'Open': 487.2,
  'Volume': 9236300
},
'history': [
  {
    'Adj Close': 491.35,
    'Change Amount': -4.15,
    'Change Rate': -0.01,
    'Close': 491.35,
    'Date': '2024-04-01',
    'Day Range': 15.65,
    'High': 497.43,
    'Low': 481.78,
    'Open': 487.2,
    'Volume': 9236300
  },
  {
    'Adj Close': 485.58,
    'Change Amount': 7.26,
    'Change Rate': 0.01,
    'Close': 485.58,
    'Date': '2024-03-28',
    'Day Range': 7.74,
    'High': 492.89,
    'Low': 485.15,
    'Open': 492.84,
    'Volume': 15212800
  },
  {
    'Adj Close': 493.86,
    'Change Amount': 5.44,
    'Change Rate': 0.01,
    'Close': 493.86,
    'Date': '2024-03-27',
    'Day Range': 11.82,
    'High': 499.89,
    'Low': 488.07,
    'Open': 499.3,
    'Volume': 9989700
  }

  ---  snip  ---
]
}

history(symbol, days)

The `history` method is used to retrieve a payload containing all historical stock price data available for the stock symbol passed to the `symbol` parameter.

Passing a positive integer value to the `days` parameter will filter the historical data to include records for the number of most recent days represented by the parameter value.

data = price_data.history("DTE", days=5)

print(data)
Output:
{
'info': {
  'industry': 'Utilities - Regulated Electric',
  'name': 'DTE Energy Company',
  'sector': 'Utilities',
  'symbol': 'DTE'
},
'current': {
  'Adj Close': 110.73,
  'Change Amount': 1.41,
  'Change Rate': 0.01,
  'Close': 110.73,
  'Date': '2024-04-01',
  'Day Range': 1.86,
  'High': 112.14,
  'Low': 110.28,
  'Open': 112.14,
  'Volume': 847500
},
'history': [
  {
    'Adj Close': 110.73,
    'Change Amount': 1.41,
    'Change Rate': 0.01,
    'Close': 110.73,
    'Date': '2024-04-01',
    'Day Range': 1.86,
    'High': 112.14,
    'Low': 110.28,
    'Open': 112.14,
    'Volume': 847500
  },
  {
    'Adj Close': 112.14,
    'Change Amount': -0.82,
    'Change Rate': -0.01,
    'Close': 112.14,
    'Date': '2024-03-28',
    'Day Range': 1.34,
    'High': 112.31,
    'Low': 110.97,
    'Open': 111.32,
    'Volume': 990500
  },
  {
    'Adj Close': 111.3,
    'Change Amount': -3.35,
    'Change Rate': -0.03,
    'Close': 111.3,
    'Date': '2024-03-27',
    'Day Range': 3.46,
    'High': 111.41,
    'Low': 107.95,
    'Open': 107.95,
    'Volume': 1668700
  },
  {
    'Adj Close': 107.13,
    'Change Amount': 1.34,
    'Change Rate': 0.01,
    'Close': 107.13,
    'Date': '2024-03-26',
    'Day Range': 1.91,
    'High': 108.98,
    'Low': 107.07,
    'Open': 108.47,
    'Volume': 1110800
  },
  {
    'Adj Close': 108.42,
    'Change Amount': 0.88,
    'Change Rate': 0.01,
    'Close': 108.42,
    'Date': '2024-03-25',
    'Day Range': 1.41,
    'High': 109.3,
    'Low': 107.89,
    'Open': 109.3,
    'Volume': 1045100
  }
]
}

history(symbol, date)

The `history` method is used to retrieve a payload containing all historical stock price data available for the stock symbol passed to the `symbol` parameter.

Passing a date to the `date` parameter using the 'YYYY-DD-MM' format will filter the historical data to include a single record for the value assigned to the parameter.

data = price_data.history("CMS", date="2022-03-25")

print(data)
Output:
{
'info': {
  'industry': 'Utilities - Regulated Electric',
  'name': 'CMS Energy Corporation',
  'sector': 'Utilities',
  'symbol': 'CMS'
},
'current': {
  'Adj Close': 59.98,
  'Change Amount': 0.41,
  'Change Rate': 0.01,
  'Close': 59.98,
  'Date': '2024-04-01',
  'Day Range': 0.7,
  'High': 60.42,
  'Low': 59.72,
  'Open': 60.39,
  'Volume': 1619100
},
'history': [
  {
    'Adj Close': 64.66,
    'Change Amount': -0.72,
    'Change Rate': -0.01,
    'Close': 68.92,
    'Date': '2022-03-25',
    'Day Range': 0.94,
    'High': 69.05,
    'Low': 68.11,
    'Open': 68.2,
    'Volume': 1706900
  }
]
}

history(symbol, date_start, date_end)

The `history` method is used to retrieve a payload containing all historical stock price data available for the stock symbol passed to the `symbol` parameter.

Passing a date to both the `date_start` and the `date_end` parameter using the 'YYYY-DD-MM' format will filter the historical data to include multiple records for the date range represented by both values. Values must be passed to both the date_start and date_end parameter for date ranges to be returned.

data = price_data.history("SCS", date_start="2021-03-10", date_end="2021-03-14")

print(data)
Output:
{
'info': {
  'industry': 'Business Equipment & Supplies',
  'name': 'Steelcase Inc.',
  'sector': 'Industrials',
  'symbol': 'SCS'
},
'current': {
  'Adj Close': 13.03,
  'Change Amount': 0.09,
  'Change Rate': 0.01,
  'Close': 13.03,
  'Date': '2024-04-01',
  'Day Range': 0.35,
  'High': 13.3,
  'Low': 12.95,
  'Open': 13.12,
  'Volume': 1679800
},
'history': [
  {
    'Adj Close': 14.47,
    'Change Amount': -0.38,
    'Change Rate': -0.02,
    'Close': 16.59,
    'Date': '2021-03-12',
    'Day Range': 0.55,
    'High': 16.71,
    'Low': 16.16,
    'Open': 16.21,
    'Volume': 542400
  },
  {
    'Adj Close': 14.08,
    'Change Amount': 0.03,
    'Change Rate': 0.0,
    'Close': 16.14,
    'Date': '2021-03-11',
    'Day Range': 0.29,
    'High': 16.23,
    'Low': 15.94,
    'Open': 16.17,
    'Volume': 620200
  },
  {
    'Adj Close': 14.11,
    'Change Amount': -0.73,
    'Change Rate': -0.05,
    'Close': 16.18,
    'Date': '2021-03-10',
    'Day Range': 0.91,
    'High': 16.22,
    'Low': 15.31,
    'Open': 15.45,
    'Volume': 758800
  }
]
}

candlestick(symbol, days)

The `candlestick` method is used to generate a Plotly Candlestick plot for the most recent total number of days represented by the value passed to the `days` parameter.

Executing this method will automatically open the data visualization in the default web browser.

data = price_data.candlestick("F", 25)

print(data)
Output:
Candlestick Plot

line(symbol, days, param)

The `line` method is used to generate a Plotly Line plot for the most recent total number of days represented by the value passed to the `days` parameter for the specified data column passed to the `param` parameter.

Executing this method will automatically open the data visualization in the default web browser.

`param` OPTIONS:

- Change Amount
- Change Rate
- Day Range
- Volume
- Adj Close
- Close
- Low
- High
- Open

data = price_data.line("F", 25, "Close")

print(data)
Output:
Line Plot

table(symbol, days)

The `line` method is used to generate a Plotly Table for the most recent total number of days represented by the value passed to the `days` parameter.

Executing this method will automatically open the data visualization in the default web browser.

data = price_data.table("F", 25)

print(data)
Output:
Table Plot

FinInfo Class

The FinInfo class provides access to the metadata catalog used for for referencing equities, stock symbols, sectors, and industry information.

THE FOLLOWING APPLIES TO ALL FinInfo METHODS:

If the value is set to `False` for the `payload` parameter, this method will `pretty print` the requested data omitting a return value. Otherwise, the value assigned to the `payload` parameter is set to `True` by default, and the method will return a data payload.

Import Quick Fin & Create a FinInfo Class Instance

Once an instance of the FinInfo class has been created, it can be used anywhere throughout a python module. At a minimum, this only needs to be done once.

Import Quick Fin and create an instance of the FinInfo class:

from quickfin import *

fin_info = FinInfo()

FinInfo Methods

The following examples provide brief descriptions for each method available in the `FinInfo` class and will utilize the class instance assigned to the `fin_info` variable from the example above.

equity(symbol, payload=True)

The `equity` method is used to retrieve a data object containing the symbol, company name, sector, and industry for the stock symbol passed to the `symbol` parameter.

data = fin_info.equity("IBM")

print(type(data)) # Print Python data type

print(data) # Print object assigned to `data` variable
Output:
<class 'dict'>

{
'industry': 'Information Technology Services',
'name': 'International Business Machines Corporation',
'sector': 'Technology',
'symbol': 'IBM'
}

equities(payload)

The `equities` method is used to retrieve a data payload containing the symbol, company name, sector, and industry for all equities included in the metadata catalog.

PAYLOAD CONTENTS:

An array of objects.

data = fin_info.equities()

print(data)
Output:
[
{
  'industry': 'Diagnostics & Research',
  'name': 'Agilent Technologies, Inc.',
  'sector': 'Healthcare',
  'symbol': 'A'},
{
  'industry': 'Aluminum',
  'name': 'Alcoa Corporation',
  'sector': 'Basic Materials',
  'symbol': 'AA'
},
{
  'industry': 'Education & Training Services',
  'name': 'ATA Creativity Global',
  'sector': 'Consumer Defensive',
  'symbol': 'AACG'
},
---  snip  ---
]

industries(payload)

The `industries` method is used to retrieve a data payload containing a list of all industries available in the metadata catalog.

PAYLOAD CONTENTS:

An array of strings.

data = fin_info.industries()

print(data)
Output:
[
'Diagnostics & Research',
'Aluminum',
'Education & Training Services',
'Uncategorized',
'Shell Companies',
'Farm Products',
'Insurance - Life',
'Rental & Leasing Services',
'Communication Equipment',
'Building Products & Equipment',
'Specialty Retail',
'Consumer Electronics',
'REIT - Diversified',
'Asset Management',
---  snip  ---
]

sectors(payload)

The `sectors` method is used to retrieve a data payload containing a list of all sectors available in the metadata catalog.

PAYLOAD CONTENTS:

An array of strings.

data = fin_info.sectors()

print(data)
Output:
[
'Healthcare',
'Basic Materials',
'Consumer Defensive',
'Uncategorized',
'Financial Services',
'Industrials',
'Technology',
'Consumer Cyclical',
'Real Estate',
'Communication Services',
'Energy',
'Utilities'
]

sector_industries(sector)

The `sector_industries` method is used to retrieve a data payload containing a list of all industries belonging to the sector passed to the `sector` parameter.

PAYLOAD CONTENTS:

An array of strings. By default, the return value will include an object containing all sectors and associated industries.

data = fin_info.sector_industries("technology")

print(data)
Output:
[
'Communication Equipment',
'Consumer Electronics',
'Software - Infrastructure',
'Semiconductor Equipment & Materials',
'Information Technology Services',
'Software - Application',
'Semiconductors',
'Computer Hardware',
'Electronic Components',
'Solar',
'Electronics & Computer Distribution',
'Scientific & Technical Instruments'
]

sector_equities(sector, payload)

The `sector_industries` method is used to retrieve a data payload containing a list of all equities belonging to the sector passed to the `sector` parameter.

PAYLOAD CONTENTS:

An array of objects. By default, the return value will include an object containing all sectors and associated equity data.

data = fin_info.sector_equities("healthcare")

print(data)
Output:
[
{
  'industry': 'Diagnostics & Research',
  'name': 'Agilent Technologies, Inc.',
  'sector': 'Healthcare',
  'symbol': 'A'
},
{
  'industry': 'Drug Manufacturers - General',
  'name': 'AbbVie Inc.',
  'sector': 'Healthcare',
  'symbol': 'ABBV'
},
{
  'industry': 'Biotechnology',
  'name': 'AbCellera Biologics Inc.',
  'sector': 'Healthcare',
  'symbol': 'ABCL'
},
---  snip  ---
]

industry_equities(industry, payload)

The `industry_industries` method is used to retrieve a data payload containing a list of all equities belonging to the industry passed to the `industry` parameter.

PAYLOAD CONTENTS:

An array of objects. By default, the return value will include an object containing all industries and associated equity data.

data = fin_info.industry_equities("farm products")

print(data)
Output:
[
{
  'industry': 'Farm Products',
  'name': 'African Agriculture Holdings Inc.',
  'sector': 'Consumer Defensive',
  'symbol': 'AAGRW'},
{
  'industry': 'Farm Products',
  'name': 'Archer-Daniels-Midland Company',
  'sector': 'Consumer Defensive',
  'symbol': 'ADM'
},
{
  'industry': 'Farm Products',
  'name': 'Forafric Global PLC',
  'sector': 'Consumer Defensive',
  'symbol': 'AFRIW'
}
---  snip  ---
]

symbols(payload)

The `symbol` method is used to retrieve a data payload containing a list of all stock symbols available in the metadata catalog.

PAYLOAD CONTENTS:

An array of strings.

data = fin_info.symbols()

print(data)
Output:
[
'A', 
'AA', 
'AACG', 
'AACT-WT', 
'AACT', 
'AAGRW', 
'AAME', 
'AAN',
---  snip  ---
]

sector_symbols(sector, payload)

The `sector_symbols` method is used to retrieve a data payload containing a list of all stock symbols belonging to the sector passed to the `sector` parameter available in the metadata catalog.

PAYLOAD CONTENTS:

An array of strings. By default, the return value will include an object containing all sectors and associated symbols.

data = fin_info.sector_symbols("communication services")

print(data)
Output:
[
'ABLV', 
'ABLVW', 
'ADTH', 
'ADVWW', 
'ANTE', 
'BAOS', 
'BOC', 
'CCO',
---  snip  ---
]

industry_symbols(industry, payload)

The `industry_symbols` method is used to retrieve a data payload of all stock symbols belonging to the industry passed to the `industry` parameter available in the metadata catalog.

PAYLOAD CONTENTS:

An array of strings. By default, the return value will include an object containing all industries and associated symbols.

data = fin_info.industry_symbols("electronic components")

print(data)
Output:
[
'ALNT', 
'BELFA', 
'CLS', 
'CTS', 
'DAKT', 
'DSWL', 
'ELTK', 
'FLEX',
---  snip  ---  
]