Ensure that provided dates are set to midnight in order to include all the data for the requested dates

This commit is contained in:
moshferatu 2024-02-15 06:03:50 -08:00
parent 788f238530
commit 4e250ef57f

View File

@ -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