Back to Community
zipline tradingcalendar causing error

I had a algorithm using zipline utils tradingcalendar:

from zipline.utils.tradingcalendar import get_early_closes
from zipline.utils import tradingcalendar

I can build the code, but when I start running the backtest, it shows an error:

"There was a problem starting your backtest. Please try again."

Anybody can help me out? Thanks

8 responses

I've used zipline.utils.tradingcalendar without problems. Can you post a code example that demonstrates what you're seeing?

Code like this worked up until Wed 22Jun ; yesterday it stopped. It will build with crtl-B but submitting a full backtest gives error as Daiwei described.

# For Early Close logic  
from pytz import timezone  
from datetime import datetime  
from zipline.utils.tradingcalendar import get_early_closes  
def initialize(context):

    # Build an early close calendar  
    dtStart=datetime(2000, 1, 1, 0, 0, 0, 0, timezone('UTC'))  
    dtEnd=datetime(2050, 1, 1, 0, 0, 0, 0, timezone('UTC'))  
    context.dtEarlyCloses=get_early_closes(dtStart,dtEnd).date

    schedule_function(day_test,  
        date_rules.every_day(),  
        half_days=True,  
        time_rule=time_rules.market_open())

def day_test(context, data):  
    if get_datetime().date() in context.dtEarlyCloses:  
      log.info("Early Close today")  
    else:  
      log.info("Regular day")  

Richard
http://quant-coder.prokopyshen.com/ContactMe

Richard, this line of your code has a type error:

context.dtEarlyCloses=get_early_closes(dtStart,dtEnd).date  

The last .date should be removed.

That said, I can confirm, this is not working. When I build it I get the following message:

ZiplineDeprecationWarning: The `tradingcalendar` module is deprecated. See the `zipline.utils.calendars.trading_schedule` module, as well as the calendar definitions in `zipline.utils.calendars`.  

Quantopian...zipline.utils.calendars.trading_schedule appears to generally have a nicer interface than trading calendar. That's good. But at first glance I don't see how to do what Richard wants to do. And I don't understand why tradingcalendar would now be broken.

i have the same problem with the same error message in using tradingcalendar module.

Looking at Quantopian's github repo for zipline it does appear there has been a lot of recent activity in the trading calendar arena.

I know that the above code snippet has worked for years ; I originally got it from an algo posted on the forums here in days gone by. In any event, something changed between Wed 22Jun2016 and Thu 23Jun2016 to break this.

Interestingly, this code works just fine and as expected in Research:

# Build an early close calendar  
dtStart=datetime(2005, 1, 1, 0, 0, 0, 0, timezone('UTC'))  
dtEnd=datetime(2020, 1, 1, 0, 0, 0, 0, timezone('UTC'))  
print type(dtStart),dtStart  
print type(dtEnd),dtEnd  
dtEarlyCloses=get_early_closes(dtStart,dtEnd).date  
print dtEarlyCloses  

And it doesnt appear that the weekend maintenance had any impact on this; the problem is still here when I tried this morning.

So as a workaround I extracted the dates from research and coded up an old-fashioned hard-coded date routine to use in the IDE in attached notebook.

Richard
http://quant-coder.prokopyshen.com/ContactMe

Clone Algorithm
1
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5771147d90be860f9ef79d2f
There was a runtime error.

Hi folks,
We are doing a lot of work on the trading calendars in an effort to bring futures to the platform. Looks like we've got a bug here. We'll look into it and get a resolution as soon as possible. I'll post here when it's fixed. Sorry for the inconvenience.

KR

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hi guys, thanks for your patience. We have fixed the bug, so any algorithms using the zipline.utils.tradingcalendar module should be able to do full backtests once again.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thanks Karen, Nathan and the rest of the Q team. All looks good now. Richard.