-
Notifications
You must be signed in to change notification settings - Fork 193
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
added analyze_backtest which can be turned off. #717
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2905,6 +2905,9 @@ def write_backtest_settings(self, settings_file: str): | |
>>> self.write_backtest_settings("backtest_settings.json") | ||
|
||
""" | ||
if not self._analyze_backtest: | ||
return | ||
Comment on lines
+2908
to
+2909
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Initialization of analyze_backtest Flag
Tell me moreWhat is the issue?The code adds a check for Why this mattersWithout proper initialization, accessing Suggested change ∙ Feature PreviewAdd proper initialization of the def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._analyze_backtest = kwargs.get('analyze_backtest', True) # Default to True for backward compatibility 💬 Chat with Korbit by mentioning @korbit-ai. |
||
|
||
datasource = self.broker.data_source | ||
auto_adjust = datasource.auto_adjust if hasattr(datasource, "auto_adjust") else False | ||
settings = { | ||
|
@@ -2920,7 +2923,7 @@ def write_backtest_settings(self, settings_file: str): | |
"quote_asset": self.quote_asset, | ||
"benchmark_asset": self._benchmark_asset, | ||
"starting_positions": self.starting_positions, | ||
"parameters": self.parameters, | ||
"parameters": {k: v for k, v in self.parameters.items() if k != 'pandas_data'} | ||
} | ||
os.makedirs(os.path.dirname(settings_file), exist_ok=True) | ||
with open(settings_file, "w") as outfile: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import logging | ||
import os | ||
import sys | ||
from datetime import datetime | ||
from zoneinfo import ZoneInfo | ||
|
||
from lumibot.credentials import ALPACA_TEST_CONFIG | ||
from lumibot.backtesting import AlpacaBacktesting | ||
|
@@ -10,22 +10,21 @@ | |
|
||
if __name__ == "__main__": | ||
|
||
tickers = [ | ||
"BTC/USD", | ||
"AMZN" | ||
] | ||
start_date = "2021-01-01" | ||
end_date = "2021-01-10" | ||
# timestep = 'day' | ||
timestep = 'hour' | ||
# timestep = 'minute' | ||
datetime_start = datetime(2025, 1, 13) | ||
datetime_end = datetime(2025, 1, 18) | ||
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invalid Future Dates for Backtesting
Tell me moreWhat is the issue?The backtesting dates are set in the future (2025), which will result in no historical data being available for analysis. Why this mattersAlpaca will not be able to provide historical price data for future dates, causing the backtesting to fail or return empty results. Suggested change ∙ Feature PreviewChange the dates to a past time period where historical data is available. For example: datetime_start = datetime(2023, 1, 13)
datetime_end = datetime(2023, 1, 18) 💬 Chat with Korbit by mentioning @korbit-ai. |
||
timestep = 'day' | ||
tzinfo = ZoneInfo("America/New_York") | ||
tickers = "TSLA" | ||
refresh_cache = False | ||
warm_up_trading_days = 0 | ||
|
||
data_source = AlpacaBacktesting( | ||
datetime_start=datetime_start, | ||
datetime_end=datetime_end, | ||
config=ALPACA_TEST_CONFIG, | ||
tickers=tickers, | ||
start_date=start_date, | ||
end_date=end_date, | ||
timestep=timestep, | ||
config=ALPACA_TEST_CONFIG, | ||
refresh_cache=refresh_cache, | ||
tzinfo=tzinfo, | ||
warm_up_trading_days=warm_up_trading_days | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example Doesn't Demonstrate New Feature
Tell me more
What is the issue?
Setting analyze_backtest to False contradicts the developer's intent to add flexibility for backtest analysis.
Why this matters
Hard-coding this value to False in the example prevents users from seeing how to properly utilize the new analyze_backtest feature.
Suggested change ∙ Feature Preview
Either make the analyze_backtest parameter configurable or set it to True to demonstrate the feature:
💬 Chat with Korbit by mentioning @korbit-ai.