-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperacion.py
More file actions
145 lines (121 loc) · 4.99 KB
/
operacion.py
File metadata and controls
145 lines (121 loc) · 4.99 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import math
import datetime as date
#from indicadores import *
from comision import *
from enum import Enum
class Tipo_operacion(Enum):
compra = 1
venta = 2
class Tipo_accion(Enum):
accionbyma = 1
cedear = 2
class operacion():
def __init__(self, ticket, valorTicket, datetime, cantidad = 1, typeOperacion = 'compra', tipo = 'accionbyma' ):
self.__ticket = ticket
self.__valorTicket = valorTicket
self.__datetime = datetime
self.__cantidad = cantidad
if(typeOperacion.lower() == 'compra' or typeOperacion.lower() == 'venta'):
self.__typeOperacion = typeOperacion.lower()
else:
self.__typeOperacion = 'compra'
print('****** EXCEPCION ******')
self.__comision = calculoComision(valorTicket, cantidad, tipo )
def getTicket(self):
return self.__ticket
def getCantidad(self):
return self.__cantidad
def getTypeOperacion(self):
return self.__typeOperacion
def getValorTicket (self):
return self.__valorTicket
def getDateTime(self):
return self.__datetime
def getComision(self):
return self.__comision
def getCostoOperacionNeto(self):
if(self.__typeOperacion == 'compra'):
#Operacion de compra del instrumento
return self.getCostoOperacionBruto() + self.getComision()
#Operacion de venta
return self.getCostoOperacionBruto() - self.getComision()
def getCostoOperacionBruto(self):
#Operacion sin comisiones
return self.getValorTicket() * self.getCantidad()
class operatiOnOnActve():
def __init__(self, ticket, tipo='accionbyma'):
self.__ticket = ticket
self.__tipo = tipo.lower()
self.__datoOperacion = []
def get_cantidad_operacion(self):
return len(self.__datoOperacion)
def get_lista_operacion(self):
#retorna el listado de operaciones realizadas
return self.__datoOperacion
@property
def string(self):
pass
def get_ticket(self):
return self.__ticket
def get_ganancia_bruto(self):
#retorna el valor de las operaciones sin las comisiones
resultado = 0 #Dinero puesto
for i in self.__datoOperacion:
if( i.getTypeOperacion == 'compra' ):
resultado -= i.getCostoOperacionBruto() #dinero gastado
else:
resultado += i.getCostoOperacionBruto() #dinero obtenido
return resultado
def get_ganancia_neta(self):
#retorna el valor de las operaciones con las comisiones incluidas
resultado = 0
for i in self.__datoOperacion:
if( i.getTypeOperacion() == 'compra' ):
resultado -= i.getCostoOperacionNeto() #dinero gastado
else:
resultado += i.getCostoOperacionNeto() #dinero obtenido
return resultado
def get_ganancia_porcentual(self):
#retorna el valor de las operaciones con las comisiones incluidas
resultado = 0
valor_compra = 0
valor_venta = 0
porcentaje = 0
for i in self.__datoOperacion:
if( i.getTypeOperacion() == 'compra' ):
valor_compra = i.getCostoOperacionNeto()
else:
valor_venta = i.getCostoOperacionNeto()
porcentaje = (valor_venta - valor_compra) / valor_compra
resultado += porcentaje
return round(resultado*100,2)
def get_cantidad_activos(self):
#print("obtiene la cantidad de papeles que se tiene (Ej: se compran 4, se venten 1, resultado: 3")
cnt = 0
for i in self.__datoOperacion:
if(i.getTypeOperacion() == 'compra'):
cnt = cnt + i.getCantidad()
else:
cnt = cnt - i.getCantidad()
return cnt
def load_operacion(self, valorTicketq, datetime=date.date.today(), cantidad=1, typeOperacion='compra' ):
p = operacion(self.__ticket, valorTicketq, datetime, cantidad, typeOperacion, tipo = self.__tipo )
self.__datoOperacion.append(p)
def get_day_in(self):
#Obtiene la cantidad de dias que se esta invertido
resultados = date.timedelta(0)
day_compra = None
day_venta = None
for i in self.__datoOperacion:
if( i.getTypeOperacion() == 'compra' ):
day_compra = i.getDateTime() #Fecha de la compra
else:
day_venta = i.getDateTime() #Fecha de venta
if(day_compra != None and day_venta != None):
diferencia = day_venta - day_compra
day_venta = None
day_venta = None
resultados = diferencia + resultados
return( resultados.days )
def get_ganacia_porcentual_diario(self):
return round(self.get_ganancia_porcentual() / self.get_day_in(), 4)