Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Limit Order with New Order Optimal Portfolio

Quantopian Community,

Using the old order model, a Limit order could be done like this:

order_target_percent(stock, weight, style = LimitOrder(Price + 0.01))  

How can this be done using the new order model?

i.e.

order_optimal_portfolio(  
        objective=some_objective,  
        constraints=some_constraint,  
    )  
4 responses

order_optimal_portfolio only does market orders.

Sort of the same question. If I use order_target_percent(someStock, somePercentage) for market orders. How would the same be achieved with order optimal portfolio?
Thank you

See the TargetWeights objective described on the help page. It should do the trick.

Give something like this a go:

order_optimal_portfolio(  
  objective=TargetWeights({sid(24): 0.5, sid(5861): 0.5}),  
  constraints=[],  
)

Grant,
Thank you for the reply. Hate to highjack @Quant Trader 's original post, but... I solved my issue by first storing my symbols & signals into a list, then created weights based on the signals and converted those into a dict. I passed the dict to the order_optimal_portfolio function and it worked fine.
In this way, hard coding the symbols and weights can be avoided. That's a plus, since my symbols and signals change daily.
In case someone else comes along and wants to do something similar, here is a back test that does this. It just creates random signals for a group of symbols on the first back test day and trades them on the open using the order_optimal_portfolio method.
Hope it helps.