Active stocks of most popular companies were analyzed in the period from Octuber 1 to Octuber 25, 2021.
import time
import datetime
import pandas as pd
import plotly.express as px
Financial variables: Date, Open, High, Low, Close (close price adjusted for splits), Adj Close (Adjusted close price adjusted for splits and dividend and/or capital gain distributions), Volume. Currency in USD.
Set the company of interest in the ticker variable.
# Set the parameters to dowload Yahoo Finance data
# Yahoo Finance: historical prices from selected company
# Set the company of interes:
ticker = 'TSLA'
# Convert string to mktime
period1 = int(time.mktime(datetime.datetime.strptime("01/01/2021", "%d/%m/%Y").timetuple()))
period2 = int(time.mktime(datetime.datetime.strptime("25/10/2021", "%d/%m/%Y").timetuple()))
interval = '1d'
# Read data from web and create DataFrame
query_string = f'https://query1.finance.yahoo.com/v7/finance/download/{ticker}?period1={period1}&period2={period2}&interval={interval}&events=history&includeAdjustedClose=true'
df = pd.read_csv(query_string)
# Output data into CSV
df.to_csv('./YahooFinances_TSLA.csv')
df = pd.read_csv('./Stocks_Companies_YahooFinance.csv', header = 0)
Table 1. Stocks of popular companies.
df.head(10)
Company | Date | Close | Adj Close | Volume | Daily Return | % Daily Return | |
---|---|---|---|---|---|---|---|
0 | AAPL | 10/1/2021 | 142.65 | 142.65 | 94639600 | 0.01 | 0.81 |
1 | AAPL | 10/4/2021 | 139.14 | 139.14 | 98322000 | -0.02 | -2.49 |
2 | AAPL | 10/5/2021 | 141.11 | 141.11 | 80861100 | 0.01 | 1.41 |
3 | AAPL | 10/6/2021 | 142.00 | 142.00 | 83221100 | 0.01 | 0.63 |
4 | AAPL | 10/7/2021 | 143.29 | 143.29 | 61732700 | 0.01 | 0.90 |
5 | AAPL | 10/8/2021 | 142.90 | 142.90 | 58718700 | 0.00 | -0.27 |
6 | AAPL | 10/11/2021 | 142.81 | 142.81 | 64452200 | 0.00 | -0.06 |
7 | AAPL | 10/12/2021 | 141.51 | 141.51 | 73035900 | -0.01 | -0.91 |
8 | AAPL | 10/13/2021 | 140.91 | 140.91 | 78762700 | 0.00 | -0.42 |
9 | AAPL | 10/14/2021 | 143.76 | 143.76 | 69907100 | 0.02 | 2.00 |
px.scatter(data_frame = df,
x = 'Adj Close',
y= 'Volume',
size = 'Volume',
color = 'Company',
title = 'Volume vs Adj Close',
# Scales
range_x = [-500, 4000],
range_y = [-20e+06, 15e+07],
# Company when hover over points
hover_name = 'Company',
text = "Company",
# Animation based on date
animation_frame = 'Date',
size_max = 100)
Figure 1. Animated pairplot of popular companies: Adj Close vs Volume. Circle size based on Volume. Color key for different companies.
Link to image: https://plotly.com/~melisadigiacomo/1/
px.scatter(data_frame = df,
x = 'Volume',
y= '% Daily Return',
size = 'Volume',
color = 'Company',
title = '% Daily Return vs Volume',
# Scale
range_y = [-15,20],
range_x = [-20e+06, 12e+07],
# Company when hover over points
hover_name = 'Company',
text = "Company",
# Animation based on date
animation_frame = 'Date',
size_max = 100)
Figure 2. Animated pairplot of popular companies: % Daily Return vs Volume. % Daily Return is the percentage of the natural log of daily Adj Close ratio. Circle size based on Volume. Color key for different companies.
Link to image: https://plotly.com/~melisadigiacomo/3/
Table 2. Stocks of Tesla, Inc.
data_TSLA = df.where(df.Company == 'TSLA').dropna()
data_TSLA.head(10)
Company | Date | Close | Adj Close | Volume | Daily Return | % Daily Return | |
---|---|---|---|---|---|---|---|
119 | TSLA | 10/1/2021 | 775.22 | 775.22 | 17031400.0 | 0.00 | -0.03 |
120 | TSLA | 10/4/2021 | 781.53 | 781.53 | 30483300.0 | 0.01 | 0.81 |
121 | TSLA | 10/5/2021 | 780.59 | 780.59 | 18432600.0 | 0.00 | -0.12 |
122 | TSLA | 10/6/2021 | 782.75 | 782.75 | 14632800.0 | 0.00 | 0.28 |
123 | TSLA | 10/7/2021 | 793.61 | 793.61 | 19195800.0 | 0.01 | 1.38 |
124 | TSLA | 10/8/2021 | 785.49 | 785.49 | 16711100.0 | -0.01 | -1.03 |
125 | TSLA | 10/11/2021 | 791.94 | 791.94 | 14200300.0 | 0.01 | 0.82 |
126 | TSLA | 10/12/2021 | 805.72 | 805.72 | 22020000.0 | 0.02 | 1.73 |
127 | TSLA | 10/13/2021 | 811.08 | 811.08 | 14120100.0 | 0.01 | 0.66 |
128 | TSLA | 10/14/2021 | 818.32 | 818.32 | 12247200.0 | 0.01 | 0.89 |
Table 3. Descriptive statistics from each variable.
data_TSLA.describe()
Close | Adj Close | Volume | Daily Return | % Daily Return | |
---|---|---|---|---|---|
count | 17.000000 | 17.000000 | 1.700000e+01 | 17.000000 | 17.000000 |
mean | 835.176471 | 835.176471 | 2.180491e+07 | 0.016471 | 1.641176 |
std | 65.219055 | 65.219055 | 1.192739e+07 | 0.029568 | 2.931778 |
min | 775.220000 | 775.220000 | 1.224720e+07 | -0.010000 | -1.030000 |
25% | 785.490000 | 785.490000 | 1.463280e+07 | 0.000000 | 0.180000 |
50% | 811.080000 | 811.080000 | 1.843260e+07 | 0.010000 | 0.820000 |
75% | 865.800000 | 865.800000 | 2.283680e+07 | 0.020000 | 1.740000 |
max | 1024.860000 | 1024.860000 | 6.285210e+07 | 0.120000 | 11.920000 |
px.scatter(data_frame = data_TSLA,
x = 'Date',
y= 'Volume',
size = 'Volume',
color = '% Daily Return',
title = 'TSLA: Date vs Volume - Octuber',
# Company when hover over points
hover_name = 'Company',
text = '% Daily Return',
color_continuous_scale = 'sunset',
size_max = 100)
Figure 3. Pairplot: % Daily Return vs Volume of Tesla, Inc. % Daily Return is the percentage of the natural log of daily Adj Close ratio. Circle size based on Volume and text inside indicates % Daily Return. Color key for % Daily Return.
Link to image: https://plotly.com/~melisadigiacomo/5/
Tesla, Inc. showed a drastic shift on Octuber 25th, 2021, both on volume and % Daily Return.
Let's analyzed what happened with the other companies on that date.
Table 4. Stocks of popular companies on October 25, 2021.
df_25 = df.where(df.Date == '10/25/2021').dropna()
df_25.head(10)
Company | Date | Close | Adj Close | Volume | Daily Return | % Daily Return | |
---|---|---|---|---|---|---|---|
16 | AAPL | 10/25/2021 | 148.64 | 148.64 | 50720600.0 | 0.00 | -0.03 |
33 | AMZN | 10/25/2021 | 3320.37 | 3320.37 | 2226000.0 | 0.00 | -0.46 |
50 | FB | 10/25/2021 | 328.69 | 328.69 | 38409000.0 | 0.01 | 1.25 |
67 | GOOG | 10/25/2021 | 2775.46 | 2775.46 | 1054100.0 | 0.00 | 0.11 |
84 | KO | 10/25/2021 | 54.23 | 54.23 | 11855000.0 | 0.00 | -0.40 |
101 | MCD | 10/25/2021 | 237.34 | 237.34 | 3178400.0 | 0.00 | -0.46 |
118 | NFLX | 10/25/2021 | 671.66 | 671.66 | 3833500.0 | 0.01 | 1.03 |
135 | TSLA | 10/25/2021 | 1024.86 | 1024.86 | 62852100.0 | 0.12 | 11.92 |
px.scatter(data_frame = df_25,
x = 'Volume',
y= '% Daily Return',
size = 'Volume',
color = 'Company',
title = 'Volume vs % Daily Return - Octuber 25, 2021',
# Company when hover over points
hover_name = 'Company',
text = "Company",
size_max = 100)
Figure 4. Pairplot: Volume vs % Daily Return of popular companies on Octuber 25, 2021. % Daily Return is the percentage of the natural log of daily Adj Close ratio. Circle size based on Volume. Color key for different companies.
Link to image: https://plotly.com/~melisadigiacomo/7/
px.scatter(data_frame = df_25,
x = 'Company',
y= 'Volume',
size = 'Volume',
color = '% Daily Return',
title = 'Company vs Volume - Octuber 25, 2021',
# Company when hover over points
hover_name = 'Company',
text = '% Daily Return',
color_continuous_scale = 'sunset',
size_max = 100)
Figure 5. Pairplot: Company vs Volume on Octuber 25, 2021. % Daily Return is the percentage of the natural log of daily Adj Close ratio. Circle size based on Volume and text inside indicates % Daily Return. Color key for % Daily Return.
Link to image: https://plotly.com/~melisadigiacomo/9/