A Python framework for building stock scanners/screeners.
Project description
stock-scanner
Rapidly develop your own stock scanners using this Python3 library.
- Built-in support for using the free Yahoo Finance API.
- Easily write your own conditions for deciding whether a stock should show up in your scan.
- Extensible and easily customizable - simply write your own implementations of the included interfaces.
Example code
Using a pre-written example Condition:
from src.stock_scanner.condition.Consolidating import Consolidating
from src.stock_scanner.scanner.BasicScanner import BasicScanner
from src.stock_scanner.stock_io import YahooIO
path = f'./{YahooIO.valid_universes.NASDAQ.value}'
print("Looking for consolidated stocks.")
stock_io = YahooIO(YahooIO.valid_universes.NASDAQ, path, max_tickers=50)
conditions = [Consolidating(window=10, max_difference_percentage=2)]
candidates = BasicScanner(conditions, stock_io).load_data().get_candidates()
print(list(map(lambda x: x.get_ticker(), candidates)))
Core interfaces
The main goal of this library is to enable rapid stock scanner development and creation of modules that you simply swap in or out at will. To achieve this, there is a number of different interfaces (or more technically correct in Python, abstract classes):
- StockIOInterface - an interface for downloading stock data to disk and then reading it.
- ConditionInterface - an interface for checking whether a stock fulfills a condition. This is the interface you probably will be doing the most work with on your own, as it's the most crucial one when building a scanner.
- ValidatorInterface - an interface for deciding whether a stock should be returned as a candidate from the scan or not, given the conditions it fulfills.
- ScannerInterface - an interface for the "main engine" of the scan.
- StockInterface - an interface for interacting with the data of a stock.
Basic use guidelines
- Construct a StockIO instance.
- Make a list of Condition instances.
- Instantiate a Validator.
- Pass these as arguments to a Scanner.
When using the included, basic implementations of some of these interfaces, the process is slightly simplified:
- Construct a StockIO instance (for example, YahooIO)
- Make a list of Condition instances.
- Pass these as arguments to BasicScanner.
Existing implementations of the interfaces
- YahooIO - fetches daily data from the open and free Yahoo Finance API. Works pretty well for many use cases, but there is a rate limit.
- BasicValidator - it looks at a stock and returns it as a candidate if it fulfills all given Conditions, otherwise not.
- BasicScanner - it runs the StockIO to download stock data, reads the data for each stock, and by default uses the BasicValidator to find candidates. It should suffice for most use cases where you look at a stock in isolation -- but if you want to make use of a Relative Strength Index, for instance, you may need to write your own logic in a custom implementation.
Experimental
Currently, I'm working on a backtesting module to facilitate the analysis of the quality of a scanner. What if you could see the Win/Loss ratio of candidates in a scanner, the average return? Not yet done.
Moreover, there are some basic functions to export Stocks and their time series to interactive HTML/CSS/JS charts, PNG files, or writing a list of candidate tickers to a text file.
Project details
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 thumos-stock-screener-0.1.6.tar.gz
.
File metadata
- Download URL: thumos-stock-screener-0.1.6.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3831a98b9453f36442901f325bb043db79ac4cfcb44dcb3286b4d5f9383d90d9 |
|
MD5 | f4586eee24402acdeffa9b2b62619dac |
|
BLAKE2b-256 | 45e6e90acf6a20d15056b489970a26e7708fb91776e34d9239accd3c27f9b405 |
File details
Details for the file thumos_stock_screener-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: thumos_stock_screener-0.1.6-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccc3804f751181c2ae1cf2de6dd3070a2ad7f1f25e341168568a7d7f3989bd48 |
|
MD5 | 0ffde14578534af929d3f1fbc8cd4862 |
|
BLAKE2b-256 | 5461eac07173df0f41d1683d8dc17a8e88ad929ae0c0fa552eefdf435974567d |