diff --git a/src/pages/journal/trading_journal_page.py b/src/pages/journal/trading_journal_page.py index f2cc4c2..52539ab 100644 --- a/src/pages/journal/trading_journal_page.py +++ b/src/pages/journal/trading_journal_page.py @@ -13,15 +13,19 @@ def calculate_weekly_metrics(trades) -> dict: """Calculate weekly performance metrics""" now = datetime.now(pytz.timezone('US/Pacific')) week_start = (now - timedelta(days=now.weekday())).replace(hour=0, minute=0, second=0, microsecond=0) + week_start = pytz.timezone('US/Pacific').localize(week_start) weekly_pl = 0 weekly_trades = [] for trade in trades: - # For sells/exits that happened this week - if (trade.get('direction') == 'sell' or trade.get('exit_price')) and \ - trade.get('exit_date', trade.get('entry_date')) >= week_start: + # Get the trade date and ensure it's timezone aware + trade_date = trade.get('exit_date', trade.get('entry_date')) + if trade_date and not trade_date.tzinfo: + trade_date = pytz.timezone('US/Pacific').localize(trade_date) + # For sells/exits that happened this week + if (trade.get('direction') == 'sell' or trade.get('exit_price')) and trade_date and trade_date >= week_start: price = float(trade.get('exit_price') or trade.get('entry_price')) shares = float(trade['shares']) position_id = trade['position_id']