-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAmznVSGoog.py
159 lines (113 loc) · 4.6 KB
/
AmznVSGoog.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import requests
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from matplotlib.patches import Rectangle
from matplotlib.gridspec import GridSpec
def wget(url):
r = requests.get(url, allow_redirects=True)
with open(url[url.rfind('/') + 1::], 'wb') as f:
f.write(r.content)
def chart_candlestick (openp, close, high, low, date, i):
price_coordinates = [high, low]
date_coordinates = [date, date]
plt.plot(date_coordinates, price_coordinates, color="black")
#plt.scatter(date, high, color="green")
#plt.scatter(date, low, color="#ff0004")
#plt.scatter(date, openp, color="#4bed15")
#plt.scatter(date, close, color="#ad0a0d")
candlestick = bull_or_bear(openp, close)
if (candlestick == "bull"):
color = "#5DFD5B"
if (candlestick == "bear"):
color = "#FF7051"
if (candlestick == "indesicion"):
color = "#DEDEDE"
plt.gca().add_patch(Rectangle((i-0.5,openp),1,(close-openp),linewidth=0.5,edgecolor='black',facecolor=color))
def chart_candlestick_amzn (openp, close, high, low, date, i):
price_coordinates = [high, low]
date_coordinates = [date, date]
plt.plot(date_coordinates, price_coordinates, color="black")
#plt.scatter(date, high, color="green")
#plt.scatter(date, low, color="#ff0004")
#plt.scatter(date, openp, color="#4bed15")
#plt.scatter(date, close, color="#ad0a0d")
candlestick = bull_or_bear(openp, close)
if (candlestick == "bull"):
color = "#3855C2"
if (candlestick == "bear"):
color = "#C238AF"
if (candlestick == "indesicion"):
color = "#DEDEDE"
plt.gca().add_patch(Rectangle((i-0.5,openp),1,(close-openp),linewidth=0.5,edgecolor='black',facecolor=color))
def bull_or_bear(openp, close):
if(openp > close):
return("bear")
if(openp < close):
return("bull")
if(close == openp):
return("indesicion")
def match (google_high, google_low, amzn_high, amzn_low, i):
if (google_low > amzn_high):
return("No match")
if (amzn_low > google_high):
return("No match")
if(google_high > amzn_high > google_low > amzn_low):
match_square(amzn_high, google_low, i)
if (amzn_high > google_high > amzn_low > google_low):
match_square(google_high, amzn_low, i)
if(amzn_high > google_high and google_low > amzn_low):
match_square(google_high, google_low, i)
if (google_high > amzn_high and amzn_low > google_low):
match_square(amzn_high, google_low, i)
def match_square (mini, maxi, i):
plt.gca().add_patch(Rectangle((i-0.5,mini),1,(maxi-mini),linewidth=0.5,edgecolor='black',facecolor='#ECFF00'))
def derivada_discreta(open_price, close_price, date):
#Voy a hacer la derivada discreta entre el precio de cierre y el precio de apertura para ver si hay un gap
lista_gap = []
lista_aux = []
lista_date = []
for i in range (0, len(date), 1):
lista_aux.append(open_price[i])
lista_date.append(date[i])
lista_aux.append(close_price[i])
lista_date.append(date[i])
for i in range(0, len(open_price)-1, 1):
lista_gap.append(close_price[i] - open_price[i+1])
plt.plot(lista_date, lista_aux)
wget("https://raw.githubusercontent.com/LedesmaFran/python/master/GOOGLE.csv")
archivo_google = pd.read_csv("GOOGLE.csv")
data_google = archivo_google.to_dict("list")
google_high = data_google["High"]
google_low = data_google["Low"]
google_date = data_google["Date"]
google_open = data_google["Open"]
google_close = data_google["Close"]
google_volume = data_google["Volume"]
wget("https://raw.githubusercontent.com/LedesmaFran/python/master/AMZN.csv")
archivo_amzn = pd.read_csv("AMZN.csv")
data_amzn = archivo_amzn.to_dict("list")
amzn_high = data_amzn["High"]
amzn_low = data_amzn["Low"]
amzn_date = data_amzn["Date"]
amzn_open = data_amzn["Open"]
amzn_close = data_amzn["Close"]
for i in range(0, len(google_close), 1):
chart_candlestick(google_open[i], google_close[i], google_high[i], google_low[i], google_date[i], i)
for i in range(0, len(amzn_close), 1):
chart_candlestick_amzn(amzn_open[i], amzn_close[i], amzn_high[i], amzn_low[i], amzn_date[i], i)
for i in range(0, len(amzn_close), 1):
match(google_high[i], google_low[i], amzn_high[i], amzn_low[i], i)
'''derivada_discreta(amzn_open, amzn_close, amzn_date)'''
#Google bull #5DFD5B verde
#Google bear #FF7051 rojo
#Amzn bull #3855C2 azul
#Amzn bear #C238AF violeta
#Match #ECFF00 amarillo
plt.xticks(rotation=45)
plt.title("Google vs Amazon")
plt.xlabel("Tiempo")
plt.ylabel("Precio")
plt.legend()
plt.show()