class Eystd(CustomFactor):
# Pre-declare inputs and window_length
inputs = [morningstar.valuation_ratios.earning_yield]
window_length = 1260 # past five years
def compute(self, today, assets, out, ey):
eystd = np.std(ey, axis=0)
#eystd[eystd == 0] = 1
out[:] = eystd
the code sample above simply calculates the past five years standard deviation of fundamental data earning_yield in pipeline for every stock in the universe.
Real earning_yield = earning_yield - USGG 10y treasury yield is the indicator I want and since Quantopian doesn't have US treasury yield data, I use fetch_csv to get it from quandl:
fetch_csv('https://www.quandl.com/api/v3/datasets/USTREASURY/YIELD.csv?api_key=MMrssLMT_-ToHwUcxf_m',
date_column='Date',
symbol='10_Year',
pre_func = preview,
post_func=rename_col,
date_format='%Y-%m-%d')
It works very well when I just need current 10y_treasury_yield data individually.
current_yield = data.current('10_Year','10_Year_Yield')
log.info(current_yield)
My problem is how can I use it as a input data source in pipeline calculation for example: inputs = [morningstar.valuation_ratios.earning_yield] ** and we can use **inputs = [data.history('10_Year','10_Year_Yield')]. So that I can calculate the standard deviation of Real earning_yield = earning_yield - USGG 10y treasury yield and get the output in pipeline.
Is there anyone know the solution? Great thanks!