Upload 1708_159_252.py
Browse files- 1708_159_252.py +87 -0
1708_159_252.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""1708.159.252
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/11rYVHhKlJ8F_hnmnVtTOUNsLA8pk8Pn6
|
8 |
+
"""
|
9 |
+
|
10 |
+
!pip install mplfinance
|
11 |
+
|
12 |
+
import pandas as pd
|
13 |
+
import matplotlib.pyplot as plt
|
14 |
+
import seaborn as sns
|
15 |
+
from mplfinance.original_flavor import candlestick_ohlc
|
16 |
+
import matplotlib.dates as mdates
|
17 |
+
|
18 |
+
data = pd.read_csv('/content/berkshire_hathaway_data.csv')
|
19 |
+
|
20 |
+
data.isnull().sum()
|
21 |
+
data = data.dropna()
|
22 |
+
data.dtypes
|
23 |
+
|
24 |
+
data['Date'] = pd.to_datetime(data['Date'])
|
25 |
+
|
26 |
+
plt.figure(figsize=(10, 6))
|
27 |
+
plt.plot(data['Date'], data['Close'], label='Close Price')
|
28 |
+
plt.xlabel('Date')
|
29 |
+
plt.ylabel('Close Price')
|
30 |
+
plt.title('Close Price Over Time')
|
31 |
+
plt.legend()
|
32 |
+
plt.grid(True)
|
33 |
+
plt.show()
|
34 |
+
|
35 |
+
ohlc = data[['Date', 'Open', 'High', 'Low', 'Close']]
|
36 |
+
ohlc['Date'] = ohlc['Date'].map(mdates.date2num)
|
37 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
38 |
+
candlestick_ohlc(ax, ohlc.values, width=0.6, colorup='g', colordown='r')
|
39 |
+
ax.xaxis_date()
|
40 |
+
ax.set_xlabel('Date')
|
41 |
+
ax.set_ylabel('Price')
|
42 |
+
ax.set_title('Candlestick Chart')
|
43 |
+
plt.grid(True)
|
44 |
+
plt.show()
|
45 |
+
|
46 |
+
plt.figure(figsize=(10, 6))
|
47 |
+
plt.bar(data['Date'], data['Volume'], label='Volume')
|
48 |
+
plt.xlabel('Date')
|
49 |
+
plt.ylabel('Volume')
|
50 |
+
plt.title('Volume Over Time')
|
51 |
+
plt.legend()
|
52 |
+
plt.grid(True)
|
53 |
+
plt.show()
|
54 |
+
|
55 |
+
data['MA50'] = data['Close'].rolling(window=50).mean()
|
56 |
+
plt.figure(figsize=(10, 6))
|
57 |
+
plt.plot(data['Date'], data['Close'], label='Close Price')
|
58 |
+
plt.plot(data['Date'], data['MA50'], label='50-Day MA')
|
59 |
+
plt.xlabel('Date')
|
60 |
+
plt.ylabel('Price')
|
61 |
+
plt.title('Close Price and 50-Day Moving Average')
|
62 |
+
plt.legend()
|
63 |
+
plt.grid(True)
|
64 |
+
plt.show()
|
65 |
+
|
66 |
+
plt.figure(figsize=(10, 6))
|
67 |
+
plt.scatter(data['High'], data['Low'], alpha=0.5, label='High vs. Low')
|
68 |
+
plt.xlabel('High Price')
|
69 |
+
plt.ylabel('Low Price')
|
70 |
+
plt.title('High vs. Low Price')
|
71 |
+
plt.legend()
|
72 |
+
plt.grid(True)
|
73 |
+
plt.show()
|
74 |
+
|
75 |
+
plt.figure(figsize=(10, 6))
|
76 |
+
plt.scatter(data['Open'], data['Close'], alpha=0.5, label='Open vs. Close')
|
77 |
+
plt.xlabel('Open Price')
|
78 |
+
plt.ylabel('Close Price')
|
79 |
+
plt.title('Open vs. Close Price')
|
80 |
+
plt.legend()
|
81 |
+
plt.grid(True)
|
82 |
+
plt.show()
|
83 |
+
|
84 |
+
plt.figure(figsize=(10, 6))
|
85 |
+
sns.heatmap(data.corr(), annot=True, cmap='coolwarm', vmin=-1, vmax=1)
|
86 |
+
plt.title('Correlation Heatmap')
|
87 |
+
plt.show()
|