# Python for Finance
# useful links
# Python for finance
libraries
- jupyterlab
- notebook
- numpy
- pandas
- pandas-datareader
- beautifulsoup4
- scikit-learn / sklearn
- Plotly
import plotly.graph_objects as go
import pandas as pd
def create_chart(df):
fig = go.Figure(data=[go.Candlestick(x=df['Date'],
open=df['Open'],
high=df['High'],
low=df['Low'],
close=df['Close'])])
fig.update_layout(xaxis_rangeslider_visible=False)
fig.show()
if __name__ == '__main__':
create_chart(pd.read_csv('Shell.csv'))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
import mplfinance as mpf
style.use('ggplot')
start = dt.datetime(2020, 4, 1)
end = dt.datetime(2020, 5, 1)
df1 = web.DataReader('RDS-A', 'yahoo', start, end) # Royal Dutch Shell plc (RDS-A) - NYSE
df2 = web.DataReader('DAL', 'yahoo', start, end) # Delta Air Lines, Inc. (DAL) - NYSE
df3 = web.DataReader('HAL', 'yahoo', start, end) # Halliburton Company (HAL) - NYSE
# df1_csv = pd.read_csv('Shell.csv', parse_dates=True, index_col=0)
# print('From CSV - Royal Dutch Shell plc (RDS-A) - NYSE - NYSE Delayed Price. Currency in USD')
# # df1.to_csv('Shell.csv')
# # df2.to_csv('Delta.csv')
# # df3.to_csv('Halliburton.csv')
# print(df1_csv.head())
print('Royal Dutch Shell plc (RDS-A) - NYSE - NYSE Delayed Price. Currency in USD')
print(df1.head()) # get the first ones
print(df1.head(6))
print(df1.tail()) # get the last ones
# df1.plot()
# plt.show()
mpf.plot(df1, type='candle')
print('Delta Air Lines, Inc. (DAL) - NYSE - NYSE Delayed Price. Currency in USD')
print(df2.head()) # get the first ones
print(df2.tail()) # get the last ones
print('Halliburton Company (HAL) - NYSE - NYSE Delayed Price. Currency in USD')
print(df3.head()) # get the first ones
print(df3.tail()) # get the last ones
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
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
# Excluding weekends from the graph
We have to use rangebreaks.