Hi Dan, first of all thank you for the reply. Basically this is the code from research enviroment i am trying to replicate in algorithm. For the fcf/p and e/p i want to compute the ratio between their mean value from 2 weeks ago to one week ago and the mean between 8 weeks ago to 2 weeks ago.
In the research i just used the resample method after select date time with run_pipeline. Even an example with just one of the 2 factors will help me to understand better the workflow.
Thanks a lot
def make_pipeline():
# Get open, close and market cap
close_price = USEquityPricing.close.latest
open_price = USEquityPricing.open.latest
market_cap = MarketCap()
# get S&P 500
QTU = QTradableStocksUS()
top_500_market_cap = market_cap.top(500)
# Create the enviroment
QTU_top_500 = QTU & top_500_market_cap
# Take only companies with closing price
has_pricing_data = close_price.notnull()
# Get the sector
morningstar_sector = Sector()
# Get factors
roe = Fundamentals.roe.latest
net_profit_margin = Fundamentals.net_income_income_statement.latest / Fundamentals.total_revenue.latest
EP_ratio = 1 / morningstar.valuation_ratios.pe_ratio.latest
fcf = Fundamentals.free_cash_flow.latest / close_price
# Return a dataframe
return Pipeline(
columns={'close_price': close_price, 'Sector_Id' : morningstar_sector,
'Roe' : roe, 'E/P' : EP_ratio, 'FCF/P' : fcf, 'open_price' : open_price,
'NPM' : net_profit_margin},
screen=QTU_top_500 & has_pricing_data
)
df = run_pipeline(make_pipeline(), '2020-3-1', '2020-4-20')