Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modelling Shorts #9

Closed
mpaoletta opened this issue Jan 28, 2022 · 2 comments
Closed

Modelling Shorts #9

mpaoletta opened this issue Jan 28, 2022 · 2 comments

Comments

@mpaoletta
Copy link

Hi,
We've stumbled on a limitation that we haven't been able to circunvent while backtesting shorts. We are currently using BracketOrders for our trades, but the problem happens on every order type. When the sim broker updates the account and makes a withdraw, it actually increases the account's cash amount when we are shorting (which is consistent with the sell operation), but it is not something that happens in a real exchange. Do you have a suggestion regarding using short on the sim broker? Our current idea would be to create a new simbroker handling this. We could also try to support this on current simbroker.

Regards,
Martin

@jbaron
Copy link
Collaborator

jbaron commented Jan 28, 2022

Hi Martin,

Still need to do some more testing on shorting, so not everything might work as I explain here. But the thoughts behind it:

Equity = Cash + Total Positions (and so equity is stable and should only change if there are some new profits, not if you only buy or sell assets)

As a consequence, if you short (just as you noticed) => Total Positions decreases, Cash increases and equity stays the same.

However in the roboquant it is not the cash but the BuyingPower that decides if you can still buy more assets. So the idea is that BuyingPower decreases because of Margin requirements on the short position you acquired (just like real life). The default BuyingPowerModel used by the SimBroker is not good for shorting since its models a Cash account and not a Margin Account. So you can short as much as you like, since Cash will only increase.

But you could use the MarginBuyingPower.

val broker = SimBroker(buyingPowerModel = MarginBuyingPower())

Still, this is not the best tested part (euphemism) , so there are still bugs in the BuyingPowerModel for margin accounts. If you have a good use case, happy to take a more detailed look into that to ensure the BuyPowerModel works as expected.

regards,
Peter

@mpaoletta
Copy link
Author

Hi Peter,
We went ahead and wrote a new BuyingPower with our needs. We're still testing it, if it pans out ok we'll create a PR with it or talk about our findings. Thanks, I'll close the issue and eventually create a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants