python RUN QUANTOPIAN(RESEARCH)PIPELINE

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python RUN QUANTOPIAN(RESEARCH)PIPELINE相关的知识,希望对你有一定的参考价值。

# import research
from quantopian.research import run_pipeline

# import pipeline methods 
# from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline, CustomFilter

# Fundamantals
from quantopian.pipeline.data import Fundamentals
from quantopian.pipeline.data import morningstar

# Factors
from quantopian.pipeline.factors import CustomFactor 
from quantopian.pipeline.factors import AverageDollarVolume, SimpleMovingAverage, Latest 
from quantopian.pipeline.factors import Returns
import quantopian.pipeline.factors as Factors

# Classifiers
from quantopian.pipeline.classifiers.fundamentals import Sector

# Filters
import quantopian.pipeline.filters as Filters
from quantopian.pipeline.filters.morningstar import IsPrimaryShare
from quantopian.pipeline.filters import  StaticAssets

# import optimize
import quantopian.optimize as opt

# import any datasets we need
from quantopian.pipeline.data.builtin import USEquityPricing

# Experimental
from quantopian.pipeline.experimental import QTradableStocksUS

# import numpy and pandas just in case
import numpy as np
import pandas as pd

import matplotlib.pyplot as plt

# define any constants. 
pass

# Make a custom factor to return the last days close price
# This is really the same as the '.latest' method
class Latest_Close(CustomFactor):  
    """  
    Gets the latest close price for each asset
    """  
    inputs = [USEquityPricing.close]
    window_length = 1
    
    def compute(self, today, assets, out, close):  
        out[:] = close[-1]

# Create a static list of some random iShares ETFs
my_etfs = (StaticAssets(symbols([
'IVV', #iShares Core S&P 500 ETF
'EFA', #iShares MSCI EAFE ETF
'AGG', #iShares Core U.S. Aggregate Bond ETF
'IJH', #iShares Core S&P Mid-Cap ETF
'IWM', #iShares Russell 2000 ETF
'IWD', #iShares Russell 1000 Value ETF
'IWF', #iShares Russell 1000 Growth ETF
'LQD', #iShares iBoxx $ Investment Grade Corporate Bond ETF
'EEM', #iShares MSCI Emerging Markets ETF
'EZU', #'iShares MSCI Eurozone ETF
])))


# instantiate the Latest_10 factor
latest_price = Latest_Close(mask = my_etfs)

high = USEquityPricing.high.latest
low = USEquityPricing.low.latest
open_price = USEquityPricing.open.latest
close = USEquityPricing.close.latest
volume = USEquityPricing.volume.latest

# Create a pipline with each of the factor outputs as columns
pipe = Pipeline(
            columns = {
            'high' : high,
            'low' : low,
            'close' : close,
            'open_price' : open_price,
            'volume' : volume,
            'latest_price' : latest_price,
            },
            screen = my_etfs
            )

# Run the pipeline and show the results
results = run_pipeline(pipe, '2016-07-08', '2016-07-08')
results

以上是关于python RUN QUANTOPIAN(RESEARCH)PIPELINE的主要内容,如果未能解决你的问题,请参考以下文章

python QUANTOPIAN为战略建立因素

python QUANTOPIAN策略与管道因素

python QUANTOPIAN进口管道

python QUANTOPIAN PIPELINE STRATEGY

python QUANTOPIAN ALGO模板(无管道)

python ETF的QUANTOPIAN模板