A set of tools to pull and analyze stock data.
Project description
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.
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 Distribution
Built Distribution
File details
Details for the file stonk-0.0.1.tar.gz
.
File metadata
- Download URL: stonk-0.0.1.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ab3adf9ecb74637560e8da5added880f07f22bc646ef86e273e8271870907de |
|
MD5 | 5283ad7fa05226be8adf5b20f3535a89 |
|
BLAKE2b-256 | a2b5dd0b89f5e4a961ab096a6cdabdbd78d9413135a555cc3437a8853d338370 |
File details
Details for the file stonk-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: stonk-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 138107d22acf570009be7f40658524ee3a660180919a0bd50f6f2b781a3652b9 |
|
MD5 | 69b6de6e8d625ab95d1e68023a586502 |
|
BLAKE2b-256 | f66949aca0c50c19fd404831dacb006dde5836b18bd08e1ccb02dd3a37df4771 |