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

allow open trades at end of backtest. #1102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

themantalope
Copy link

Added option to leave trades open at the end of a backtest. Allows users to check if they have open trades at the end of a backtest as an easy way to use the strategy in a "live" manner.

@LorenzoPietroBonatti
Copy link

Hey, could you please show me how is it working for you? I tried to fork your branch and use it, but the trades doesn't remained open. Even if my strategy should be bought in the past candles and should not have sold all my position. Appreciate the help.

@themantalope
Copy link
Author

Sure, here is a quick example:

from other_module import AmazingStrategy
from backtesting import Backtest
import pandas as pd

data = pd.read_csv("filewith_olhc.csv")
bt = Bactest(data, AmazingStrategy, cash=10000, leave_orders_open=True)
results = bt.run()
# now get the strategy object from results
strat_res = results._strategy
open_trades = strat_res.trades

Typically, all trades are closed at the end of the Backtest.run (see here). I wanted to be able to take a strategy with updated daily data and see if there are any "open" trades/positions (not sure which is the better term to use). If there is a less clunky way to do so please let me know.

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

Successfully merging this pull request may close these issues.

None yet

2 participants