Skip to content

Commit

Permalink
fix: bad week end count when crossing years
Browse files Browse the repository at this point in the history
  • Loading branch information
loiccoyle committed Jan 3, 2025
1 parent d749b6a commit 08cb292
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tinyticker/tickers/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def _get_yfinance_start_end(self) -> Tuple[pd.Timestamp, pd.Timestamp]:
start -= pd.to_timedelta("1d") * n_trade_days
# if we passed a weekend, add 2 days and a bit more because the added days can themselves
# be weekends
start -= pd.to_timedelta("2d") * (end.week - start.week) * 1.5
n_weekends = len(pd.bdate_range(start, end, freq="C", weekmask="Sat Sun"))
start -= pd.to_timedelta("2d") * (n_weekends) * 1.5
# go back before weekend
# start.weekday() returns 6 for Sunday, and 5 for Saturday
# max(0, start.weekday() - 4) is 0 for Mon-Fri, 1 for Sat, 2 for Sun
Expand Down

0 comments on commit 08cb292

Please sign in to comment.