Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
'dir' output from debugger?

If I go into the debugger and type 'dir' I get:

bound method AlgorithmProxy.qdir of AlgorithmProxy(
capital_base=100000.0 sim_params= SimulationParameters(
period_start=2014-10-01 00:00:00+00:00, period_end=2014-10-10
23:59:00+00:00, capital_base=1000000.0, data_frequency=daily,
emission_rate=daily, first_open=2014-10-01 13:31:00+00:00,
last_close=2014-10-10 20:00:00+00:00), initialized=True,
slippage=VolumeShareSlippage( volume_limit=0.25, price_impact=0.1),
commission=PerShare(cost=0.03, min trade cost=None), blotter=Blotter(
transact_partial=(VolumeShareSlippage( volume_limit=0.25,
price_impact=0.1), PerShare(cost=0.03, min trade cost=None)),
open_orders=defaultdict(, {}), orders={}, new_orders=[],
current_dt=2014-10-01 00:00:00+00:00), recorded_vars={})

Does anyone know how to access the data shown above from within the algorithm? For example, it'd be handy to get access to the value of 'last_close' so that the last call to handle_data could be detected?

Grant

3 responses

I'm betting they did not mean to leave the "dir" command available. Most of the introspection tools are unavailable - even "help". From the look of it, we would need getters and setters to read and modify those objects. For instance, "open_orders" is a dictionary in that object, but we need to use get_open_orders to see the contents. It would be nice to have a "get_sim_params"!

Ray,

Yes, that's the basic idea--as you suggest, something like 'get_sim_params' or 'get_backtest_params' would be handy.

The 'dir' command is available in a backtest, too (see attached). To get at the values, though, one would have to parse the text--kinda awkward.

Grant

To get at the values, though, one would have to parse the text--kinda
awkward.

Hey, thanks! Fortunately they give us regular expressions, so the code is trivial:

import re  
a=dir  
b = re.findall('period_end=(.*),',str(a))  

The result is a string inside a list, but pandas has a nice datetime parser built-in, so:
import pandas c = pandas.to_datetime(b[0]) And there you go... c contains your end datetime.