-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
32 lines (26 loc) · 941 Bytes
/
utils.py
File metadata and controls
32 lines (26 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class dotdict(dict):
"""dot.notation access to dictionary attributes"""
__getattr__ = dict.get
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
import pandas as pd
from datetime import date, datetime , timedelta
def datetosymbol(ed):
d = str(ed).replace('-', '')[2:]
c = ['O', 'N', 'D']
if ed.month > 9:
a = str(ed.year - 2000) + c[ed.month - 10] + d[-2:]
else:
a = str(ed).replace('-', '')[2:].replace('0', '', 1)
return a
def findexpiry(expiry):
holidays = pd.read_csv('nse_holidays.csv')
hl = [str(datetime.strptime(j, '%d-%b-%Y').date()).replace('-', '')[2:].replace('0', '', 1) for j in holidays.Date]
while expiry.weekday()!=3:
expiry+=timedelta(days=1)
expstr = datetosymbol(expiry.date())
while expstr in hl:
#go to previous day
expiry-=timedelta(days=1)
expstr = datetosymbol(expiry.date())
return expstr