-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgains.py
125 lines (73 loc) · 3.38 KB
/
gains.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
125
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 28 15:34:06 2018
@author: blue
"""
from pandas import read_csv
from numpy import dot, where
from argparse import ArgumentParser
def getArgs():
parser = ArgumentParser()
parser.add_argument("--end", type=str, default=None,
help="End date to calculate accountability")
parser.add_argument("--init", type=str, default=None,
help = "init data to calculate accountability")
return parser.parse_args()
def get_obtained(frame, members, init=None, end=None):
cols = len(members['Ticker symbol'])
if init==None and end==None:
old_quants = frame.iloc[-2][1:(cols+1)].values
new_prices = frame.iloc[-1][(cols+1):(2*cols+1)]
old_prices = frame.iloc[-2][(cols+1):(2*cols+1)]
fees = frame.iloc[-2]['Total']
new_value = dot(old_quants, new_prices)
old_value = dot(old_quants, old_prices)
obtained = new_value-old_value -fees
elif init==None:
idx = list(where(frame[frame.columns[0]]==end))[0][0]
accumulated = 0
for i in range(1,idx+1):
old_quants = frame.iloc[i-1][1:(cols+1)].values
new_prices = frame.iloc[i][(cols+1):(2*cols+1)]
old_prices = frame.iloc[i-1][(cols+1):(2*cols+1)]
fees = frame.iloc[i-1]['Total']
new_value = dot(old_quants, new_prices)
old_value = dot(old_quants, old_prices)
obtain_1round = new_value-old_value -fees
accumulated += obtain_1round
obtained = accumulated
elif end==None:
idx= list(where(frame[frame.columns[0]]==init))[0][0]
accumulated = 0
for i in range(idx+1,len(frame)):
old_quants = frame.iloc[i-1][1:(cols+1)].values
new_prices = frame.iloc[i][(cols+1):(2*cols+1)]
old_prices = frame.iloc[i-1][(cols+1):(2*cols+1)]
fees = frame.iloc[i-1]['Total']
new_value = dot(old_quants, new_prices)
old_value = dot(old_quants, old_prices)
obtain_1round = new_value-old_value -fees
accumulated += obtain_1round
obtained = accumulated
else:
idx_init = list(where(frame[frame.columns[0]]==init))[0][0]
idx_end = list(where(frame[frame.columns[0]]==end))[0][0]
accumulated = 0
for i in range(idx_init+1,idx_end+1):
old_quants = frame.iloc[i-1][1:(cols+1)].values
new_prices = frame.iloc[i][(cols+1):(2*cols+1)]
old_prices = frame.iloc[i-1][(cols+1):(2*cols+1)]
fees = frame.iloc[i-1]['Total']
new_value = dot(old_quants, new_prices)
old_value = dot(old_quants, old_prices)
obtain_1round = new_value-old_value -fees
accumulated += obtain_1round
obtained = accumulated
return obtained
if __name__=="__main__":
args = getArgs()
frame = read_csv("./accountability.csv")
members = read_csv("./csv/members_IBEX35.csv")
obtained = get_obtained(frame, members, init=args.init, end = args.end)
print(obtained)