I'm not sure what your 'make_pipeline' function does, however, all you really need is:
- Define a pipeline by specifying the columns in the output dataframe and, optionally, any filter you want to apply to the output.
- Attach a pipeline to the algorithm using the 'attach_pipeline' method.
- Get the resulting output from the pipeline by calling the 'pipeline_output'. Typically done every day in the built in 'before_trading_start' function.
1 and 2 would go in the 'initialize' function because they happen only once. Note that defining the pipeline is often placed into a separate function just to make it easier to read, and then called inside of the 'initialize' function. That's what your user defined function 'make_pipeline' does, but this isn't required.
# Create any factors you want to use (in this case macd). Just ensure they are imported first.
macd = MACD(fast_period = 2, slow_period = 400, signal_period = 3)
# Create any filters you want to use.
macd_low_filter = macd < 0
# Now create a pipeline and add all the factors and filters you want. These become the columns in the
# dataframe that the pipeline output returns
pipe = Pipeline(
columns = {
'macd' : macd,},
screen = macd_low_filter
)
# Finally 'attach' the pipeline to the algorithm
attach_pipeline(pipe, name='my_pipe')
Then get the output of the pipe(typically within the 'before_trading_start' function)
context.output = pipeline_output('my_pipe')
The 'context.output' object is a pandas dataframe. The rows are indexed with the security object. The columns are the factors (or potentially filters and classifiers) set up in the pipeline definition.
'context.assets_to_trade' isn't any sort of built in variable. One would need to assign that to something to use it. In the example above the variable 'context.output' is an arbitrary user defined variable that refers to the dataframe returned by the pipeline.