From 61811a97a945867e885e892991a4b7c552544d86 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Fri, 23 Feb 2024 14:09:36 -0800 Subject: [PATCH] Add script for computing the average slippage incurred for a given trading day --- slippage_analysis.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 slippage_analysis.py diff --git a/slippage_analysis.py b/slippage_analysis.py new file mode 100644 index 0000000..2c8f1b9 --- /dev/null +++ b/slippage_analysis.py @@ -0,0 +1,28 @@ +import datetime + +from database.trades import trades + +def average_entry_slippage(date: datetime): + trade_records = trades(date) + + slippages = [] + for spreads in trade_records['Spreads']: + for spread in spreads: + if 'Entry Slippage' in spread: + slippages.append(spread['Entry Slippage']) + + if slippages: + average_slippage = sum(slippages) / len(slippages) + return average_slippage + else: + return None + +if __name__ == "__main__": + target_date = datetime.date(2024, 2, 23) + + average_slippage = average_entry_slippage(target_date) + + if average_slippage is not None: + print(f"{target_date} Average Entry Slippage: {average_slippage}") + else: + print(f"No trades found for {target_date}.") \ No newline at end of file