Do stock prices go down on Fridays?

Kirill Strelkov
3 min readAug 28, 2020

It seems that stock prices have tendency to go up on Mondays and go down Friday. Here is quick analysis of S&P500 weekday prices from 2015 to 2020.

Getting S&P 500 data

import pandas as pdimport yfinance as yf
import os
from pandas.core.frame import DataFrame
from more_itertools.recipes import flatten
# Save csv file from
# https://datahub.io/core/s-and-p-500-companies to 'sp500.csv'
df = pd.read_csv("stocks/week/sp500.csv")
df.head()
First 5 rows of S&P companies

Step 2: Get stock price histories for 2015–2020

START_DATE = "2015-08-28"
END_DATE = "2020-08-28"
def get_history(symbol):
ticker = yf.Ticker(symbol)
df = ticker.history(period="1d", start=START_DATE, end=END_DATE)
if not df.empty:
df["Symbol"] = symbol
return df
get_history(df["Symbol"][0]).head()
First 5 days of stock prices for MMM

Step 3: Get differences between Monday and other weekday

def get_weekly_diffs(df):
symbol = df["Symbol"][0]
df = df.reset_index()
df["weekday"] = df["Date"].apply(lambda x: x.weekday())
if df[df["weekday"] == 0].empty:
return {}
# getting first row that starts with Monday
df = df[df[df["weekday"] == 0].index[0] :]
prev_monday_price = 0
full_weeks = []
is_monday = False
is_friday = False
week = []
for _, row in df.iterrows():
weekday = row["weekday"]
# filter weeks were all days were traiding days
is_monday = weekday == 0
is_friday = weekday == 4
if is_monday:
prev_monday_price = row["Open"]
price_diff = 1
week = [row]
else:
if prev_monday_price == 0:
continue
price_diff = row["Open"] / prev_monday_price
week.append(row)
row["diff"] = price_diff
if is_friday and len(week) == 5:
full_weeks += week
if not full_weeks:
return {}
df = DataFrame(full_weeks) df["Symbol"] = symbol
return df.to_dict("r")
DataFrame(get_weekly_diffs(get_history(df["Symbol"][0]))).head()
First 5 days of stock prices for MMM with weekdays differences comparing to Monday in percentage

Step 4: Find mean weekday differences for all stocks

os.sys.path.append('../github/python_recipes/')
from utils.misc import concurrent_map
histories = []# Next check is needed because some stocks
# might not contain data at all
for df_h in concurrent_map(get_history, df["Symbol"]):
if not df_h.empty:
histories.append(df_h)
symbol_diffs = flatten(concurrent_map(get_weekly_diffs, histories))df = DataFrame(symbol_diffs)
df = (
df[["weekday", "diff"]]
.groupby("weekday", group_keys=False)
.mean()
.reset_index(drop=True)
)
df = df * 100
df.head()
Mean weekdays differences comparing to Monday(0 — Monday, 5 — Friday)

Step 5: Visualize data

from seaborn import barplotindex2weekday = dict(
zip(
range(0,5),
['Monday', 'Tuesday', 'Wednesday', 'Thursday','Friday']
)
)
df_percent_diff = df - 100
df_percent_diff.index = [
index2weekday[w]
for w in df_percent_diff.index
]
barplot(
x=df_percent_diff.index,
y=list(flatten(df_percent_diff.values))
)
df_percent_diff
Mean weekdays differences comparing to Monday
Weekdays change in percentage comparing to Monday

You can see from table and chart that on Friday stock prices go up to ~0.19% on “average”.

--

--