-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstockgrapher.py
68 lines (40 loc) · 1.54 KB
/
stockgrapher.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
#numerical python to deal with array
#(array is defined as a collection of items that are stored at contiguous memory locations)
import numpy as np
#pandas is known as data analysis library.
#pandas is used to manipulate data frames.
import pandas as pd
#yfinance is used to download historical market data from yahoo finance.
import yfinance as yf
#plotly is used to create interactive plots.
#plotly express is a high-level interface to plotly, which operates on "tidy" data and produces easy-to-style figures.
import plotly.graph_objs as go
#download historical data for required stocks
data = yf.download(tickers='BTC-USD', period='2d', interval='60m')
fig =go.Figure()
#Candlestick chart
fig.add_trace(go.Candlestick(x=data.index,
open=data['Open'],
high=data['High'],
low=data['Low'],
close=data['Close'], name = 'market data'))
# Add titles
fig.update_layout(
title='Bitcoin',
yaxis_title='BTC-USD')
# X-Axes
fig.update_xaxes(
rangeslider_visible=True,
rangeselector=dict(
buttons=list([
dict(count=1, label="1m", step="month", stepmode="backward"),
dict(count=6, label="6m", step="month", stepmode="backward"),
dict(count=1, label="YTD", step="year", stepmode="todate"),
dict(count=1, label="1y", step="year", stepmode="backward"),
dict(step="all")
])
)
)
# Show plot
fig.show()
#save the plot as html file