From 57b446924e0a44d3545705e7ee5dcc58416644e0 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Tue, 27 Feb 2024 19:39:37 -0800 Subject: [PATCH] Update slippage analysis with exit slippage if any trades were stopped out on the specified date --- slippage_analysis.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/slippage_analysis.py b/slippage_analysis.py index 4777241..4fa4a35 100644 --- a/slippage_analysis.py +++ b/slippage_analysis.py @@ -2,27 +2,32 @@ import datetime from database.trades import trades -def average_slippage(date: datetime): +def average_slippage(date: datetime.date): trade_records = trades(date) - slippages = [] + entry_slippages = [] + exit_slippages = [] for spreads in trade_records['Spreads']: for spread in spreads: if 'Entry Slippage' in spread: - slippages.append(spread['Entry Slippage']) + entry_slippages.append(spread['Entry Slippage']) + if 'Exit Slippage' in spread: + exit_slippages.append(spread['Exit Slippage']) - if slippages: - average_slippage = sum(slippages) / len(slippages) - return average_slippage - else: - return None + average_entry_slippage = sum(entry_slippages) / len(entry_slippages) if entry_slippages else None + average_exit_slippage = sum(exit_slippages) / len(exit_slippages) if exit_slippages else None + + return average_entry_slippage, average_exit_slippage if __name__ == '__main__': - target_date = datetime.date(2024, 2, 23) + target_date = datetime.date(2024, 2, 27) - average_slippage = average_slippage(target_date) + entry_slippage, exit_slippage = average_slippage(target_date) - if average_slippage is not None: - print(f'{target_date} Average Entry Slippage: {average_slippage}') + if entry_slippage is not None: + print(f'Average Entry Slippage: {entry_slippage}') + + if exit_slippage is not None: + print(f'Average Exit Slippage: {exit_slippage}') else: print(f'No trades found for {target_date}.') \ No newline at end of file