Skip to content
All library documents

Open Source Tools for Technical Stock Screening

Article Quant Q&A · Author: Eka

Summary

The document discusses ways to screen stocks using technical rules, such as comparing closing prices with a moving average. It points to R’s quantmod package for retrieving market data, charting, and applying indicators. It also describes a Python approach using backtrader: an analyzer can compare each asset’s latest close with its moving average and report which assets are above or below it.

The examples illustrate that screening can be built into a trading platform or performed on locally stored data with a technical analysis library or custom code. The post also mentions other Python platforms and data sources, but gives no systematic comparison of their capabilities, reliability, costs, or current data access. Its sample output is a single historical run, not evidence that the screening rule predicts returns. Data availability and provider support may change over time.

Key ideas

  • A stock screener can apply technical rules across a list of assets.
  • The R quantmod package is presented as an option for retrieving data, charting, and filtering by indicators.
  • A backtrader analyzer can classify assets according to whether their closes are above a moving average.
  • Screening can also be done locally with a technical analysis library or custom Python code.
  • The examples show implementation approaches, not evidence of trading profitability.

Tags

Full text
# Open source software for stock screening and scanning using technical analysis?


# Open source software for stock screening and scanning using technical analysis?












I am looking for open source software which can download stock data (yahoo/google finance etc) and used for screening/scanning stocks using technical analysis, for example:

- return stock list if close price is greater than 10 period moving average, or

- return stock list if upper bolinger band is greater than stock close price etc

Can anyone suggest similar open source software?

## Answer by vonjd (score 6, accepted)

https://quant.stackexchange.com/a/27572

I think the most sophisticated solutions are to be found within the R universe.

One package that comes to mind is the `quantmod package`. You can use it to download data from Yahoo and Google finance, plot charts and filter your stocks using all kinds of technical indicators (that come with the package).

It can be found on CRAN: https://cran.r-project.org/web/packages/quantmod/index.html

To get you started: http://www.quantmod.com/examples/

A gallery of some of the technical indicators: http://www.quantmod.com/gallery/

The full documentation (100 p.) can be found here: https://cran.r-project.org/web/packages/quantmod/quantmod.pdf

## Answer by mementum (score 5)

https://quant.stackexchange.com/a/29653

Being the question tagged as `python` and given I look for small challenges for my platform, `backtrader`, I took the chance to see how easy would be to do this with the platform.

Documented at: http://www.backtrader.com/posts/2016-08-15-stock-screening/stock-screening/

The core code in this case is an analyzer which looks for assets which are above the 10-days moving average (example from the OP). The analyzer code:

```
class Screener_SMA(bt.Analyzer):
    params = dict(period=10)

    def start(self):
        self.smas = {data: bt.indicators.SMA(data, period=self.p.period)
                     for data in self.datas}

    def stop(self):
        self.rets['over'] = list()
        self.rets['under'] = list()

        for data, sma in self.smas.items():
            node = data._name, data.close[0], sma[0]
            if data > sma:  # if data.close[0] > sma[0]
                self.rets['over'].append(node)
            else:
                self.rets['under'].append(node)
```

It can be used directly with the built-in executable `btrun` (created by `setup.py` / `pip`) or managed with a hand-crafted script. A sample execution with `btrun`:

```
btrun --format yahoo --data YHOO --data IBM --data NVDA --data TSLA --data ORCL --data AAPL --fromdate 2016-07-15 --todate 2016-08-13 --analyzer st-screener:Screener_SMA --cerebro runonce=0 --writer --nostdstats
```

Yes: the prices are being directly downloaded from Yahoo with `--format yahoo`.

Which earlier today (before the market closed again today) delivered:

```
- Analysis:
  - over: ('ORCL', 41.09, 41.032), ('IBM', 161.95, 161.221), ('YHOO', 42.94, 39.629000000000005), ('AAPL', 108.18, 106.926), ('NVDA', 63.04, 58.327)
  - under: ('TSLA', 224.91, 228.423)
```

I am sure that the same can be done with other python platforms like `pyAlgoTrade`, `zipline`, etc. A list of known (to me) python open source platforms can be found in the README of `backtrader` on the front page of the repository: https://github.com/mementum/backtrader

Disclaimer: if not obvious, I am the author of `backtrader`

## Answer by babelproofreader (score 2)

https://quant.stackexchange.com/a/27568

I would recommend using Python because it can be downloaded for Windows or Mac and is available in almost all Linux repositories as standard.

Once you have Python installed you can use any of the following links to see how to get your data

https://www.quantstart.com/articles/Downloading-Historical-Intraday-US-Equities-From-DTN-IQFeed-with-Python

https://stackoverflow.com/questions/12433076/download-history-stock-prices-automatically-from-yahoo-finance-in-python

https://github.com/leonth/bulk-download-quandl

https://pypi.python.org/pypi/googlefinance

https://code.activestate.com/recipes/511444-stock-prices-historical-data-bulk-download-from-in/

and of course once you have your data you can screen it in situ on your pc however you want by, for example, using a technical analysis library such as TA Lib and/or writing your own custom screener in Python. An example of the latter can be seen at

https://www.youtube.com/watch?v=Y4GHgJjIQnk

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.