-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstagnancy_graph.py
125 lines (107 loc) · 3.45 KB
/
stagnancy_graph.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
import plotly.graph_objs as go
import plotly
from stock_general_research import StockGeneralResearcher
def get_graph(ticker_symbol, high_data, low_data, dates):
"""
Makes graph for multiple months. Returns a string div.
:param dates: dates data goes back to
:param low_data: data for stock lows
:param high_data: data for stock highs
"""
#stock_general = StockGeneralResearcher(ticker_symbol)
trace_high = go.Scatter(
x=dates,
y=high_data,
name="%s High" % ticker_symbol,
line=dict(color='#17BECF'),
opacity=0.8)
trace_low = go.Scatter(
x=dates,
y=low_data,
name="%s Low" % ticker_symbol,
line=dict(color='#7F7F7F'),
opacity=0.8)
data = [trace_high, trace_low]
layout = dict(
#title='%s Stock Time Series Graph' % stock_general.get_company_name()'
title='%s Stock Time Series Graph' % ticker_symbol,
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=1,
label='1m',
step='month',
stepmode='backward'),
dict(count=3,
label='3m',
step='month',
stepmode='backward'),
dict(count=6,
label='6m',
step='month',
stepmode='backward'),
dict(count=9,
label='9m',
step='month',
stepmode='backward'),
dict(count=24,
label='24m',
step='month',
stepmode='backward'),
dict(step='all')
])
),
rangeslider=dict(
visible=False
),
title='Time',
type='date'
),
yaxis=dict(
title='Stock Price',
type='linear'
)
)
fig = dict(data=data, layout=layout)
div = plotly.offline.plot(fig, output_type='div')
return div
def get_custom_graph(ticker_symbol, past_months, high_data, low_data, dates):
"""
Makes graph for given past months of a stock. Returns a string div.
:param dates: dates data goes back to
:param low_data: data for stock lows
:param high_data: data for stock highs
:param past_months: Number of months graph goes back.
"""
#stock_general = StockGeneralResearcher(ticker_symbol)
trace_high = go.Scatter(
x=dates,
y=high_data,
name="%s High" % ticker_symbol,
line=dict(color='#17BECF'),
opacity=0.8)
trace_low = go.Scatter(
x=dates,
y=low_data,
name="%s Low" % ticker_symbol,
line=dict(color='#7F7F7F'),
opacity=0.8)
data = [trace_high, trace_low]
layout = dict(
title='%s Stock Graph For Past %i Months' % (ticker_symbol, past_months),
#title='Stock Graph For Past %i Months' % (past_months),
xaxis=dict(
rangeslider=dict(
visible=False
),
title='Time',
type='date'
),
yaxis=dict(
title='Stock Price',
type='linear'
)
)
fig = dict(data=data, layout=layout)
div = plotly.offline.plot(fig, output_type='div')
return div