@check_is_trading
@export_as_api
@ExecutionContext.enforce_phase(EXECUTION_PHASE.HANDLE_BAR, EXECUTION_PHASE.SCHEDULED)
def order_target_percent(id_or_ins, percent, style=None):
 order_book_id = assure_order_book_id(id_or_ins)
 bar_dict = ExecutionContext.get_current_bar_dict()
 price = bar_dict[order_book_id].close
 position = get_simu_exchange().account.portfolio.positions[order_book_id]
 current_value = (position.quantity * price)
 portfolio_value = get_simu_exchange().account.portfolio.portfolio_value
 return order_value(order_book_id, ((portfolio_value * percent) - current_value), style)

@ check_is_trading @ export_as_api @ ExecutionContext . enforce_phase ( EXECUTION_PHASE . HANDLE_BAR , EXECUTION_PHASE . SCHEDULED ) def order_target_percent ( id_or_ins , percent , style = None ) : order_book_id = assure_order_book_id ( id_or_ins ) bar_dict = ExecutionContext . get_current_bar_dict ( ) price = bar_dict [ order_book_id ] . close position = get_simu_exchange ( ) . account . portfolio . positions [ order_book_id ] current_value = ( position . quantity * price ) portfolio_value = get_simu_exchange ( ) . account . portfolio . portfolio_value return order_value ( order_book_id , ( ( portfolio_value * percent ) - current_value ) , style )
place an order to adjust position to a target percent of the portfolio value .