Skip to main content

A Python framework for building stock scanners/screeners.

Project description

Stock-scanner

Stock-scanner is a Python3 package aimed at facilitating the rapid development of custom stock scanners/screeners. The goal is for it to be a sort of framework which easily lets users swap different modules at their own discretion.

Example code

Using a pre-written Condition:

from stock_screener import Stock
from stock_screener.scanner import BasicScanner
from stock_screener.condition.Above150And200SMA import Above150And200SMA
from stock_screener.data_fetcher import YahooDataFetcher

universe = 'nasdaq'
path = f'./{universe}'

print("Looking for stocks above the 150 and 200 day SMA.")

data_fetcher = YahooDataFetcher(universe, path)
conditions = [ Above150And200SMA ]

candidates = (
            BasicScanner(conditions, data_fetcher)
                .loadData()
                .getCandidates()
)

print(list(map(lambda x: x.getTicker(), candidates)))

Writing a custom Condition:

from stock_screener import Stock
from stock_screener.condition import Condition
from stock_screener.scanner.BasicScanner import BasicScanner
from stock_screener.data_fetcher.YahooDataFetcher import YahooDataFetcher

universe = 'nasdaq'
path = f'./{universe}'

# Has the stock consolidated?
class Consolidating(Condition):
    def __init__(self, stock: Stock) -> None:
        """
        Always call super in the constructor.
        """
        super().__init__(stock)

        # We will look from the last close to 10 days back
        window = 10
        try:
            # Find the max and min closes in this window
            self.max_close = stock.getClose()[-window:].max()
            self.min_close = stock.getClose()[-window:].min()
        except IndexError:
            return False

    def fulfilled(self) -> bool:
        """
        If the difference between them is less than 3%
        we consider the stock consolidated
        """
        return self.min_close > (self.max_close * 0.97)

print("Looking for consolidated stocks.")

data_fetcher = YahooDataFetcher(universe, path)
conditions = [ Above150And200SMA, Consolidating ]
candidates = (
            BasicScanner(conditions, data_fetcher)
                .loadData()
                .getCandidates()
)

print(list(map(lambda x: x.getTicker(), candidates)))

Interfaces

To achieve this goal of modularity, the framework has a few different interfaces you need to implement when writing your own extensions. They are:

  • DataFetcher - an interface for downloading stock data and saving it locally.
  • DataReader - an interface for reading stock data files.
  • Condition - an interface for checking whether a stock fulfills a condition.
  • Validator - an interface for deciding whether a stock should be returned as a candidate from the scan or not, given the conditions it fulfills.
  • Scanner - an interface for the "main engine" of the scan.

A general outline of the use of these interfaces could look as such:

  1. Use a DataFetcher to download stock data.
  2. Use a DataReader to load the stock data into memory.
  3. Give a Validator a set of Conditions to see if the stock should be returned from the scan or not.

This process usually all takes place in a Scanner.

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

stock-scanner-0.0.14.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

stock_scanner-0.0.14-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file stock-scanner-0.0.14.tar.gz.

File metadata

  • Download URL: stock-scanner-0.0.14.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.6.9

File hashes

Hashes for stock-scanner-0.0.14.tar.gz
Algorithm Hash digest
SHA256 3dfb0ef3535f4f4e986bc790e18235128e9f7655496cffe277216855d1300419
MD5 b6af7ff1cb85f737473e1ecc71a8dfee
BLAKE2b-256 26999a26bac105d44fd5645d7669ed40128e8783fb26bdf8dd84832ddc191695

See more details on using hashes here.

File details

Details for the file stock_scanner-0.0.14-py3-none-any.whl.

File metadata

  • Download URL: stock_scanner-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.6.9

File hashes

Hashes for stock_scanner-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 fbdbcdb8cd5fc4ede8052cfeca73cfd73df122085dd271409d6b6b03308e37b1
MD5 ec7c7d1d53028dce155d5565a0c776a4
BLAKE2b-256 b61ba339b50538a8bc9f9f289cc110c9f52767a1a2d151a918e1057101d62430

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