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

Intraday Trades Not Closing Correctly with Autoclose Function and Stop Loss #743

Open
Aqua-4 opened this issue Aug 16, 2024 · 0 comments
Open

Comments

@Aqua-4
Copy link

Aqua-4 commented Aug 16, 2024

Description:

I've added a function to close intraday trades at the end of the day, but I'm encountering an issue when running vbt.Portfolio.from_signals(**portfolio_params) with a stop loss. Specifically,
when I set portfolio_params['sl_stop'] = sl_percent / 100 , my trades are being carried over to the next day instead of being closed.

Input Data and Expected Behavior:

My input data is generated by the autoclose_intraday_trades() function, which assigns an exit signal (short) at the end of the day to close the trade. The expected input data looks like this: long, hold, hold, ..., short.
Issue with Stop Loss:
However, when the stop loss is triggered, vbt.Portfolio.from_signals(**portfolio_params) inserts an additional signal into the array, changing it to long, hold, short, ...short . This causes the trade to not be closed correctly, resulting in spillover into the next day.

Actual Behavior:

The trade is not being closed at the end of the day, and the stop loss is not being applied correctly.

Reproduction Steps:

Add a custom function autoclose_intraday_trades() to assign an exit signal at the end of the day.
Run vbt.Portfolio.from_signals(**portfolio_params) with portfolio_params['sl_stop'] = sl_percent / 100.
Observe that trades are being spilled over to the next day when stop loss is triggered.

Request:

I would like to request assistance in resolving this issue. Is there a way to handle this in VBT to ensure proper backtesting for intraday trades? Please provide guidance or a solution to resolve this issue.

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

1 participant