-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
64 lines (44 loc) · 2.36 KB
/
__init__.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#AlgoFnO Library for Delivery Data and Derivative Data Analysis
#=============================================================================================
import csv
import os
import glob
import pandas as pd
#=============================================================================================
class insertData:
#=============================================================================================
def insertCM(self,folder,ticker):
location = folder+'/'+"cm*.csv"
files = os.path.join(location)
files = glob.glob(files)
df = pd.concat(map(pd.read_csv, files), ignore_index=True)
df =df.loc[df['SYMBOL']==ticker]
return df
#=============================================================================================
def insertFO(self,folder,ticker):
location = folder+'/'+"fo*.csv"
files = os.path.join(location)
files = glob.glob(files)
df = pd.concat(map(pd.read_csv, files), ignore_index=True)
df = df.loc[df['SYMBOL']==ticker]
df = df.loc[df['INSTRUMENT']=='FUTSTK']
df = df.groupby(['TIMESTAMP']).sum()
return df
#=============================================================================================
class BhavCopyAnalysis:
#=============================================================================================
def doAnalysis(self,folder,tickerList):
for ticker in tickerList:
insertDataObject = insertData()
dataFrameCM = insertDataObject.insertCM(folder,ticker)
dataFrameFO = insertDataObject.insertFO(folder,ticker)
result = pd.merge(dataFrameCM, dataFrameFO, on='TIMESTAMP', how='outer')
result['%_OI_change'] = (result['CHG_IN_OI'] / result['OPEN_INT'])*100
result['Quantity/Trades'] = (result['TOTTRDQTY'] / result['TOTALTRADES'])*100
result['%_Price_change'] = ((result['CLOSE_x']-result['PREVCLOSE']) / result['PREVCLOSE'])*100
cols = [1,6,12,13,14,15,16,17,18,19,20,21]
result.drop(result.columns[cols],axis=1,inplace=True)
result = result.sort_values(by=['TIMESTAMP'], ascending=False)
location = folder + '/FnOAnalysisFor_' + ticker + '.csv'
result.to_csv(location)
#=============================================================================================