All Projects → portfolioplus → pystockfilter

portfolioplus / pystockfilter

Licence: MIT license
Financial technical and fundamental analysis indicator library for pystockdb.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pystockfilter

Qlib Server
Qlib-Server is the data server system for Qlib. It enable Qlib to run in online mode. Under online mode, the data will be deployed as a shared data service. The data and their cache will be shared by all the clients. The data retrieval performance is expected to be improved due to a higher rate of cache hits. It will consume less disk space, too.
Stars: ✭ 81 (+211.54%)
Mutual labels:  finance, stock, quant
akshare
AKShare is an elegant and simple financial data interface library for Python, built for human beings! 开源财经数据接口库
Stars: ✭ 5,155 (+19726.92%)
Mutual labels:  finance, stock, quant
Akshare
AKShare is an elegant and simple financial data interface library for Python, built for human beings! 开源财经数据接口库
Stars: ✭ 4,334 (+16569.23%)
Mutual labels:  finance, stock, quant
Beibo
🤖 Predict the stock market with AI 用AI预测股票市场
Stars: ✭ 46 (+76.92%)
Mutual labels:  finance, stock, quant
Rqalpha
A extendable, replaceable Python algorithmic backtest && trading framework supporting multiple securities
Stars: ✭ 4,425 (+16919.23%)
Mutual labels:  finance, stock, quant
Py Market Profile
A library to calculate Market Profile (aka Volume Profile) for financial data from a Pandas DataFrame.
Stars: ✭ 153 (+488.46%)
Mutual labels:  finance, quant
Alpha Mind
quantitative security portfolio analysis. The analysis pipeline including data storage abstraction, alpha calculation, ML based alpha combining and portfolio calculation.
Stars: ✭ 171 (+557.69%)
Mutual labels:  finance, stock
wallstreet
Stock Quotes and Charts for the Terminal
Stars: ✭ 75 (+188.46%)
Mutual labels:  finance, stock
Finance Python
python tools for Finance with the functionality of indicator calculation, business day calculation and so on.
Stars: ✭ 238 (+815.38%)
Mutual labels:  finance, stock
Awesome Quant
中国的Quant相关资源索引
Stars: ✭ 2,529 (+9626.92%)
Mutual labels:  finance, quant
Trading Backtest
A stock backtesting engine written in modern Java. And a pairs trading (cointegration) strategy implementation using a bayesian kalman filter model
Stars: ✭ 247 (+850%)
Mutual labels:  finance, stock
Turingtrader
The Open-Source Backtesting Engine/ Market Simulator by Bertram Solutions.
Stars: ✭ 132 (+407.69%)
Mutual labels:  finance, quant
Finance
프로그래머가 투자하는 법
Stars: ✭ 121 (+365.38%)
Mutual labels:  finance, stock
Quant Notes
Quantitative Interview Preparation Guide, updated version here ==>
Stars: ✭ 180 (+592.31%)
Mutual labels:  finance, quant
Yahoofinanceapi
A handy Yahoo! Finance api wrapper, based on .NET Standard 2.0
Stars: ✭ 99 (+280.77%)
Mutual labels:  finance, stock
Vnpy
基于Python的开源量化交易平台开发框架
Stars: ✭ 17,054 (+65492.31%)
Mutual labels:  finance, quant
mooquant
MooQuant 是一个基于 pyalgotrade 衍生而来的支持 python3 的支持国内A股的量化交易框架。
Stars: ✭ 24 (-7.69%)
Mutual labels:  stock, quant
backend-ctp
CTP接口封装,使用redis做消息中转
Stars: ✭ 26 (+0%)
Mutual labels:  stock, quant
pandas-datareader-gdax
GDAX data for Pandas in the style of DataReader
Stars: ✭ 11 (-57.69%)
Mutual labels:  finance, quant
DeltaTrader
极简版Python量化交易工具
Stars: ✭ 174 (+569.23%)
Mutual labels:  finance, quant

pystockfilter

Release Build CI Build PyPI - Downloads Coverage Status Codacy Badge

Create your own fundamental or chart based stock filter. All you need is a database set up with pystockdb.

built-in filters

technical filters

  • ADX
  • RSI
  • StockIsHot: Simple trend indicator
  • StockIsHotSecure: improved StockIsHot version.

fundamental filters

  • Lervermann
  • Piotroski F-Score
  • Price Target Score: analysts price targets compared with actual price

install

pip install pystockfilter

quick start

Build internal filters:

import logging
from pystockdb.db.schema.stocks import db

from pystockfilter.tool.build_internal_filters import BuildInternalFilters

# connect to database
arguments = {'db_args': {
    'provider': 'sqlite',
    'filename': db_path_test,
    'create_db': False
    }
}
db.bind(**arguments["db_args"])
db.generate_mapping()
# create internal filters for Adidas AG and Infineon
arguments = {'symbols': ['ADS.F', 'IFX.F']}
builder = BuildInternalFilters(arguments, logger)
builder.build()
# create internal filters for all stocks in database
arguments = {'symbols': ['ALL']}
builder = BuildInternalFilters(arguments, logger)
builder.build()

Build custom filters:

import logging
import math
from datetime import datetime

import numpy as np
import tulipy as ti
import yfinance as yf
from dateutil.relativedelta import relativedelta
from pony.orm import db_session, select
from pystockdb.db.schema.stocks import Price, Tag
from pystockfilter.filter.base_filter import BaseFilter
from pystockfilter.base.base_helper import BaseHelper
from pystockfilter.tool.build_filters import BuildFilters

# custom filter 
class DividendKings(BaseFilter):
    """
    Calculates median of last dividends
    """

    NAME = 'DividendKings'

    def __init__(self, arguments: dict, logger: logging.Logger):
        self.buy = arguments['args']['threshold_buy']
        self.sell = arguments['args']['threshold_sell']
        self.lookback = arguments['args']['lookback']
        self.max_yield = arguments['args']['max_div_yield']
        super(DividendKings, self).__init__(arguments, logger)

    @db_session
    def analyse(self):
        symbol = select(sym.name for sym in self.stock.price_item.symbols
                        if Tag.YAO in sym.item.tags.name).first()
        try:
            yao_item = yf.Ticker(symbol)
            data = yao_item.dividends
        except ValueError:
            raise RuntimeError("Couldn't load dividends for {}".format(symbol))

        dates = data.index.array
        drop = []
        # let us calculate the dividend yield
        for my_date in dates:
            price = Price.select(
                    lambda p: p.symbol.name == symbol
                    and p.date.date() == my_date.date()
                ).first()
            if price:
                div_yield = (data[my_date] / price.close) * 100
                if div_yield > self.max_yield:
                    drop.append(my_date)
                    self.logger.error(
                        '{} has a non plausible div yield at {} ({} = {} / {} * 100).'
                        .format(symbol, my_date, div_yield, data[my_date], price.close)
                    )
                else:
                    data[my_date] = div_yield
            else:
                drop.append(my_date)
        data = data.drop(labels=drop)
        self.calc = data.median(axis=0)
        if self.calc is None or math.isnan(self.calc):
            raise RuntimeError("Couldn't calculate dividend yield.")
        return super(DividendKings, self).analyse()

    def get_calculation(self):
        return self.calc

    def look_back_date(self):
        return self.now_date + relativedelta(months=-self.lookback)

logger = BaseHelper.setup_logger("custom filter")

arguments_div = {
    "name": "DividendKings",
    "bars": False,
    "index_bars": False,
    "args": {
        "threshold_buy": 3,
        "threshold_sell": 0.2,
        "intervals": None,
        "max_div_yield": 9,
        "lookback": 2,
    },
}

symbols = ["ADS.F", "WDI.F", "BAYN.F"]

config_custom_filter = {
    "symbols": symbols,
    "filters": [DividendKings(arguments_div, logger)],
}

custom = BuildFilters(config_custom_filter, logger)
custom.build()

issue tracker

https://github.com/portfolioplus/pystockfilter/issuese

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].