def test_engine(refdata, stocks, data_path): def list_symbols(): return ['A', 'AA'] mock_iex.get_available_symbols(refdata) mock_iex.get_key_stats(stocks) mock_iex.get_chart(stocks) eng = LivePipelineEngine(list_symbols) ADV = AverageDollarVolume(window_length=20, ) top5 = ADV.top(5, groupby=Sector()) pipe = Pipeline({ 'top5': top5, 'close': USEquityPricing.close.latest, }, screen=top5) df = eng.run_pipeline(pipe) assert sorted(df.columns) == ['close', 'top5'] pipe = Pipeline({ 'close': USEquityPricing.close.latest, }) df = eng.run_pipeline(pipe) assert df.shape == (2, 1) assert df.close['AA'] > 40
def pipeline_output(self, name): try: from pipeline_live.engine import LivePipelineEngine except ImportError: raise RuntimeError('pipeline-live is not installed') finder = self.asset_finder def list_symbols(): return sorted([a.symbol for a in finder._asset_cache.values()]) eng = LivePipelineEngine(list_symbols) output = eng.run_pipeline(self._pipelines[name]) output.index = pd.Index(finder.lookup_symbols(output.index)) return output
def initialize (context): # runs once when script starts log.info("Welcome Vincent Perkins") #context is a python dictionary that contains information on portfolio/performance. context.idr_losers = pd.Series(([])) #intraday losing stocks context.day_count = 0 context.daily_message = "Day {}." context.open_orders = get_open_orders() context.backup_stocks = symbols('BAM') context.age = {} #empty dictionary maps one value to another #context.usep = USEquityPricing() #USEquityPricing object #Factor criteria close_price = USEquityPricing.close.latest vol = USEquityPricing.volume.latest ann_var = AnnualizedVolatility() rsi = RSI() #screening mask_custom = (IsPrimaryShare() & (vol < 150000) & (close_price > 1) & (close_price < 3) & (ann_var > 0.815) & (rsi < 50)) stockBasket = USEquityPricing.close.latest.top(3000, mask = mask_custom) #Column construction pipe_columns = {'close_price': close_price, 'volume': vol, 'ann_var': ann_var} #Creation of actual pipeline pipe = Pipeline(columns = pipe_columns, screen = stockBasket) attach_pipeline(pipe, 'Stocks') #Testing log.info(USEquityPricing.get_loader()) eng = LivePipelineEngine(list_symbols) df = eng.run_pipeline(pipe) log.info(df) #Schedule functions schedule_function(day_start, date_rules.every_day(), time_rules.market_open(hours = 0, minutes = 1)) schedule_function(late_day_trade, date_rules.every_day(), time_rules.market_open(hours = 5, minutes = 56)) #offset open tells when to run a user defined function schedule_function(check_portfolio, date_rules.every_day(), time_rules.market_open(hours = 0, minutes = 1)) schedule_function(morning_day_trade1, date_rules.every_day(), time_rules.market_open(hours = 0, minutes = 15)) schedule_function(morning_day_trade2, date_rules.every_day(), time_rules.market_open(hours = 0, minutes = 45)) schedule_function(check_portfolio, date_rules.every_day(), time_rules.market_open(hours = 0, minutes = 48)) schedule_function(cancel_open_orders, date_rules.every_day(),time_rules.market_close(hours=0, minutes=1))
from pipeline_live.engine import LivePipelineEngine from pipeline_live.data.sources.iex import list_symbols from pipeline_live.data.alpaca.pricing import USEquityPricing from pipeline_live.data.alpaca.factors import AverageDollarVolume from pipeline_live.data.polygon.fundamentals import PolygonCompany from zipline.pipeline import Pipeline from dotenv import load_dotenv load_dotenv() engine = LivePipelineEngine(list_symbols) top5 = AverageDollarVolume(window_length=20).top(5) pipe = Pipeline( { "close": USEquityPricing.close.latest, "marketcap": PolygonCompany.marketcap.latest, }, screen=top5, ) result = engine.run_pipeline(pipe) print(result)
from pipeline_live.engine import LivePipelineEngine from pipeline_live.data.alpaca.pricing import USEquityPricing from pipeline_live.data.alpaca.factors import AverageDollarVolume from pipeline_live.data.sources.polygon import list_symbols from zipline.pipeline import Pipeline from src.ziplineStrategies.Filters.CurVsAvgVolFilter import curVsAvgVolFilter # from src.ziplineStrategies.Filters.CompanySizeFilter import isMidToLargeCap from pipeline_live.data.iex.factors import SimpleMovingAverage from pylivetrader.api import (symbol, pipeline_output, order_target_percent) import logging ENGINE = LivePipelineEngine(list_symbols) def initialize(context): context.params = { 'lookback': 20, 'smaSlowLookback': 30, 'smaFastLookback': 10 } context.position_size = .1 context.stopLevel = .9 context.leverageLimit = 1.5 context.stopPriceMap = {} def make_pipeline(context): advFilter = curVsAvgVolFilter(context.params.get('lookback')) # midToLargeFilter = isMidToLargeCap(context.params.get('lookback')) smaSlow = SimpleMovingAverage(