vectorbt
vectorbt copied to clipboard
Unlimited cash problem
Hi, First of all, thank you for this great package. I'm stunned by the beauty of the Dash visualization and the Numba-assisted optimization.
Now, the problem that I have is with ShortOnly and All trading. The documentation of the from_signals states that:
Longs are limited by the cash in the account, while shorts are unlimited
I've noticed this problem when one of my strategies recorded a -256% loss which clearly indicates a negative balance! I've tried a couple of things like close_first or different size types and they don't work. (TargetPercent doesn't work with short positions)
Are you planning to implement a liquidation check? Because this issue literally breaks the whole analysis for the futures trading.
I should add that a critical problem of this is when a strategy crosses the liquidation price (negative margin) at some point and then recovers from it later, which is far from reality.
Hi @nsarang, 1. you can set lock_cash to True to lock the cash that was used to short (in backtrader this would be setting shortcash to False and preventing cash from turning negative). 2. I have had no issues with TargetPercent on short positions so far. 3. vectorbt doesn't support margin trading nor futures. But you can define any kind of check by implementing a custom order function that tracks your balances. Can't tell whether/when it will be implemented, I have plenty of other features to work on right now.
Edit: fixed shortcash
@polakowo
Hmm, I've been using version 0.18.2 which explains why I missed the lock_cash feature and why TargetPercent didn't work. I'll check the new version and see how it goes 👍
On a seperate note, version 0.19.2 breaks the dash visualization, giving the following error:
AttributeError: type object 'Portfolio' has no attribute 'subplot_settings'
@nsarang I will update the app as part of the next release in a couple of days.
Hi again @polakowo
- I've tried
lock_cashbut it's still generating less than -100% returns. I suppose it's just a bug in the portfolio stats calculations? - Using
TargetPercentthrowsValueError: Only SizeType.Amount, SizeType.Value, and SizeType.Percent are supported - Using
PercentgivesValueError: SizeType.Percent does not support position reversal using signals. Usingclose_first=Truesolves the problem but then wouldn't do any reversal. Do you know a workaround for this?
@nsarang
- Can you please give me a reproducible example?
- from_signals doesn't (and shouldn't) support TargetPercent since any target size may be in conflict with the current signal (imagine placing an exit but target percentage requires an entry).
- Percent is quite different from TargetPercent but it won't work if you plan to reverse the position since vectorbt doesn't know how to fit two operations (closing one position and opening another) into one order such that the end result is exactly the size that you requested.
You should try out Portfolio.from_orders and Portfolio.from_order_func, both have no such limitations.