Can someone help me with portfolio optimizations,
I know it is a requirement for allocation so how do I implement it into
def Market_Order(context,data,parameter6,parameter7):
#Market_Order(context,data,stock.symbol,round(expected_capital))
stock=parameter6
price_start=data.history(stock, 'open',1,'1m')
price_current=data.current(stock,'price')
varI=bool(price_start[0]<=price_current)
var_v=True#
if varI:
price_history = data.history(stock, "price", 15, frequency="1m")
mean_15=price_history[-10]
current_price= data.current(stock, 'price')
Stop_loss=(current_price - (current_price * 0.11))
sym=parameter6
#stock_TX= sym not in context.container
order_check=len(get_open_orders(stock.symbol))
StockTK= sym not in context.portfolio.positions
#Stk_Traded= ((StockTK) & (stock_TX) &(order_check == 0))
Stk_Traded= ((StockTK) &(order_check == 0))
Allotment= parameter7
#Allotment= (50000/len(context.results.index))
B4_Order_check=bool((data.can_trade(stock)) & (order_check == 0) & (context.account.leverage==0))
if (B4_Order_check):
#context.container.append(stock.symbol)
if (current_price > mean_15): #and (current_position > 0):
ALot_Bal=context.balance - Allotment
Volume= round(Allotment/current_price)
context.balance =ALot_Bal
order_value(stock,Volume,style=StopLimitOrder(limit_price=current_price, stop_price=Stop_loss))
context.orders_placed=context.orders_placed+1
Current_time= pd.Timestamp(get_datetime()).tz_convert('US/Eastern')
Current_hour= Current_time.hour
Current_minute= Current_time.minute
Current_TV= ((60)*Current_hour)+Current_minute
context.spend.append(context.balance)
context.funds.append(context.account.settled_cash)
security= stock
context.timex[sym]= Current_TV
Thank you in advance