14 lines
730 B
Python
14 lines
730 B
Python
|
from database.backtest import backtest_results
|
||
|
from datetime import datetime, timedelta
|
||
|
|
||
|
def best_entry_times(lookback_period: int = 10):
|
||
|
end_date = datetime.now().replace(hour = 0, minute = 0, second = 0, microsecond = 0)
|
||
|
start_date = end_date - timedelta(days = lookback_period)
|
||
|
|
||
|
backtest = backtest_results('SPX', '10 Delta Iron Condor', start_date = start_date, end_date = end_date)
|
||
|
backtest['Entry Time'] = backtest['Entry Time'].dt.time
|
||
|
|
||
|
profit_by_entry_time = backtest.groupby('Entry Time')['Profit'].sum().reset_index()
|
||
|
|
||
|
best_entry_times = profit_by_entry_time.sort_values(by='Profit', ascending=False).head(10)
|
||
|
return [str(entry_time) for entry_time in best_entry_times['Entry Time'].tolist()]
|