tradingstrategy-ai/trade-executor

close credit supply and open spot in same cycle

Closed this issue · 0 comments

Image

Image

In this strategy momentume-crossover-with-credit.ipynb, it sometimes happens that a credit supply position is closed and a new spot position is opened in the same cycle.

However, in this case, the portfolio_value is estimated incorrectly in the open_spot. This is because the quantity for the loan gets marked as zero in close_credit_supply_position but the position is still open (so the funds are in limbo and not recorded anywhere).

This affects the risk analysis metrics which use portfolio_value_at_open. The bug only becomes obvious when using a really high position_size like 0.999.