|
|
@ -45,17 +45,25 @@ class Prop(Strategy): |
|
|
|
""" |
|
|
|
orders: List[Union[Long, Short]] = [] |
|
|
|
conversion_rate = data.loc[data.index[-1][0]].close.to_dict() |
|
|
|
|
|
|
|
# Desired state |
|
|
|
results = indicators_results.T[self.indicator] |
|
|
|
desired_state_precent = results[results > 0] / results[results > 0].sum() |
|
|
|
desired_state_dolards = ( |
|
|
|
state.total_balance(conversion_rate) * desired_state_precent |
|
|
|
) |
|
|
|
stock_to_sell = [] |
|
|
|
|
|
|
|
# Remove all action that the indicator place as negative. |
|
|
|
for stock in results[results < 0].index: |
|
|
|
orders.append(Short(stock, state.stocks[stock], conversion_rate[stock])) |
|
|
|
order = Short(stock, state.stocks[stock], conversion_rate[stock]) |
|
|
|
if self.filter_order(order): |
|
|
|
orders.append(order) |
|
|
|
stock_to_sell.append(stock) |
|
|
|
|
|
|
|
total_money = state.balance + sum( |
|
|
|
conversion_rate[stock_name] * amount |
|
|
|
for stock_name, amount in state.stocks.items() |
|
|
|
if results[stock] > 0 or stock_name in stock_to_sell |
|
|
|
) |
|
|
|
|
|
|
|
# Desired state |
|
|
|
desired_state_precent = results[results > 0] / results[results > 0].sum() |
|
|
|
desired_state_dolards = total_money * desired_state_precent |
|
|
|
|
|
|
|
# Create the new buy orders from with the delta between the actual and the desired state. |
|
|
|
for stock, amount in desired_state_dolards.items(): |
|
|
|