Ensure that provided dates are set to midnight in order to include all the data for the requested dates
This commit is contained in:
parent
788f238530
commit
4e250ef57f
@ -3,7 +3,7 @@ import os
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from concurrent.futures import ProcessPoolExecutor
|
from concurrent.futures import ProcessPoolExecutor
|
||||||
from datetime import datetime
|
from datetime import date, datetime, time
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
@ -278,12 +278,13 @@ def backtest_iron_condor(
|
|||||||
filters: List[BacktestFilter] = []
|
filters: List[BacktestFilter] = []
|
||||||
) -> pd.DataFrame:
|
) -> pd.DataFrame:
|
||||||
|
|
||||||
start_year = start_date.year
|
# Setting dates to midnight to ensure all the data between them is included.
|
||||||
end_year = end_date.year
|
start_date = datetime.combine(start_date, time())
|
||||||
|
end_date = datetime.combine(end_date, time())
|
||||||
|
|
||||||
futures = []
|
futures = []
|
||||||
with ProcessPoolExecutor(max_workers = 10) as executor:
|
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))
|
year_directory = os.path.join(OPTION_DATA_DIRECTORY, str(year))
|
||||||
for file in os.listdir(year_directory):
|
for file in os.listdir(year_directory):
|
||||||
historical_data_file = os.path.join(year_directory, file)
|
historical_data_file = os.path.join(year_directory, file)
|
||||||
@ -292,8 +293,6 @@ def backtest_iron_condor(
|
|||||||
|
|
||||||
# Assuming file format 'YYYY-MM-DD.csv'.
|
# Assuming file format 'YYYY-MM-DD.csv'.
|
||||||
current_date = datetime.strptime(os.path.splitext(file)[0], '%Y-%m-%d')
|
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:
|
if current_date < start_date or current_date > end_date:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user