-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModifier.py
124 lines (108 loc) · 4.88 KB
/
Modifier.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import csv
def dataorg(file):
transbytick = {}
data = open(file)
csv_data = csv.reader(data)
for row in csv_data:
if row[1] != "Money Movement":
details = row[2].split(' ')
odate = row[0]
fee = row[4]
if row[1].split(' ')[0] == "Trade":
ticker = details[2]
exdate = details[3].lstrip("0")
if details[0] == "Bought":
buysell = "B"
elif details[0] == "Sold":
buysell = "S"
if details[4] == "Call":
callput = "C"
elif details[4] == "Put":
callput = "P"
strike = details[5]
premium = details[7]
contracts = details[1]
elif row[1].split(' ')[0] == "Receive":
ticker = row[1].split(' ')[2]
if details[-1] == "expiration.":
exdate = details[4].lstrip("0")
premium = "$0.00"
buysell = "expired"
callput = details[5][0]
strike = details[6]
contracts = details[2]
elif details[-1] != "exercise" and details[-1] != "assignment":
exdate = row[0].split()[0].lstrip("0")
premium = row[3]
if details[0] == "Bought":
buysell = "S"
elif details[0] == "Sold":
buysell = "B"
callput = "Assigned"
strike = details[-1]
contracts = int(details[3])/100
if ticker in transbytick:
if exdate in transbytick[ticker]:
if strike in transbytick[ticker][exdate]:
if callput in transbytick[ticker][exdate][strike]:
if odate > transbytick[ticker][exdate][strike][callput][0][0]:
placeholder = transbytick[ticker][exdate][strike][callput][0]
transbytick[ticker][exdate][strike][callput] = [[placeholder[0], placeholder[1], placeholder[2], placeholder[3], placeholder[4]+fee, premium, odate]]
elif odate == transbytick[ticker][exdate][strike][callput][0][0]:
print(ticker)
print(transbytick[ticker][exdate][strike][callput][0][0])
transbytick[ticker][exdate][strike][callput] += [[odate, buysell, premium, contracts, fee]]
else:
transbytick[ticker][exdate][strike][callput] = [[odate, buysell, premium, contracts, fee]]
else:
transbytick[ticker][exdate][strike] = {callput: [[odate, buysell, premium, contracts, fee]]}
else:
transbytick[ticker][exdate] = {strike: {callput: [[odate, buysell, premium, contracts, fee]]}}
else:
transbytick[ticker] = {exdate: {strike: {callput: [[odate, buysell, premium, contracts, fee]]}}}
print("--------------Results-------------------")
for key in transbytick:
print("Ticker ================"+key+"-------------------")
for seckey in transbytick[key]:
print(" Exp Date =========="+seckey+"----------------------")
for thirkey in transbytick[key][seckey]:
print(" Strike ==========" + thirkey + "----------------------")
for fourthkey in transbytick[key][seckey][thirkey]:
print(" Contract ==========" + fourthkey + "----------------------")
print(" "+str(transbytick[key][seckey][thirkey][fourthkey]))
def remake(file):
rerowed = []
data = open(file)
csv_data = csv.reader(data)
for row in csv_data:
print("------->"+row[1])
if row[1] != "Money Movement":
newrow = []
details = row[2].split(' ')
print(details)
ticker = details[2]
odate = row[0].split(' ')[0]
exdate = details[3]
if details[0] == "Bought":
buysell = "B"
elif details[0] == "Sold":
buysell = "S"
if details[4] == "Call":
callput = "C"
elif details[4] == "Put":
callput = "P"
strike = details[5]
premium = details[7]
contracts = details[1]
fee = row[4]
newrow = [ticker,odate,exdate,callput,buysell,strike,premium,contracts,fee]
rerowed += [newrow]
return rerowed
def cvsprinter(list):
with open("remastered.csv", "w", newline='') as f:
writer = csv.writer(f)
writer.writerows(list)
def main():
inp = input("filename:")
dataorg(inp)
main()