def StocksUS():
    return ((USEquityPricing.close.latest > 3)
            & Exchange().element_of(['NYSE', 'NASDAQ', 'NYSEMKT']) &
            (Sector().notnull()) & (~Sector().element_of(
                ['Financial Services', 'Real Estate', 'Energy', 'Utilities']))
            & (IsDomesticCommonStock().eq(1)) &
            (Fundamentals(field='revenue_arq') > 0) &
            (Fundamentals(field='assets_arq') > 0) &
            (Fundamentals(field='equity_arq') > 0) & (EV() > 0))
class EarningYield(CustomFactor):
    inputs = [Fundamentals(field='netinccmnusd_art'), MarketCap()]
    window_safe = True
    window_length = 1

    def compute(self, today, assets, out, earnings, mkt_cap):
        l = self.window_length
        out[:] = earnings[-l] / mkt_cap[-l]
示例#3
0
class SalesYieldEV(CustomFactor):
    inputs = [
        Fundamentals(field='revenueusd_arq'),
        EV(),
        InterestRate(),
        InflationRate()
    ]
    window_safe = True
    window_length = 1

    def compute(self, today, assets, out, sales, ev, rateint, rateinf):
        l = self.window_length
        cf_yield_ev = sales[-l] / ev[-l]
        out[:] = adjust_for_inflation(cf_yield_ev, l, rateint, rateinf)
示例#4
0
class EarningYieldEV(CustomFactor):
    inputs = [
        Fundamentals(field='netinccmnusd_arq'),
        EV(),
        InterestRate(),
        InflationRate()
    ]
    window_safe = True
    window_length = 1

    def compute(self, today, assets, out, earning, ev, rateint, rateinf):
        l = self.window_length
        earning_yield_ev = earning[-l] / ev[-l]
        out[:] = adjust_for_inflation(earning_yield_ev, l, rateint, rateinf)
示例#5
0
class CashFlowYieldEV(CustomFactor):
    inputs = [
        Fundamentals(field='ncfo_arq'),
        EV(),
        InterestRate(),
        InflationRate()
    ]
    window_safe = True
    window_length = 1

    def compute(self, today, assets, out, cf, ev, rateint, rateinf):
        l = self.window_length
        cf_yield_ev = cf[-l] / ev[-l]
        out[:] = adjust_for_inflation(cf_yield_ev, l, rateint, rateinf)
示例#6
0
class BookValueYieldEV(CustomFactor):
    inputs = [
        Fundamentals(field='equityusd_arq'),
        EV(),
        InterestRate(),
        InflationRate()
    ]
    window_safe = True
    window_length = 1

    def compute(self, today, assets, out, bv, ev, rateint, rateinf):
        l = self.window_length
        bv_yield_ev = bv[-l] / ev[-l]
        out[:] = adjust_for_inflation(bv_yield_ev, l, rateint, rateinf)
def make_pipeline():
    rsi = RSI()
    return Pipeline(
        columns={
            'longs': rsi.top(3),
            'shorts': rsi.bottom(3),
            'revenue': Fundamentals(field='revenue_art'),
        },
        # no screen: 1 mo -> ca. 4 minutes;
        #            1 yr -> 20m

        # base_universe: ca. 1 mo. -> 3 minutes
        #screen = base_universe()

        # tradable_stocks(): 1 mo. -> ca 1h
        # 1yr -< 1h 40m
        #screen = TradableStocksUS()

        # NamedUniverse('tradable_stocks_us'): 1yr 7m
        screen=NamedUniverse('tradable_stocks_us'))
def base_universe():
    #return TradableStocksUS()
    return ((Fundamentals(field='revenue_art') > 0) &
            (Fundamentals(field='assets_arq') > 0) &
            (Fundamentals(field='equity_arq') > 0) & (EV() > 0))
screen = StaticAssets(symbols(['IBM', 'F', 'AAPL']))
)

stocks = spe.run_pipeline(pipe, pipe_start, pipe_end)
print("stocks.shape [close]", stocks)

from sharadar.pipeline.factors import MarketCap, EV, Fundamentals
pipe_mkt_cap = Pipeline(columns={
    'mkt_cap': MarketCap()
},
)

start_time = time.time()
stocks = spe.run_pipeline(pipe_mkt_cap, pipe_start, pipe_end)
print("stocks.shape [mkt cap]", stocks.shape)
print("--- %s ---" % datetime.timedelta(seconds=(time.time() - start_time)))

pipe_mkt_cap_ev = Pipeline(columns={
    'mkt_cap': MarketCap(),
    'ev': EV(),
    'debt': Fundamentals(field='debtusd_arq'),
    'cash': Fundamentals(field='cashnequsd_arq')
},
screen = StaticAssets(symbols(['IBM', 'F', 'AAPL']))
)

stocks = spe.run_pipeline(pipe_mkt_cap_ev, pipe_start, pipe_end)
print(stocks)


    window_safe = True
    window_length = 1

    def compute(self, today, assets, out, earnings, mkt_cap):
        l = self.window_length
        out[:] = earnings[-l] / mkt_cap[-l]


month_length = 21
monthly = tuple(
    np.append(np.arange(-11 * month_length, 0, step=month_length), -1))

universe = StaticAssets(symbols(['IBM', 'F', 'AAPL']))
pipe = Pipeline(columns={
    'revenue':
    Fundamentals(field='revenue', window_length=1),
    'revenue_trend':
    LogFundamentalsTrend(field='revenue', mask=universe).trend,
    'ey':
    EarningYield(),
    'ey_trend':
    LogTimeTrend([EarningYield()], periodic=monthly, mask=universe).trend,
},
                screen=universe)

engine = make_pipeline_engine()
pipe_date = pd.to_datetime('2017-09-07', utc=True)
stocks = engine.run_pipeline(pipe, pipe_date)
print(stocks)

#NO PERIODIC