Quantopian Tutorial LESSON 10

This is a continuation of Last time.

LESSON 10 Managing Orders When using Quantopian's slippage model, not all orders placed will be filled. Unfilled orders remain until they are filled or canceled, so you need to consider this situation.

ʻOrder_target_percent ()` does not consider open orders. The order will be canceled at the close of the day, but if you place an additional order with unfilled orders remaining during the day, you will trade over the original funds (over order).

To avoid overorders, use the get_open_orders () function to check for unfilled orders. By passing an instance of the stock as an argument, the open order of the target stock is returned in dictionary type.

In the example below, XTL is long when there are no unfilled orders and it is possible to trade. You can clone the code from here.

def initialize(context):
    # Relatively illiquid stock.
    context.xtl = sid(40768)

def handle_data(context, data):
    # Get all open orders.
    open_orders = get_open_orders()

    if context.xtl not in open_orders and data.can_trade(context.xtl):
        order_target_percent(context.xtl, 1.0)

LESSON 11 Putting It All Together

LESSON 9<-->LESSON11

Recommended Posts

Quantopian Tutorial LESSON 10
Quantopian Tutorial LESSON 8
Quantopian Tutorial LESSON 1, 2
Quantopian Tutorial LESSON 6
Quantopian Tutorial LESSON 9
Quantopian Tutorial LESSON 5
Quantopian Tutorial LESSON 3
Quantopian Tutorial LESSON 7
Quantopian Tutorial LESSON 4
Quantopian Tutorial LESSON 11
sqlalchemy tutorial
PyODE Tutorial 2
Python tutorial
PyODE Tutorial 1
PyODE Tutorial 3
TensorFlow tutorial tutorial