Skip to main content

Stonks

(C) 2020 Mark M. Bailey, PhD

About

This is a set of tools I built to pull and analyze stock prices. Stock prices can be pulled from the World Trading Data API (www.worldtradingdata.com, key required), or they can be acquired through other means. This set of tools can also be used to generate synthetic price lists in order to test out the analytical features (or for anything else you can come up with). The "analyze()" class will generate an analysis object from the input price list, which can be analyzed using either a stochastic oscillator or a relative strength index indicator (or both). An output of "Hold", "Sell", or "Buy" signal can be extracted from the analysis based on the most recent indicator values.

Disclaimer: I do this mostly for fun (I like to code, I'm a data science nerd and I like stocks; but I'm just a math professor and not qualified to offer financial advice).

If you want to make this better, let's collaborate!

Installation

pip install stonk

Sample usage

Initial import

import stonk

Access historic stock data

Note that this requires an API key from World Trading Data (www.worldtradingdata.com).

stock = stonks.stock_API(API_KEY)
Parameters:

  • API_KEY = World Trading Data API Key (str).

daily_price_dictionary = stock.daily(TKR, time_delta, beta=True, EX='^IXIC')
Parameters:

  • TKR = Ticker symbol (str).
  • time_delta = Specifies the number of days into the past (from today) to pull historic closing prices (int).
  • beta = Boolean to include beta calculation in output dictionary (default=True).
  • EX = Exchange on which to base beta calculation (default = '^IXIC')
  • output = dictionary

intraday_price_dictionary = intraday(TKR, range_=1, interval=60, beta=True, EX='^IXIC')
Parameters:

  • TKR = Ticker symbol (str).
  • range_ = Specifies the number of days you want to return data for (int or str).
  • interval = Specifies the interval (in minutes) of time between the data (int or str).
  • interval = Boolean to include beta calculation in output dictionary (default=True).
  • EX = Exchange on which to base beta calculation (default = '^IXIC')
  • output = dictionary

Generate synthetic stock price data

If you don't have API access or other real stock data and want to mess around with simulations, this class will generate synthetic price data (either bullish random price or oscillating random price). Note that these generators are imperfect and will sometimes generate negative prices (if you'd like to contribute to this project and make this function better, please feel free!).

synthetic_price_generator = stonks.syn_stock()
synthetic_prices = synthetic_price_generator.oscillator(n, scale=1)
synthetic_prices = synthetic_price_generator.bullish_random(n, scale=1)
Parameters:

  • n = Number of prices to simulate.
  • scale = Standard deviation (spread or “width”) of the distribution. Must be non-negative.

Calculate momentum indicators

This class will calculate either a stochastic oscillator or relative strength index indicator for a list of stock prices. Sell or buy signals are also generated.

stock = analyze(input_, closing_prices='closing_prices')
Parameters:

  • input_ = Price list or dictionary (generated from daily_price_dictionary).
  • closing_prices = Key for prices dictionary (default is 'closing_prices').

stock_object = stock.stochastic_oscillator(n, c=3)
output = stock_object.stochastic_output
signal = stock_object.stochastic_assessment
Parameters:

  • n = Period size (int).
  • c = Moving average size (default is 3).
  • output = JSON output (Within the 'assessment' list, a value of -1 means the stock is oversold, and 1 indicates that it is overbought. A value of 0 means neither).
  • signal = Buy, Sell, or Hold signal based on most recent stochastic output.

stock_object = stock.RSI(n)
output = stock_object.RSI_output
signal = stock_object.RSI_assessment
Parameters:

  • n = Period size (int).
  • output = JSON output (Within the 'assessment' list, a value of -1 means the stock is oversold, and 1 indicates that it is overbought. A value of 0 means neither).
  • signal = Buy, Sell, or Hold signal based on most recent stochastic output.

Metadata

Release files for stonk 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stonk 0.0.1
File Size Uploaded
stonk-0.0.1.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stonk 0.0.1
File Interpreter ABI Platform
stonk-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / stonk-0.0.1.tar.gz

Download URL stonk-0.0.1.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2ab3adf9ecb74637560e8da5added880f07f22bc646ef86e273e8271870907de
BLAKE2b-256 checksum
How to use checksums
a2b5dd0b89f5e4a961ab096a6cdabdbd78d9413135a555cc3437a8853d338370
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / stonk-0.0.1-py3-none-any.whl

Download URL stonk-0.0.1-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
138107d22acf570009be7f40658524ee3a660180919a0bd50f6f2b781a3652b9
BLAKE2b-256 checksum
How to use checksums
f66949aca0c50c19fd404831dacb006dde5836b18bd08e1ccb02dd3a37df4771
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page