diff --git a/backtesting/backtest_iron_condor.py b/backtesting/backtest_iron_condor.py index 34e11f4..fe0d869 100644 --- a/backtesting/backtest_iron_condor.py +++ b/backtesting/backtest_iron_condor.py @@ -3,7 +3,7 @@ import os import pandas as pd from concurrent.futures import ProcessPoolExecutor -from datetime import datetime +from datetime import date, datetime, time from dotenv import load_dotenv from typing import List @@ -278,12 +278,13 @@ def backtest_iron_condor( filters: List[BacktestFilter] = [] ) -> pd.DataFrame: - start_year = start_date.year - end_year = end_date.year + # Setting dates to midnight to ensure all the data between them is included. + start_date = datetime.combine(start_date, time()) + end_date = datetime.combine(end_date, time()) futures = [] with ProcessPoolExecutor(max_workers = 10) as executor: - for year in range(start_year, end_year + 1): + for year in range(start_date.year, end_date.year + 1): year_directory = os.path.join(OPTION_DATA_DIRECTORY, str(year)) for file in os.listdir(year_directory): historical_data_file = os.path.join(year_directory, file) @@ -292,8 +293,6 @@ def backtest_iron_condor( # Assuming file format 'YYYY-MM-DD.csv'. current_date = datetime.strptime(os.path.splitext(file)[0], '%Y-%m-%d') - - # TODO: This doesn't work as expected when the start date is not set to midnight. if current_date < start_date or current_date > end_date: continue