From fb851d4d3f72b3db8284070496e79b6e9f83e158 Mon Sep 17 00:00:00 2001 From: fuzzyhandle Date: Mon, 3 Feb 2020 07:39:18 +0530 Subject: [PATCH] Special situations where weekend is a working day Market was open on 1st Feb 2020 on a Saturday. Add logic to handle such instances --- nsepy/live.py | 20 +++++++++++++++++++- tests/test_live.py | 6 ++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/nsepy/live.py b/nsepy/live.py index 206260e..4bc7797 100644 --- a/nsepy/live.py +++ b/nsepy/live.py @@ -202,5 +202,23 @@ def getworkingdays(dtfrom, dtto): stweekends.add(dt) # pdb.set_trace() + stspecial = set( + [datetime.date(2020,2,1) # Budget day + ] + ) + + #Remove special weekend working days from weekends set + stweekends -= stspecial stworking = (stalldays - stweekends) - set(dfholiday.index.values) - return sorted(stworking) + # stworking = (stalldays - stweekends) - set(dfholiday.index.values) + + # #Special cases where market was open on weekends + # stspecial = set( + # [datetime.date(2020,2,1) # Budget day + # ] + # ) + # for dtspecial in stspecial: + # if (dtspecial >= dtfrom and dtspecial <= dtto): + # stworking.add(dtspecial) + + return sorted(stworking) \ No newline at end of file diff --git a/tests/test_live.py b/tests/test_live.py index 0110cef..5057160 100644 --- a/tests/test_live.py +++ b/tests/test_live.py @@ -150,3 +150,9 @@ def test_working_day(self): workingdays = getworkingdays(datetime.date( 2019, 3, 1), datetime.date(2019, 3, 31)) self.assertEqual(len(workingdays), 19) + + # working day for special dates on weekend + workingdays = getworkingdays(datetime.date( + 2020, 1, 31), datetime.date(2020, 2, 3)) + self.assertEqual(len(workingdays), 3) + \ No newline at end of file