Figured out how to sort through the entire universe and get the previous day close for every stock.
This code isn't perfect and it sorts through the stock alphabetically but it does what it's supposed to do. :D
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import SimpleMovingAverage
from quantopian.pipeline import CustomFactor
import numpy as np
import pandas as pd
import datetime
class PriceRange(CustomFactor):
# define inputs for the compute method
inputs = [USEquityPricing.close]
def compute(self, today, assets, out, close):
out[:] = close[-1]
def initialize(context):
stock_prices = PriceRange(window_length=10)
#attaches a name to the pipeline
pipe = attach_pipeline(Pipeline(), name = 'pipeline')
# adds the stock_prices variable to the stock_prices pipeline
pipe.add(stock_prices, 'pipeline')
def before_trading_start(context, data):
# Access results using the name passed to `attach_pipeline`.
results = pipeline_output('pipeline')
print results.head(30)
# Define a universe with the results of a Pipeline.
update_universe(results.sort('pipeline').index[:10])
def handle_data(context, data):
# placeholder variable
variable = int