当前位置: 首页>>代码示例>>Python>>正文


Python yahoofinance.build_feed函数代码示例

本文整理汇总了Python中pyalgotrade.tools.yahoofinance.build_feed函数的典型用法代码示例。如果您正苦于以下问题:Python build_feed函数的具体用法?Python build_feed怎么用?Python build_feed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了build_feed函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testInvalidDates

    def testInvalidDates(self):
        instrument = "orcl"

        # Don't skip errors.
        with self.assertRaisesRegexp(Exception, "HTTP Error 404: Not Found"):
            with common.TmpDir() as tmpPath:
                bf = yahoofinance.build_feed([instrument], 2100, 2101, storage=tmpPath, frequency=bar.Frequency.DAY)

        # Skip errors.
        with common.TmpDir() as tmpPath:
            bf = yahoofinance.build_feed(
                [instrument], 2100, 2101, storage=tmpPath, frequency=bar.Frequency.DAY, skipErrors=True
            )
            bf.loadAll()
            self.assertNotIn(instrument, bf)
开发者ID:JimSnead,项目名称:pyalgotrade,代码行数:15,代码来源:yahoo_test.py

示例2: algoparser

def algoparser(**kwargs):
    """
    编译用户代码
    :param args:
    :param kwargs:
              sid: 资产ID
              start: 策略开始时间
              end: 策略结束时间
              code: 用户策略代码(字符串)
              filename: 用户策略文件名(.py)
    :return:
    """
    sid = kwargs.pop('sid', None)
    start = kwargs.pop('start', None)
    end = kwargs.pop('end', None)
    code = kwargs.pop('code',None)

    Algo = compile(code, '<string>', 'exec')
    exec Algo

    instrument = sid
    feed = yahoofinance.build_feed([instrument], start, end, ".")

    strat = Strategy(feed, instrument)

    sharpeRatioAnalyzer = sharpe.SharpeRatio()
    strat.attachAnalyzer(sharpeRatioAnalyzer)

    plt = plotter.StrategyPlotter(strat,True,False,False)
    strat.run()
    stat = plt.plotjson()
    print stat
    return stat
开发者ID:StratsOn,项目名称:pyalgotrade,代码行数:33,代码来源:engine.py

示例3: main

def main(plot):
    use_ex = True

    instrument = "tcehy"
    feed = yahoofinance.build_feed([instrument], 2015, 2016, ".")

    if (use_ex):
        strat = SMACrossOverEx(feed, instrument)
    else:
        strat = SMACrossOver(feed, instrument, 15)
    sharpeRatioAnalyzer = sharpe.SharpeRatio()
    strat.attachAnalyzer(sharpeRatioAnalyzer)

    # Attach a returns analyzers to the strategy.
    returnsAnalyzer = returns.Returns()
    strat.attachAnalyzer(returnsAnalyzer)

    if plot:
        plt = plotter.StrategyPlotter(strat, True, False, True)
        if (use_ex):
            plt.getInstrumentSubplot(instrument).addDataSeries("sma-15", strat.getSMA(15))
            plt.getInstrumentSubplot(instrument).addDataSeries("sma-30", strat.getSMA(30))
        else:
            plt.getInstrumentSubplot(instrument).addDataSeries("sma", strat.getSMA())

        # Plot the simple returns on each bar.
        plt.getOrCreateSubplot("returns").addDataSeries("Simple returns", returnsAnalyzer.getReturns())

    strat.run()
    strat.info("Final portfolio value: $%.2f" % strat.getResult())

    print "Sharpe ratio: %.2f" % sharpeRatioAnalyzer.getSharpeRatio(0.05)

    if plot:
        plt.plot()
开发者ID:upbit,项目名称:pyalgotrade-step-by-step,代码行数:35,代码来源:sma_test.py

示例4: main

def main(plot):
    al1 = Analyst('Ivy Kang')
    al1.assign_weight('cmg', 0.673)
    al1.assign_weight('aapl', 0.215)

    al2 = Analyst('Charlie Brown')
    al2.assign_weight('cmg', 0.420)
    al2.assign_weight('orcl', 0.130)
    al2.assign_weight('bk', 0.32)
    al2.assign_weight('bk', 0.40)
    al2.assign_weight('cmg', 0.30)

    org = Organization()
    org.add_analyst(al1)
    org.add_analyst(al2)

    # Download the bars.
    feed = yahoofinance.build_feed(org.get_weights().keys(), 2014, 2015, ".instr_data")

    strat = OrgStrat(feed, org)
    sharpeRatioAnalyzer = sharpe.SharpeRatio()
    strat.attachAnalyzer(sharpeRatioAnalyzer)

    if plot:
        plt = plotter.StrategyPlotter(strat, True, False, True)

    strat.run()

    if plot:
        plt.plot()
开发者ID:yuanagain,项目名称:gimg_btn,代码行数:30,代码来源:strats.py

示例5: pickAsFunToLoop2

def pickAsFunToLoop2(instrument):

    #code = pickle.load(open(r'C:\Users\pmhgms\Desktop\machine_leaning\DataSet\stock_code.pickle','rb'))
    #instrument = code[randint(0, len(code))]
    # Load the yahoo feed from the CSV file
    instruments = [instrument]
    sy, ey = 2000, 2015
    smaPeriod = 60
    feed = yahoofinance.build_feed(instruments, sy, ey, "yhfeed", skipErrors=True)
    
    # Evaluate the strategy with the feed's bars.
    myStrategy = tut.SMACrossOver(feed, instrument, smaPeriod)
    
    # Attach a returns analyzers to the strategy.
    returnsAnalyzer = returns.Returns()
    myStrategy.attachAnalyzer(returnsAnalyzer)
    sharpeRatioAnalyzer = sharpe.SharpeRatio()
    myStrategy.attachAnalyzer(sharpeRatioAnalyzer)
    # Attach the plotter to the strategy.
    plt = plotter.StrategyPlotter(myStrategy)
    # Include the SMA in the instrument's subplot to get it displayed along with the closing prices.
    plt.getInstrumentSubplot(instrument).addDataSeries("sma", myStrategy.getSMA())
    # Plot the simple returns on each bar.
    #plt.getOrCreateSubplot("returns").addDataSeries("Simple returns", returnsAnalyzer.getReturns())
    
    # Run the strategy.
    myStrategy.run()
    myStrategy.info("Final portfolio value: $%.2f" % (myStrategy.getResult()))
    
    # Plot the strategy.
    directory = 'smajpg'
    picname = instrument+'_From_'+str(sy)+'_To_'+str(ey)+'_smaPeriod_'+str(smaPeriod)+'.jpg'
    path = os.path.join(directory, picname)
    plt.plot(savefige=True, path=path)
开发者ID:pmhgms,项目名称:dataScript,代码行数:34,代码来源:ana_temp.py

示例6: main

def main(plot, instruments, smaPeriod, cash):

    # Download the bars.
    # In the instruments,I can provide more instruments.The instruments name can be got from yahoo finance.
    #instruments = ["c07.si","C09.SI","C31.SI","E5H.SI"]
    #instruments = ["h78.si"]
    #feed is a Feed type defined in yahoofeed.py
    feed = yahoofinance.build_feed(instruments, 2008, 2009, "./Historical_Price")

    for instrument in instruments:
        myStrategy = MyStrategy(feed, instrument, smaPeriod, cash)

        if plot == True :
            # Attach a returns analyzers to the strategy.
            returnsAnalyzer = returns.Returns()
            myStrategy.attachAnalyzer(returnsAnalyzer)

            # Attach the plotter to the strategy.
            plt = plotter.StrategyPlotter(myStrategy)
            # Include the SMA in the instrument's subplot to get it displayed along with the closing prices.
            #plt.getInstrumentSubplot(instrument).addDataSeries("SMA", myStrategy.getSMA())
            # Plot adjusted close values instead of regular close.
            plt.getInstrumentSubplot(instrument).setUseAdjClose(True)
            # Plot the strategy returns at each bar.
            #plt.getOrCreateSubplot("returns").addDataSeries("Net return", returnsAnalyzer.getReturns())
            #plt.getOrCreateSubplot("returns").addDataSeries("Cum. return", returnsAnalyzer.getCumulativeReturns())

        myStrategy.run()
        print "Result for %s : %.2f" % (instrument, myStrategy.getResult())

        # Plot the strategy.
        if plot == True :
            plt.plot()
开发者ID:wygold,项目名称:HelloWorld,代码行数:33,代码来源:candleAnalyze.py

示例7: main

def main(plot):
    initialCash = 10000
    instrumentsByClass = {
        "US Stocks": ["VTI"],
        "Foreign Stocks": ["VEU"],
        "US 10 Year Government Bonds": ["IEF"],
        "Real Estate": ["VNQ"],
        "Commodities": ["DBC"],
    }

    # Download the bars.
    instruments = ["SPY"]
    for assetClass in instrumentsByClass:
        instruments.extend(instrumentsByClass[assetClass])
    feed = yahoofinance.build_feed(instruments, 2007, 2013, "data", skipErrors=True)

    strat = MarketTiming(feed, instrumentsByClass, initialCash)
    sharpeRatioAnalyzer = sharpe.SharpeRatio()
    strat.attachAnalyzer(sharpeRatioAnalyzer)
    returnsAnalyzer = returns.Returns()
    strat.attachAnalyzer(returnsAnalyzer)

    if plot:
        plt = plotter.StrategyPlotter(strat, False, False, True)
        plt.getOrCreateSubplot("cash").addCallback("Cash", lambda x: strat.getBroker().getCash())
        # Plot strategy vs. SPY cumulative returns.
        plt.getOrCreateSubplot("returns").addDataSeries("SPY", cumret.CumulativeReturn(feed["SPY"].getPriceDataSeries()))
        plt.getOrCreateSubplot("returns").addDataSeries("Strategy", returnsAnalyzer.getCumulativeReturns())

    strat.run()
    print "Sharpe ratio: %.2f" % sharpeRatioAnalyzer.getSharpeRatio(0.05)
    print "Returns: %.2f %%" % (returnsAnalyzer.getCumulativeReturns()[-1] * 100)

    if plot:
        plt.plot()
开发者ID:grayfox7744,项目名称:quantLibrary,代码行数:35,代码来源:test1.py

示例8: main

def main(plot):
    entrySMA = 200
    exitSMA = 5
    rsiPeriod = 2
    overBoughtThreshold = 90
    overSoldThreshold = 10

    # Download the bars.
    instrument = "tcehy"
    feed = yahoofinance.build_feed([instrument], 2014, 2016, ".")

    strat = RSI2(feed, instrument, entrySMA, exitSMA, rsiPeriod, overBoughtThreshold, overSoldThreshold)
    sharpeRatioAnalyzer = sharpe.SharpeRatio()
    strat.attachAnalyzer(sharpeRatioAnalyzer)

    if plot:
        plt = plotter.StrategyPlotter(strat, True, False, True)
        plt.getInstrumentSubplot(instrument).addDataSeries("Entry SMA", strat.getEntrySMA())
        plt.getInstrumentSubplot(instrument).addDataSeries("Exit SMA", strat.getExitSMA())
        plt.getOrCreateSubplot("rsi").addDataSeries("RSI", strat.getRSI())
        plt.getOrCreateSubplot("rsi").addLine("Overbought", overBoughtThreshold)
        plt.getOrCreateSubplot("rsi").addLine("Oversold", overSoldThreshold)

    strat.run()
    strat.info("Final portfolio value: $%.2f" % strat.getResult())

    print "Sharpe ratio: %.2f" % sharpeRatioAnalyzer.getSharpeRatio(0.05)

    if plot:
        plt.plot()
开发者ID:upbit,项目名称:pyalgotrade-step-by-step,代码行数:30,代码来源:rsi2_test.py

示例9: main2

def main2(plot):
    instrument = "ivv"
    smaPeriod = 20
    
    # Download the bars.
    feed = yahoofinance.build_feed([instrument], 2013, 2014, ".")
    
    # Evaluate the strategy with the feed's bars.
    myStrategy = SMACrossOver(feed, instrument, smaPeriod)
    
    # Attach a returns analyzers to the strategy.
    returnsAnalyzer = returns.Returns()
    myStrategy.attachAnalyzer(returnsAnalyzer)
    
    # Attach the plotter to the strategy.
    plt = plotter.StrategyPlotter(myStrategy)
    # Include the SMA in the instrument's subplot to get it displayed along with the closing prices.
    plt.getInstrumentSubplot(instrument).addDataSeries("SMA", myStrategy.getSMA())
    # Plot the simple returns on each bar.
    plt.getOrCreateSubplot("returns").addDataSeries("Simple returns", returnsAnalyzer.getReturns())
    
    # Run the strategy.
    myStrategy.run()
    myStrategy.info("Final portfolio value: $%.2f" % myStrategy.getResult())
    
    # Plot the strategy.
    plt.plot()    
开发者ID:luosz,项目名称:quant,代码行数:27,代码来源:sma_crossover.py

示例10: main

def main(plot):
    instrument = "yhoo"
    bBandsPeriod = 20

    # Download the bars.
    feed = yahoofinance.build_feed([instrument], 2011, 2015, ".")
    # feed = ts.get_hist_data('601198')
    print type(feed)
    # import sys;sys.exit(0)

    strat = BBands(feed, instrument, bBandsPeriod)
    sharpeRatioAnalyzer = sharpe.SharpeRatio()
    strat.attachAnalyzer(sharpeRatioAnalyzer)

    if plot:
        plt = plotter.StrategyPlotter(strat, True, True, True)
        plt.getInstrumentSubplot(instrument).addDataSeries("upper", strat.getBollingerBands().getUpperBand())
        plt.getInstrumentSubplot(instrument).addDataSeries("middle", strat.getBollingerBands().getMiddleBand())
        plt.getInstrumentSubplot(instrument).addDataSeries("lower", strat.getBollingerBands().getLowerBand())

    strat.run()
    print "Sharpe ratio: %.2f" % sharpeRatioAnalyzer.getSharpeRatio(0.05)

    if plot:
        plt.plot()
开发者ID:johnsonhongyi,项目名称:pyQuant,代码行数:25,代码来源:talib-tools.py

示例11: testBuildDailyFeed

 def testBuildDailyFeed(self):
     with common.TmpDir() as tmpPath:
         instrument = "orcl"
         bf = yahoofinance.build_feed([instrument], 2010, 2010, storage=tmpPath)
         bf.loadAll()
         self.assertEqual(bf[instrument][-1].getOpen(), 31.22)
         self.assertEqual(bf[instrument][-1].getClose(), 31.30)
开发者ID:JimSnead,项目名称:pyalgotrade,代码行数:7,代码来源:yahoo_test.py

示例12: main

def main(plot):
    initialCash = 1000000
    commodity_tickers=["B","TA","BR"]
    instrumentsByClass = {
        "commodity": commodity_tickers
    }

    # Download the bars.
    instruments = []
    for assetClass in instrumentsByClass:
        instruments.extend(instrumentsByClass[assetClass])
    feed = yahoofinance.build_feed(instruments, 2007, 2013, "data", skipErrors=True)

    strat = MarketTiming(feed, instrumentsByClass, initialCash)
    sharpeRatioAnalyzer = sharpe.SharpeRatio()
    strat.attachAnalyzer(sharpeRatioAnalyzer)
    returnsAnalyzer = returns.Returns()
    strat.attachAnalyzer(returnsAnalyzer)

    if plot:
        plt = plotter.StrategyPlotter(strat, False, False, True)
        plt.getOrCreateSubplot("cash").addCallback("Cash", lambda x: strat.getBroker().getCash())
        # Plot strategy vs. SPY cumulative returns.
        plt.getOrCreateSubplot("returns").addDataSeries("SPY", cumret.CumulativeReturn(feed["SPY"].getPriceDataSeries()))
        plt.getOrCreateSubplot("returns").addDataSeries("Strategy", returnsAnalyzer.getCumulativeReturns())

    strat.run()
    print "Sharpe ratio: %.2f" % sharpeRatioAnalyzer.getSharpeRatio(0.05)
    print "Returns: %.2f %%" % (returnsAnalyzer.getCumulativeReturns()[-1] * 100)

    if plot:
        plt.plot()
开发者ID:JayDeng2837,项目名称:WorkSpace,代码行数:32,代码来源:dual_momentum.py

示例13: pickAsFunToLoop

def pickAsFunToLoop(instrument,usevir=0):

    #code = pickle.load(open(r'C:\Users\pmhgms\Desktop\machine_leaning\DataSet\stock_code.pickle','rb'))
    #instrument = code[randint(0, len(code))]
    # Load the yahoo feed from the CSV file
    instruments = [instrument]
    sy, ey = 2000, 2015
    p1, p2 = 20, 10
    usevir = usevir
    feed = yahoofinance.build_feed(instruments, sy, ey, "yhfeed", skipErrors=True)
    
    # Evaluate the strategy with the feed's bars.
    myStrategy = tut.MyStrategy(feed, instrument, p1, p1, usevir)
    
    # Attach a returns analyzers to the strategy.
    returnsAnalyzer = returns.Returns()
    myStrategy.attachAnalyzer(returnsAnalyzer)
    
    # Attach the plotter to the strategy.
    plt = plotter.StrategyPlotter(myStrategy)
    # Include the SMA in the instrument's subplot to get it displayed along with the closing prices.
    plt.getInstrumentSubplot(instrument).addDataSeries("high", myStrategy.getHigh())
    plt.getInstrumentSubplot(instrument).addDataSeries("low", myStrategy.getLow())
    # Plot the simple returns on each bar.
    #plt.getOrCreateSubplot("returns").addDataSeries("Simple returns", returnsAnalyzer.getReturns())
    
    # Run the strategy.
    myStrategy.run()
    myStrategy.info("Final portfolio value: $%.2f, Stop loss %d time, Skip buy %d time" % (myStrategy.getResult(), myStrategy.stoplosstimes, myStrategy.skipbuy))
    
    # Plot the strategy.
    directory = 'temjpg'
    picname = instrument+'_From_'+str(sy)+'_To_'+str(ey)+'_p1_'+str(p1)+'_p2_'+str(p2)+'_usevir_'+str(usevir)+'.jpg'
    path = os.path.join(directory, picname)
    plt.plot(savefige=True, path=path)
开发者ID:pmhgms,项目名称:dataScript,代码行数:35,代码来源:ana_temp.py

示例14: main2

def main2(plot, instrument, entry_sma_period, exit_sma_period):
    # Download the bars.
    feed = yahoofinance.build_feed([instrument], 2014, 2014, ".")
    
    # Evaluate the strategy with the feed's bars.
    strat = SMACrossOver2(feed, instrument, entry_sma_period, exit_sma_period)
    
    # Attach a returns analyzers to the strategy.
    returnsAnalyzer = returns.Returns()
    strat.attachAnalyzer(returnsAnalyzer)
    
    # Attach the plotter to the strategy.
    plt = plotter.StrategyPlotter(strat)
    # Include the SMA in the instrument's subplot to get it displayed along with the closing prices.
    plt.getInstrumentSubplot(instrument).addDataSeries("SMA", strat.getSMA())
    plt.getInstrumentSubplot(instrument).addDataSeries("exit SMA", strat.get_exit_SMA())
    # Plot the simple returns on each bar.
    plt.getOrCreateSubplot("returns").addDataSeries("Simple returns", returnsAnalyzer.getReturns())
    
    # Run the strategy.
    strat.run()
    strat.info("Final portfolio value: $%.2f" % strat.getResult())
    
    # Plot the strategy.
    plt.plot()
开发者ID:luosz,项目名称:quant,代码行数:25,代码来源:my_sma_crossover.py

示例15: main

def main(plot):
    initialCash = 10000
    instrumentsByClass = {
        "Technology": ["MSFT", "ORCL", "IBM", "HPQ"],
        "Services": ["WMT", "UPS", "TGT", "CCL"],
        "Basic Materials": ["XOM", "CVX", "COP", "OXY"],
        "Financial": ["BAC", "JPM", "WFC", "GS"],
        "Consumer Goods": ["PG", "PEP", "CL", "KO"],
    }

    # Download the bars.
    instruments = []
    for assetClass in instrumentsByClass:
        instruments.extend(instrumentsByClass[assetClass])
    feed = yahoofinance.build_feed(instruments, 2005, 2013, "data", skipErrors=True)

    strat = MarketTiming(feed, instrumentsByClass, initialCash)
    sharpeRatioAnalyzer = sharpe.SharpeRatio()
    strat.attachAnalyzer(sharpeRatioAnalyzer)

    if plot:
        plt = plotter.StrategyPlotter(strat, False, False, True)
        plt.getOrCreateSubplot("cash").addCallback("Cash", lambda x: strat.getBroker().getCash())

    strat.run()
    print "Sharpe ratio: %.2f" % sharpeRatioAnalyzer.getSharpeRatio(0.05)

    if plot:
        plt.plot()
开发者ID:frostyplanet,项目名称:pyalgotrade,代码行数:29,代码来源:market_timing.py


注:本文中的pyalgotrade.tools.yahoofinance.build_feed函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。