Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Liquidization of Entire Portfolio

Hello:
What would be the better/right way to liquidize all the positions in my portfolio? The following for loop could serve the purpose. However, I don't suppose order_target_percent() can be used in the contest since a contest participating algorithm is required to place all of its orders with the order_optimal_portfolio function. Other ordering methods in the Quantopian API are not allowed in the contest.
Thanks for the advice...

for position in context.portfolio.positions:
order_target_percent(position, 0)

2 responses

Something along this line

import pandas as pd

    order_optimal_portfolio(  
        objective = opt.TargetWeights(  
            # the 0 means close them  
            pd.Series(0, index = context.portfolio.positions.keys())  
        ),  
        constraints = []  

make sense.... thanks,