Issue with get_datetime in Zipline.

133 views
Skip to first unread message

Joël Hubert

unread,
Aug 18, 2015, 5:33:36 AM8/18/15
to Zipline Python Opensource Backtester
Hi, I'm importing all this from an algo written in the Quantopian IDE:

from pytz import timezone
from datetime import datetime, timedelta 
from zipline.utils.tradingcalendar import get_early_closes
from numpy import matrix, array, zeros, empty, sqrt, ones, dot, append, mean, cov, transpose, linspace
import numpy as np
import scipy.optimize
import math
import pandas as pd
import random
import zipline
from zipline import TradingAlgorithm
from zipline.data.loader import load_bars_from_yahoo

Slightly further this is called:
 def handle_data(context, data):    
   if get_datetime().hour == 14 and get_datetime().minute == 35: 

The IPython notebook I'm using gives me the following error:

<string> in handle_data(context, data)
NameError: global name 'get_datetime' is not defined 

I have no idea what this is about, I'm not that advanced. Help much appreciated.

John Ricklefs

unread,
Aug 18, 2015, 7:22:22 PM8/18/15
to Zipline Python Opensource Backtester
Hi Joël,

I believe the problem here is that you need to import "get_datetime" into your IPython namespace. Try adding `from zipline.api import get_datetime` to your notebook and report back if you still see this error.

Cheers!
--John "JD" Ricklefs
Engineering @ Quantopian
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages