Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

ExchangeTradingAlgorithmBacktest object has no attribute interrupt_algorithm #284

Open
gatapia opened this issue Mar 21, 2018 · 4 comments

Comments

@gatapia
Copy link

gatapia commented Mar 21, 2018

I'm trying to use interrupt_algorithm to kill a backtest (live=False) but I get this error:

AttributeError: 'ExchangeTradingAlgorithmBacktest' object has no attribute 'interrupt_algorithm'

The code I use is:

import pandas as pd
from catalyst.utils.run_algo import run_algorithm
from catalyst.api import symbol
from datetime import datetime
import pytz

def initialize(context):
    context.i = 0

def handle_data(context, data):
    prices = data.history(symbol('btc_usd'), fields=['close'],bar_count=1,frequency='1T')    
    context.i = context.i + 1
    if context.i == 3: context.interrupt_algorithm()

start_end = datetime(2018, 1, 1, 0, 0, 0, 0, pytz.utc)
run_algorithm(
    capital_base=3000,
    initialize=initialize,
    handle_data=handle_data,
    exchange_name='bitfinex',
    algo_namespace='Test candles',
    base_currency='usd',
    data_frequency='minute',
    live=False,        
    start=start_end,
    end=start_end)

If this is not the appropriate way to programatically stop a backtest what is the correct way?

@lenak25
Copy link
Contributor

lenak25 commented Mar 21, 2018

@gatapia currently the correct way to stop backtest is to define an end date :)
The interrupt_algorithm method is defined for live mode only.
Do you feel that an alternative stop mechanism is required in backtest?

@gatapia
Copy link
Author

gatapia commented Mar 21, 2018

Hi @lenak25,

I have a fair bit of validation within my algo, and if one of my conditions is violated I would like to report this and stop the algo. I would like this behaviour to be consistent between live and backtest but its not critical. I mean currently calling context.interrupt_algorithm() does kill the backtest (with has no attribute exception), its just not very graceful and also inconsistent with live mode.

So this could be considered a low priority enhancement request. But I do think that it is important for backtest and live should be consistent where possible.

@gatapia
Copy link
Author

gatapia commented Mar 21, 2018

Also, algorithms in cython have problems relying on Exceptions, since Exceptions and cython really suck. Which is another issue I have.

@lenak25
Copy link
Contributor

lenak25 commented Mar 22, 2018

@gatapia , thanks for your inputs.
We will take this into consideration when planning our next releases.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants