Futures with Pipeline

Hi there,

Can a pipeline be created with futures pricing and volume data in the trading algorithm? I see methods for EquityPricing and USEquityPricing.

This is working fine when I test creating the pipeline in a notebook here:

import zipline.api as algo
from zipline.pipeline import Pipeline
from zipline.pipeline.data import EquityPricing
from zipline.pipeline.data.master import SecuritiesMaster
from zipline.pipeline.factors import ExponentialWeightedMovingAverage
from zipline.pipeline.factors import ExponentialWeightedMovingStdDev
from zipline.pipeline.filters.master import Universe
from zipline.finance.commission import PerTrade, PerContract 
from zipline.finance.slippage import VolumeShareSlippage, FixedSlippage, VolatilityVolumeShare 
from zipline.finance.execution import MarketOrder
from quantrocket.realtime import collect_market_data
import numpy as np

""" 
Model Settings 
""" 
slow_ma = 80 
fast_ma = 40

def make_pipeline():
    """
    Create a pipeline that returns close and volume data.
    """
    
    # Create pipeline
    pipeline = Pipeline(
        columns={
            "close": EquityPricing.close.latest,
            "volume": EquityPricing.volume.latest,
            "slow_ma": ExponentialWeightedMovingAverage(inputs=[EquityPricing.close],window_length=slow_ma,decay_rate=1),
            "fast_ma": ExponentialWeightedMovingAverage(inputs=[EquityPricing.close],window_length=fast_ma,decay_rate=1),
            "trend": ExponentialWeightedMovingAverage(inputs=[EquityPricing.close],window_length=fast_ma,decay_rate=1) 
            \ > ExponentialWeightedMovingAverage(inputs=[EquityPricing.close],window_length=slow_ma,decay_rate=1)
        }
    )
    return pipeline

However, when I try to create the pipelinel in the trading algorithm, I get the following error:

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-24-5601f8e62487> in <module>
     11     data_frequency = 'daily',
     12     bundle = 'futures-trend-1d-bundle',
---> 13     filepath_or_buffer = 'mm_results.csv'
     14     )
     15 result = ZiplineBacktestResult.from_csv("mm_results.csv")

/opt/conda/lib/python3.7/site-packages/quantrocket/zipline.py in backtest(strategy, data_frequency, capital_base, bundle, start_date, end_date, progress, filepath_or_buffer)
    523     response = houston.post("/zipline/backtests/{0}".format(strategy), params=params, timeout=60*60*96)
    524 
--> 525     houston.raise_for_status_with_json(response)
    526 
    527     filepath_or_buffer = filepath_or_buffer or sys.stdout

/opt/conda/lib/python3.7/site-packages/quantrocket/houston.py in raise_for_status_with_json(response)
    204                 e.json_response = {}
    205                 e.args = e.args + ("please check the logs for more details",)
--> 206             raise e
    207 
    208 # Instantiate houston so that all callers can share a TCP connection (for

/opt/conda/lib/python3.7/site-packages/quantrocket/houston.py in raise_for_status_with_json(response)
    196         """
    197         try:
--> 198             response.raise_for_status()
    199         except requests.exceptions.HTTPError as e:
    200             try:

/opt/conda/lib/python3.7/site-packages/requests/models.py in raise_for_status(self)
    938 
    939         if http_error_msg:
--> 940             raise HTTPError(http_error_msg, response=self)
    941 
    942     def close(self):

HTTPError: ('500 Server Error: INTERNAL SERVER ERROR for url: http://houston/zipline/backtests/futures_trend?data_frequency=daily&capital_base=5000000&bundle=futures-trend-1d-bundle&start_date=2018-12-19&end_date=2020-06-30', {'status': 'error', 'msg': "Symbol 'CLOSE' was not found."})

When I remove the “close” column from the pipeline and re-run, the error will disappear.

Please advise.

David

Despite the name, you can use EquityPricing for futures, as you see from the notebook. It works the same in algorithms as in notebooks. It’s not possible to pinpoint the error message based on the information you provide, but it’s probably due to something you’re doing elsewhere in the algorithm. I’d suggest simplifying the algorithm as much as possible until you pinpoint the cause of the error.