2024-01-31 17:49:14 +00:00
|
|
|
from database.backtest import backtest_results
|
|
|
|
from database.procedures import backtest_profit, most_recent_trade_date
|
|
|
|
from database.trades import trades
|
2024-02-03 14:00:07 +00:00
|
|
|
|
|
|
|
symbol = 'SPX'
|
2024-01-31 17:49:14 +00:00
|
|
|
|
|
|
|
trade_date = most_recent_trade_date()
|
|
|
|
print(f'Trade Date: {trade_date}')
|
|
|
|
|
|
|
|
trade_data = trades(trade_date)
|
|
|
|
|
2024-02-17 13:56:42 +00:00
|
|
|
strategy = trade_data['Strategy'].iloc[0]
|
|
|
|
|
2024-02-03 14:00:07 +00:00
|
|
|
traded_entry_times = set()
|
2024-01-31 17:49:14 +00:00
|
|
|
for _, trade in trade_data.iterrows():
|
2024-02-03 14:00:07 +00:00
|
|
|
entry_time = str(trade["Entry Time"])[-8:]
|
|
|
|
print(f'Entry Time: {entry_time}')
|
|
|
|
traded_entry_times.add(entry_time)
|
2024-01-31 17:49:14 +00:00
|
|
|
|
|
|
|
spreads = trade['Spreads']
|
|
|
|
for spread in spreads:
|
|
|
|
legs = spread['Legs']
|
|
|
|
open_price = spread['Open']
|
|
|
|
|
|
|
|
# Assuming the first leg is always short and the second is long.
|
|
|
|
short_leg = legs[0]
|
|
|
|
long_leg = legs[1]
|
|
|
|
|
|
|
|
print(f' Short Strike: {short_leg["Strike"]}, Type: {short_leg["Type"]}')
|
|
|
|
print(f' Long Strike: {long_leg["Strike"]}, Type: {long_leg["Type"]}')
|
|
|
|
print(f' Opening Price: {open_price}')
|
|
|
|
|
2024-02-03 14:00:07 +00:00
|
|
|
backtest_data = backtest_results(symbol, strategy, trade_date)
|
2024-01-31 17:49:14 +00:00
|
|
|
|
|
|
|
for _, backtest in backtest_data.iterrows():
|
2024-02-03 14:00:07 +00:00
|
|
|
entry_time = str(backtest["Entry Time"])[-8:]
|
|
|
|
if entry_time in traded_entry_times:
|
|
|
|
print(f'Backtest Entry Time: {entry_time}')
|
2024-01-31 17:49:14 +00:00
|
|
|
|
|
|
|
spreads = backtest['Spreads']
|
|
|
|
for spread in spreads:
|
2024-02-03 14:00:07 +00:00
|
|
|
legs = spread['Legs']
|
|
|
|
open_price = spread['Open']
|
2024-01-31 17:49:14 +00:00
|
|
|
|
|
|
|
short_leg = legs[0]
|
|
|
|
long_leg = legs[1]
|
|
|
|
|
2024-02-03 14:00:07 +00:00
|
|
|
print(f' Backtest Short Strike: {short_leg["Strike"]}, Type: {short_leg["Type"]}')
|
|
|
|
print(f' Backtest Long Strike: {long_leg["Strike"]}, Type: {long_leg["Type"]}')
|
2024-01-31 17:49:14 +00:00
|
|
|
print(f' Backtest Opening Price: {open_price}')
|
|
|
|
|
2024-02-03 14:04:58 +00:00
|
|
|
print(f'Backtest Profit: {backtest_profit(trade_date)}')
|