Skip to content

Instantly share code, notes, and snippets.

@qharlie
Last active May 14, 2019 00:29
Show Gist options
  • Save qharlie/3803dc7532513d3657635a0a46ac471c to your computer and use it in GitHub Desktop.
Save qharlie/3803dc7532513d3657635a0a46ac471c to your computer and use it in GitHub Desktop.
import backtrader as bt
import util.data as btu
import os
def run_stock_scanner(tickers, _from, _to, analyzers):
cerebro = bt.Cerebro()
for ticker in tickers:
DataFactory = btu.get_store().getdata
data = DataFactory(
dataname=ticker,
timeframe=bt.TimeFrame.TFrame("Days"),
fromdate=pd.Timestamp(_from),
todate=pd.Timestamp(_to),
historical=True)
cerebro.adddata(data)
for a in analyzers:
cerebro.addanalyzer(a,_name=str(a.__name__))
ret = cerebro.run(runonce=False, stdstats=True, writer=True)
return ret
# from scanner import run_stock_scanner, KitchenSinkAnalyzer
#
# tickers = btu.us_tickers()
#
# res = run_stock_scanner(tickers,
# '2019-04-10',
# '2019-05-10',
# [KitchenSinkAnalyzer])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment