Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Save ouput got from pipeline

Hi,

I am new to Quantopian. I was working with pipeline and custom factors. I understand that in/out in custom factor is narray. How do I log it for debugging purpose?

update_universe(context.my_universe.index)

def handle_data(context, data):
for security in context.my_universe.index:
if security in data:
print "security : %s" % str(security.symbol)
order_target_percent(security, -0.10)

In the above code how do I save the orders (security and order date) so that I can cover the short after say X number of days?
I think I should save some kind of order mapping in dictionary. Any pointers on this?
Any help is appreciated!

3 responses

Hello Sowmya,

See https://www.quantopian.com/help#api-position. You can access current positions via the position object. You could save order info., but it sounds like the position object will do the trick.

Grant

Thanks for the reply Grant.
I looked at the position object but can't find a way to get the order details say the order date. Do I have to save it in context in a dictionary object?

Here's a code snippet that may be helpful.

It appears that while an algo is running, it saves all of the orders, which are accessible by order_id. So if you save the order_id's, you can just pull up the orders. And my understanding is that Quantopian will save data in context, even if the algo needs to be restarted (e.g. for maintenance, outage, etc.). But I don't know if orders are saved. And I don't know what happens if the algo crashes, due to an exception (I think everything is lost, but maybe Quantopian support can recover some data?). I say all of this, since if you are planning to go live, you'll want to get more information on how to write an algo that can tolerate re-starts and crashes. In any case, for backtesting, it looks like you can use the order status field to determine when it has been completely filled, and record that time (I'm not sure it is captured in the order). Then, you can wait X minutes/days, and close the position.

Also, note that for live trading, all orders are cancelled after the market closes. This is not the case for the backtester (and Quantopian simulated live trading, too, I think). Something else to consider if you are wanting to capture orders/fills.