def run(capital, risk_level, quarter):
        start = Zipliner.dates[quarter]
        end = Zipliner.dates[quarter + 1]
        df = None

        if (risk_level == 2):
            df = zipline.run_algorithm(start=start,
                                       end=end,
                                       initialize=low_risk.initialize,
                                       capital_base=capital,
                                       handle_data=low_risk.handle_data)
        elif (risk_level == 1):
            df = zipline.run_algorithm(start=start,
                                       end=end,
                                       initialize=mid_risk.initialize,
                                       capital_base=capital,
                                       handle_data=mid_risk.handle_data)
        elif (risk_level == 0):
            df = zipline.run_algorithm(
                start=start,
                end=end,
                initialize=high_risk.initialize,
                capital_base=capital,
                handle_data=None,
                before_trading_start=high_risk.before_trading_start)

        return df
Ejemplo n.º 2
0
 def train(self, sd, ed):
     start = 0 if self.config.resume_from_checkpoint is None else self.config.resume_from_checkpoint
     for self.epoch in tqdm(range(start, self.config.n_epochs)):
         print("Epoch {}".format(self.epoch))
         trading_days = date_range(sd, ed, freq=trading_day)
         self.timestep_progress = tqdm(total=len(trading_days) / 21)
         run_algorithm(initialize=self.initialize_training_algo,
                       capital_base=self.capital,
                       start=sd,
                       end=ed)
Ejemplo n.º 3
0
def quickstart_tutorial():
    def initialize(context):
        context.i = 0
        context.asset = zipline.api.symbol("AAPL")

    def handle_data(context, data):
        # Skip first 300 days to get full windows.
        context.i += 1
        if context.i < 300:
            return

        # Compute averages.
        # data.history() has to be called with the same params from above and returns a pandas dataframe.
        short_mavg = data.history(context.asset,
                                  "price",
                                  bar_count=100,
                                  frequency="1d").mean()
        long_mavg = data.history(context.asset,
                                 "price",
                                 bar_count=300,
                                 frequency="1d").mean()

        # Trading logic.
        if short_mavg > long_mavg:
            # order_target orders as many shares as needed to achieve the desired number of shares.
            zipline.api.order_target(context.asset, 100)
        elif short_mavg < long_mavg:
            zipline.api.order_target(context.asset, 0)

        # Save values for later inspection.
        zipline.api.record(AAPL=data.current(context.asset, "price"),
                           short_mavg=short_mavg,
                           long_mavg=long_mavg)

    zipline.run_algorithm(
        start=pd.Timestamp("2014-01-01", tz="utc"),
        end=pd.Timestamp("2018-01-01", tz="utc"),
        initialize=initialize,
        capital_base=1e7,
        handle_data=handle_data,
        before_trading_start=None,
        analyze=None,
        data_frequency="daily",
        bundle="quantopian-quandl",  # zipline ingest -b quantopian-quandl
        bundle_timestamp=None,
        trading_calendar=None,
        metrics_set="default",
        benchmark_returns=None,
        default_extension=True,
        extensions=(),
        strict_extensions=True,
        environ=os.environ,
        blotter="default")
Ejemplo n.º 4
0
 def run_algorithm(self):
     start_time = datetime(2018, 1, 2, 9, 31, 0, 0, pytz.utc)
     end_time = datetime(2018, 2, 4, 16, 0, 0, 0, pytz.utc)
     zipline.run_algorithm(start=start_time,
                           end=end_time,
                           initialize=self.initialize,
                           capital_base=100000,
                           handle_data=self.handle_data,
                           before_trading_start=self.before_trading_start,
                           data_frequency='minute',
                           data=self.prepare_data(),
                           trading_calendar=ChineseStockCalendar(),
                           analyze=self.analyze)
Ejemplo n.º 5
0
def run(name, algo, bundle_name, start, end, capital_base, analyze=True):
    '''Helper to run algorithm
    '''
    return (name, run_algorithm(start=start, end=end,
                                initialize=algo.initialize, handle_data=algo.handle_data, analyze=algo.analyze if analyze else None,
                                capital_base=capital_base, environ=os.environ, bundle=bundle_name
                                ))
Ejemplo n.º 6
0
def main(job_id, D):
    parsed = {
        'symbols': 'SPY',
        'start': '2014-01-01',
        'end': '2014-12-31',
        'algofile': '/home/quant/pta/py/algos/BBANDS-zipday.py',
        'capital_base': '100000',
        'data_frequency': 'daily',
        'conf_file': None,
        'source': 'yahoo',
        'output': None,
        'risk': None,
        'algo_params': D
    }

    # Below what we expect spearmint to pass us
    # parsed['algo_params']=[47,88.7,7.7]
    # D={}
    # D['timeperiod']=10
    # D['nbdevup']=1.00
    # D['nbdevdn']=1.00

    perf = run_algorithm(**parsed)

    StartV = perf['portfolio_value'][0]

    EndV = perf['portfolio_value'][-1]

    # spearmint wants to minimize so return negative profit
    BBANDS = (StartV - EndV)

    return BBANDS
Ejemplo n.º 7
0
def apple_run(shares_per_day, capital_base, start_date, end_date, log_channel):

    ws = create_connection("ws://alpharithmic.herokuapp.com/ws/logs/%s/" %
                           log_channel)
    msg_placeholder = "{\"message\": \"%s\"}"

    ws.send(msg_placeholder % "Link Start")

    def init(context):
        ws.send(msg_placeholder % "Simulation Start")
        pass

    def handle(context, data):
        order(symbol('AAPL'), shares_per_day)
        ws.send(msg_placeholder %
                ("Ordered %s shares of Apple" % str(shares_per_day)))

    start = pd.to_datetime(start_date).tz_localize('US/Eastern')
    end = pd.to_datetime(end_date).tz_localize('US/Eastern')
    result = run_algorithm(start,
                           end,
                           capital_base=capital_base,
                           initialize=init,
                           handle_data=handle,
                           bundle="quandl")

    ws.send(msg_placeholder % "Simulation End")
    ws.send(msg_placeholder % "Fetching backtest results from Redis Queue...")

    result.dropna(inplace=True)

    ws.close()

    return create_json_response(result)
Ejemplo n.º 8
0
def run_strategy(strategy_name):
    """
    Run an example module from zipline.examples.
    """
    mod = None

    if strategy_name == "buy_and_hold":
        mod = BuyAndHold()
    elif strategy_name == "auto_correlation":
        mod = AutoCorrelation()

    register_calendar("YAHOO", get_calendar("NYSE"), force=True)

    print('mod', type(mod), mod.__class__.__name__)
    print('mod._test_args()', mod._test_args())

    return run_algorithm(
        initialize=getattr(mod, 'initialize', None),
        handle_data=getattr(mod, 'handle_data', None),
        before_trading_start=getattr(mod, 'before_trading_start', None),
        analyze=getattr(mod, 'analyze', None),
        bundle='quantopian-quandl',  # change from quandl -> quantopian-quandl
        environ=environ,
        # Provide a default capital base, but allow the test to override.
        **merge({'capital_base': 1e7}, mod._test_args()))
Ejemplo n.º 9
0
    def run_algorithm(self):
        from zipline.api import order, record, symbol, set_benchmark
        import zipline
        import matplotlib.pyplot as plt
        from datetime import datetime
        import pytz
        from zipline.utils.calendars.exchange_calendar_shsz import SHSZExchangeCalendar

        def initialize(context):
            set_benchmark(symbol('SH00300'))

        def handle_data(context, data):
            order(symbol('SH00300'), 10)
            record(SPY=data.current(symbol('SH00300'), 'price'))

        self.perf = zipline.run_algorithm(
            start=datetime(2017, 3, 6, 9, 31, 0, 0,
                           pytz.timezone("Asia/Shanghai")),
            end=datetime(2017, 3, 9, 3, 30, 0, 0,
                         pytz.timezone("Asia/Shanghai")),
            initialize=initialize,
            trading_calendar=SHSZExchangeCalendar(),
            capital_base=100000,
            handle_data=handle_data,
            data_frequency='minute',
            data=self.panel)
        self.perf.head()
Ejemplo n.º 10
0
def run_strategy(strategy_name):
    mod = None

    if strategy_name == "buy_and_hold":
        mod = BuyAndHold()
    elif strategy_name == "auto_correlation":
        mod = AutoCorrelation()
    elif strategy_name == "scalping":
        mod = ScalpBollingerBand()

#     register_calendar("YAHOO", get_calendar("NYSE"), force=True)
    data_panel, start, end = prepareCSV('csv')
    print(data_panel, type(start))

    return run_algorithm(
        data=data_panel,
        trading_calendar=CryptoCalendar(),
        initialize=getattr(mod, 'initialize', None),
        handle_data=getattr(mod, 'handle_data', None),
        before_trading_start=getattr(mod, 'before_trading_start', None),
        analyze=getattr(mod, 'analyze', None),
        #         bundle='quandl',
        environ=environ,
        data_frequency='minute',
        # Provide a default capital base, but allow the test to override.
        **merge({
            'capital_base': 5000,
            'start': start,
            'end': end
        }, mod._test_args()))
Ejemplo n.º 11
0
def get_perf(dict_dt_sec_wgt, initial_amount, start, end):
    stg_analyze = zl_backtest(dict_dt_sec_wgt)
    res = run_algorithm(start=start,
                        end=end,
                        initialize=stg_analyze.initialize,
                        capital_base=initial_amount,
                        handle_data=stg_analyze.rebalance,
                        bundle='quantopian-quandl')
    res.to_pickle('res3.pkl')
    return res
Ejemplo n.º 12
0
    def get_performance(self):

        return zipline.run_algorithm(start=self.start_session,
                                     end=self.end_session,
                                     initialize=self.initialize,
                                     trading_calendar=always_open.AlwaysOpenCalendar(),
                                     capital_base=self.initial_portfolio_value,
                                     handle_data=self.handle_data,
                                     data_frequency="minute",
                                     data=self.minute_data)
Ejemplo n.º 13
0
def analyze(context, perf):
    fig, ax = plt.subplots(3, 1, sharex=True, figsize=[16, 9])

    # portfolio value
    perf.portfolio_value.plot(ax=ax[0])
    ax[0].set_ylabel('portfolio value in $')

    # asset
    perf[['price', 'moving_average']].plot(ax=ax[1])
    ax[1].set_ylabel('price in $')

    # mark transactions

    perf_trans = perf.loc[[t != [] for t in perf.transactions]]
    buys = perf_trans.loc[[
        t[0]['amount'] > 0 for t in perf_trans.transactions
    ]]
    sells = perf_trans.loc[[
        t[0]['amount'] < 0 for t in perf_trans.transactions
    ]]
    ax[1].plot(buys.index,
               perf.price.loc[buys.index],
               '^',
               markersize=10,
               color='g',
               label='buy')
    ax[1].plot(sells.index,
               perf.price.loc[sells.index],
               'v',
               markersize=10,
               color='r',
               label='sell')
    ax[1].legend()

    # daily returns
    perf.returns.plot(ax=ax[2])
    ax[2].set_ylabel('daily returns')

    fig.suptitle('Simple Moving Average Strategy - Apple', fontsize=16)
    plt.legend()
    plt.show()

    print('Final portfolio value (including cash): {}$'.format(
        np.round(perf.portfolio_value[-1], 2)))

    perf = zipline.run_algorithm(start=datetime(2000, 1, 5, 0, 0, 0, 0,
                                                pytz.utc),
                                 end=datetime(2018, 3, 1, 0, 0, 0, 0,
                                              pytz.utc),
                                 initialize=initialize,
                                 capital_base=100,
                                 handle_data=handle_data,
                                 analyze=analyze,
                                 data=panel)
    result.append(perf.portfolio_value[-1])
Ejemplo n.º 14
0
def get_perf(dict_dt_sec_wgt, initial_amount, start, end):
    stg_analyze = stg()

    res = run_algorithm(start=start,
                        end=end,
                        initialize=stg_analyze.initial,
                        capital_base=initial_amount,
                        handle_data=stg_analyze.handle_data,
                        bundle='quantopian-quandl')
    res.to_pickle('res_aapl.pkl')
    return res
Ejemplo n.º 15
0
def validate_single_stock(ticker):

    def init(context):
        symbol(ticker)

    def handle_data(context, data):
        pass

    start = pd.to_datetime("2017-01-09").tz_localize('US/Eastern')
    end = pd.to_datetime("2017-01-11").tz_localize('US/Eastern')

    try:
        run_algorithm(start, end, capital_base=1000000,
                      initialize=init,
                      handle_data=handle_data,
                      bundle="quandl")

        return True
    except:
        return False
Ejemplo n.º 16
0
def run_strategy(strategy_name):
    mod = None
    if strategy_name == "buy_and_hold":
        mod = BuyAndHold()
    register_calendar("YAHOO", get_calendar("NYSE"), force=True)
    return run_algorithm(
        initialize=getattr(mod, 'initialize', None),
        handle_data=getattr(mod, 'handle_data', None),
        before_trading_start=getattr(mod, 'before_trading_start', None),
        analyze=getattr(mod, 'analyze', None),
        bundle='quandl',
        environ=environ,
        # Definimos un capital inicial que puede ser sobreescrito por el test
        **merge({'capital_base': 1e7}, mod._test_args()))
Ejemplo n.º 17
0
def run_example(example_name, environ):
    """
    Run an example module from zipline.examples.
    """
    mod = EXAMPLE_MODULES[example_name]
    return run_algorithm(
        initialize=getattr(mod, 'initialize', None),
        handle_data=getattr(mod, 'handle_data', None),
        before_trading_start=getattr(mod, 'before_trading_start', None),
        analyze=getattr(mod, 'analyze', None),
        bundle='test',
        environ=environ,
        # Provide a default capital base, but allow the test to override.
        **merge({'capital_base': 1e7}, mod._test_args())
    )
Ejemplo n.º 18
0
    def run(self) -> pd.DataFrame:
        """Function to run the simulation; triggers zipline's `run_algorithm`,
        with appropriate function overrides.
        
        Returns:
            pd.DataFrame -- Zipline simulation results.
        """

        return run_algorithm(start=config.backtest_start,
                             end=config.backtest_end,
                             capital_base=config.capital_base,
                             initialize=self.zipline_initialize,
                             handle_data=self.zipline_handle_data,
                             data_frequency=config.backtest_frequency,
                             bundle='quandl')
def main():
    #file_path = 'AAPL.csv'
    print("Reading csv file...")
    data = OrderedDict()
    data['BITMAP'] = pd.read_csv(FILE_PATH,
                                 index_col=0,
                                 parse_dates=['timestamp'])
    print(data['BITMAP'].head())
    print(data['BITMAP'].keys())
    # salvando em arquivo o Dataframe

    # convertendo o pandas Dataframe em pandas Panel
    panel = pd.Panel(data)
    panel.minor_axis = [
        'open', 'high', 'low', 'close', 'volume', 'volume_(currency)',
        'weighted_price'
    ]
    #panel.minor_axis = ['Open', 'High', 'Low', 'Close', 'Volume']
    panel.major_axis = panel.major_axis.tz_localize(pytz.utc)
    print(panel)
    print("Starting zipline..")
    #alg_obj = TradingAlgorithm(initialize=initialize, handle_data=handle_data)
    capital_base = 50000
    start = datetime(2016, 1, 1, 0, 0, 0, 0, pytz.utc)
    end = datetime(2016, 2, 1, 0, 0, 0, 0, pytz.utc)
    print("Running zipline..")
    run_algorithm(start=start,
                  end=end,
                  initialize=initialize,
                  capital_base=capital_base,
                  handle_data=handle_data,
                  analyze=analyze,
                  data=panel,
                  data_frequency='minute')
    #perf_manual = alg_obj.run(panel)
    print("Finished")
Ejemplo n.º 20
0
def py_run(fly_initialize,
           fly_handle_data,
           start,
           end,
           capital_base,
           before_trading_start,
           analyze,
           data_frequency,
           data,
           bundle,
           bundle_timestamp,
           trading_calendar,
           metrics_set,
           default_extension,
           #extensions,
           strict_extensions #,
           #environ
           ):

    def initialize(context):
      fly_initialize(context)
      return

    def handle_data(context, data):
      fly_handle_data(context, data)
      return

    performance = run_algorithm(
      initialize = initialize,
      handle_data = handle_data,
      start = start,
      end = end,
      capital_base = capital_base,
      before_trading_start = before_trading_start,
      analyze = analyze,
      data_frequency = data_frequency,
      data = data,
      bundle = bundle,
      bundle_timestamp = bundle_timestamp,
      trading_calendar = trading_calendar,
      metrics_set = metrics_set,
      default_extension = default_extension,
      #extensions,
      strict_extensions = strict_extensions,
      environ = os.environ
    )

    return performance
Ejemplo n.º 21
0
def main(Ent, Ex):

    global zEnter
    global zExit
    zEnter = Ent
    zExit = Ex
    eastern = pytz.timezone('US/Eastern')
    start = datetime.datetime(2013, 1, 3, 0, 0, 0, 0, eastern)
    end = datetime.datetime(2017, 8, 1, 0, 0, 0, 0, eastern)

    results = run_algorithm(start=start,
                            end=end,
                            initialize=initialize,
                            capital_base=1000000,
                            bundle='quantopian-quandl')
    return results.portfolio_value[-1]
Ejemplo n.º 22
0
    def run_backtest(self, param_dict):

        run = 0
        start_date = param_dict["start"]
        end_date = param_dict["end"]
        while run < self.n_backtests:

            start_year = np.random.randint(low=2002, high=2016)
            start_month = np.random.randint(low=1, high=13)
            start_date = str(start_year) + "-" + str(start_month) + "-1"

            try:

                backtest = run_algorithm(
                    start=pd.Timestamp(start_date, tz="US/Eastern"),
                    end=pd.Timestamp(end_date, tz="US/Eastern"),
                    initialize=self.initialize_algo,
                    capital_base=self.cash,
                    handle_data=self.handle_data,
                    before_trading_start=self._before_trading_start,
                    data_frequency="daily",
                    bundle="quantopian-quandl")

                # save_q = "Do you want to save performance? (y/n)"
                # if (raw_input(save_q) == 'y'):

                #     perf_name = "backtests/performance/" + name + \
                #          "_" + str(run+1) + ".csv"
                #     perf.to_csv(perf_name)
                #     log.info("Algorithm succeeded! \
                #         Saved performance results to: " + perf_name)
                #     print("Algorithm succeeded! Saved \
                #         performance results to: " + perf_name)

            except OutOfMoney as e:

                log.info("Algorithm failed. Ran out of money.")
                print("Algorithm failed. Ran out of money")
            for strategy in self.strategies:

                strategy.__init__(self.param_dict, self.agent)

            run += 1
            if run % 5 == 0:

                self.agent.save()
Ejemplo n.º 23
0
def run_strategy(strategy_name):
    mod = None

    if strategy_name == "buy_and_hold":
        mod = BuyAndHold()

    register_calendar("YAHOO", get_calendar("NYSE"), force=True)

    return run_algorithm(
        initialize=getattr(mod, 'initialize', None),
        handle_data=getattr(mod, 'handle_data', None),
        before_trading_start=getattr(mod, 'before_trading_start', None),
        analyze=getattr(mod, 'analyze', None),
        bundle='quandl',
        environ=environ,
        # Provide a default capital base, but allow the test to override.
        **merge({'capital_base': 1e7}, mod._test_args()))
Ejemplo n.º 24
0
 def test(self, sd, ed, live_start_date, benchmark='SPY'):
     trading_days = date_range(sd, ed, freq=trading_day)
     self.timestep_progress = tqdm(total=len(trading_days) / 21)
     results = run_algorithm(initialize=self.initialize_testing_algo,
                             capital_base=self.capital,
                             start=sd,
                             end=ed)
     returns, positions, transactions = pf.utils.extract_rets_pos_txn_from_zipline(
         results)
     benchmark_returns = get_benchmark_returns(benchmark, sd, ed)
     benchmark_returns.ix[sd] = 0.0
     pf.create_full_tear_sheet(returns,
                               positions=positions,
                               transactions=transactions,
                               benchmark_rets=benchmark_returns,
                               live_start_date=live_start_date,
                               round_trips=True)
Ejemplo n.º 25
0
def run_strategy(strategy_name):
    """
    Run an example module from zipline.examples.
    """
    mod = BaseStrategy

    register_calendar("YAHOO", get_calendar("NYSE"), force=True)

    return run_algorithm(
        initialize=getattr(mod, 'initialize', None),
        handle_data=getattr(mod, 'handle_data', None),
        before_trading_start=getattr(mod, 'before_trading_start', None),
        analyze=getattr(mod, 'analyze', None),
        bundle='quandl',
        environ=environ,
        # Provide a default capital base, but allow the test to override.
        **merge({'capital_base': 1e7}, mod._test_args()))
    def run(self, portfolio, start, end, capital_base=100000):
        MovingAverageStrategy._portfolio = portfolio
        data, _ = AlphaVantageAPI.get_daily_data_for(portfolio.assets)
        data['benchmark'] = data[portfolio.benchmark]
        assets_panel = MovingAverageStrategy.to_panel(data)
        nyse_calendar = trading_calendars.get_calendar('XNYS')

        portfolio.performance = zipline.run_algorithm(
            start=start,
            end=end,
            data_frequency='daily',
            capital_base=capital_base,
            before_trading_start=MovingAverageStrategy.before_trading_start(),
            initialize=MovingAverageStrategy.initialize,
            handle_data=MovingAverageStrategy.handle_data,
            analyze=MovingAverageStrategy.analyze,
            trading_calendar=nyse_calendar,
            data=assets_panel)
Ejemplo n.º 27
0
def test_strategy(params_dict, file_name):
    results = OrderedDict()
    for key, value in params_dict.items():
        global CORR_1, CORR_2, CAP_EXP, VOL_TARGET, REBALANCE
        CORR_1, CORR_2, CAP_EXP, VOL_TARGET, REBALANCE = value

        test = run_algorithm(
            start=pd.Timestamp('2013-01-01', tz='utc'),
            end=pd.Timestamp('2018-10-31', tz='utc'),
            initialize=initialize,
            handle_data=handle_data,
            bundle='futures',
            capital_base=1e+6,
        )

        results[key] = test

    with open('results/{}.pickle'.format(file_name), 'wb') as file:
        pickle.dump(results, file)
Ejemplo n.º 28
0
    def get_performance(self):

        start_session = self.end_session - timedelta(
            days=self.days_to_trade) + timedelta(minutes=1)

        print(self.start_session
              if start_session < self.start_session else start_session)

        start = self.start_session if start_session < self.start_session else start_session

        return zipline.run_algorithm(
            start=start + self.start_timedelta,
            end=self.end_session,
            initialize=self.initialize,
            trading_calendar=always_open.AlwaysOpenCalendar(),
            capital_base=self.initial_portfolio_value,
            handle_data=self.handle_data,
            data_frequency="minute",
            data=self.minute_data)
Ejemplo n.º 29
0
    def run_algorithm(self,
                      params_list,
                      capital_base=800000,
                      exchange_calendar=TFSExchangeCalendar(),
                      **kwargs):
        #TODO: sortino ratio warning, suppress?
        """

        :param params_list: list of parameter to be used for the strategy
        :param capital_base: optional. Money to start with
        :param exchange_calendar: TradingCalendar
        :return: return from zipline.run_algorithm()
        """

        if 'trailing_window' not in params_list:
            raise KeyError('data history parameter missing')

        if self.panel[self.asset_symbol].index[
                params_list['trailing_window']].tzinfo:
            self.start_session = self.panel[self.asset_symbol].index[
                params_list['trailing_window']].tz_convert(
                    'UTC').to_pydatetime()
            self.end_session = self.panel[
                self.asset_symbol].index[-1].tz_convert('utc').to_pydatetime()
        else:
            self.start_session = self.panel[self.asset_symbol].index[
                params_list['trailing_window']].tz_localize(
                    'utc').to_pydatetime()
            self.end_session = self.panel[self.asset_symbol].index[
                -1].tz_localize('utc').to_pydatetime()

        result = zipline.run_algorithm(start = self.start_session,\
                      end = self.end_session,\
                      initialize = self.initialize_(params_list=params_list,commission_cost={'cost':0.0075}), \
                      handle_data= self.handle_data_(),\
                      data = self.panel,\
                      capital_base=capital_base,\
                      data_frequency = self.frequency,\
                      trading_calendar=exchange_calendar,**kwargs,)

        return result
Ejemplo n.º 30
0
 def test_example(self, example):
     mod = getattr(examples, example)
     actual_perf = run_algorithm(
         handle_data=mod.handle_data,
         initialize=mod.initialize,
         before_trading_start=getattr(mod, 'before_trading_start', None),
         analyze=getattr(mod, 'analyze', None),
         bundle='test',
         environ={
             'ZIPLINE_ROOT': self.tmpdir.getpath('example_data/root'),
         },
         capital_base=1e7,
         **mod._test_args())
     assert_equal(
         actual_perf[self.cols_to_check],
         self.expected_perf[example][self.cols_to_check],
         # There is a difference in the datetime columns in pandas
         # 0.16 and 0.17 because in 16 they are object and in 17 they are
         # datetime[ns, UTC]. We will just ignore the dtypes for now.
         check_dtype=False,
     )
Ejemplo n.º 31
0
 def test_example(self, example):
     mod = getattr(examples, example)
     actual_perf = run_algorithm(
         handle_data=mod.handle_data,
         initialize=mod.initialize,
         before_trading_start=getattr(mod, 'before_trading_start', None),
         analyze=getattr(mod, 'analyze', None),
         bundle='test',
         environ={
             'ZIPLINE_ROOT': self.tmpdir.getpath('example_data/root'),
         },
         capital_base=1e7,
         **mod._test_args()
     )
     assert_equal(
         actual_perf[self.cols_to_check],
         self.expected_perf[example][self.cols_to_check],
         # There is a difference in the datetime columns in pandas
         # 0.16 and 0.17 because in 16 they are object and in 17 they are
         # datetime[ns, UTC]. We will just ignore the dtypes for now.
         check_dtype=False,
     )