cvxgrp / cvxstatarb

16 stars 8 forks source link

Position tracking bug in simulation #43

Closed thomasarmstrong98 closed 5 months ago

thomasarmstrong98 commented 5 months ago

https://github.com/cvxgrp/cvxstatarb/blob/98ee78fca19a5509904fc475ab0f401019a39e84/experiments/utils.py#L185C33-L185C42

Hi, I think there's a potential bug here. Since positions takes absolute value, and prices should be >0, this will lead to 0 short positions being identified.

    positions = portfolio_temp.stocks.abs() * portfolio_temp.prices
    long_positions = positions[positions > 0].sum(axis=1)
    short_positions = positions[positions < 0].sum(axis=1)

should be

    positions = portfolio_temp.stocks
    absolute_notionals = portfolio_temp.stocks.abs() * portfolio_temp.prices
    long_positions = absolute_notionals[positions > 0].sum(axis=1)
    short_positions = absolute_notionals[positions < 0].sum(axis=1)

Let me know if you think this correction is necessary - not sure the impact on the simulate results as of yet.

kasperjo commented 5 months ago

@thomasarmstrong98 this is certainly a bug! Thanks for catching it!

It's now fixed. Luckily it doesn't affect the results:)