-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Backtesting | ||
=========== | ||
|
||
Backtesting is a beta feature recently added to Tastytrade, so please report any issues! | ||
|
||
Let's see how to perform a backtest: | ||
|
||
.. code-block:: python | ||
from datetime import timedelta | ||
from tastytrade import ( | ||
Backtest, | ||
BacktestEntry, | ||
BacktestExit, | ||
BacktestLeg, | ||
BacktestSession, | ||
today_in_new_york | ||
) | ||
from tqdm.asyncio import tqdm # progress bar | ||
backtest_session = BacktestSession(session) | ||
backtest = Backtest( | ||
symbol="SPY", | ||
entry_conditions=BacktestEntry(), | ||
exit_conditions=BacktestExit(at_days_to_expiration=21), | ||
legs=[BacktestLeg(), BacktestLeg(side="put")], | ||
start_date=today_in_new_york() - timedelta(days=365) | ||
) | ||
results = [r async for r in tqdm(backtest_session.run(backtest))] | ||
print(results[-1]) | ||
.. note:: | ||
As of the time of this writing, the end date of a backtest must be on or before July 31, 2024. | ||
|
||
There are lots of configuration options you can find in the documentation for each class. | ||
The ``run`` function is an ``AsyncGenerator``, so you can do something else while a backtest is running, show a progress bar, or maybe even run several at once! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters