top of page

Beta of Fan Milk Ltd (FML): Ghana Stock Exchange (GSE)

Finding the Beta of FML on the GSE using Python (Jupyter Notebook)

FML Beta Results

Timeframe  Raw Beta  Adjusted Beta
  1-Month  0.563058       0.708706
  3-Month  0.145659       0.430439
   1-Year  0.408104       0.605403
   2-Year  0.356980       0.571320
   3-Year  0.366631       0.577754
   5-Year  0.350336       0.566891
  10-Year  0.372667       0.581778

View realtime data on FML via my GSE Stock data viewer: https://www.akweidata.com/projects-1/ghana-stock-exchange%3A-real-time-prices-web-app-v1


Data

FML data retrieved from the Ghana Stock Exchange Website: https://gse.com.gh/trading-and-data/

GSE-CI data retrieved from Eikon Refinitiv



Code

import pandas as pd
GSECI = pd.read_excel("GSECIdata")
FML = pd.read_excel("FMLdata")
GSECI.head()
FML.head()
GSECI.dtypes
FML.dtypes

# Convert the date columns to the same format
# Assuming the date columns are named 'Date' in both dataframes
GSECI['Date'] = pd.to_datetime(GSECI['Date'], format='%m/%d/%Y')
FML['Date'] = pd.to_datetime(FML['Date'], format='%d/%m/%Y')

# Now merge the dataframes on the 'Date' column
combined_data = pd.merge(FML, GSECI, on='Date', suffixes=('_FML', '_GSECI'))

# Display the first few rows of the combined dataframe to check the merge
print(combined_data.head())
# Calculate daily returns for FML and GSE-CI
combined_data['Return_FML'] = combined_data['Close_FML'].pct_change()
combined_data['Return_GSECI'] = combined_data['Close_GSECI'].pct_change()

# Drop the NaN values that result from pct_change()
combined_data = combined_data.dropna()

# Calculate covariance between FML's and GSE-CI's returns
covariance_matrix = combined_data[['Return_FML', 'Return_GSECI']].cov()
covariance = covariance_matrix.loc['Return_FML', 'Return_GSECI']

# Calculate the variance of GSE-CI's returns
variance_gseci = combined_data['Return_GSECI'].var()

# Calculate beta of FML
beta_fml = covariance / variance_gseci

print(f"The beta of FML is: {beta_fml}")

import numpy as np
import pandas as pd

# Assuming 'combined_data' has already been defined and contains daily return data

# Define a function to calculate raw and adjusted beta
def calculate_beta(return_stock, return_market):
    covariance = return_stock.cov(return_market)
    variance = return_market.var()
    raw_beta = covariance / variance
    # Adjusted beta is calculated with the formula (2/3 * raw_beta + 1/3)
    adjusted_beta = (2/3 * raw_beta) + (1/3)
    return raw_beta, adjusted_beta

# Define time frames in trading days
time_frames = {
    '1-Month': 21,
    '3-Month': 63,
    '1-Year': 252,
    '2-Year': 504,
    '3-Year': 756,
    '5-Year': 1260,
    '10-Year': 2520
}

# List to store beta values
beta_values = []

# Calculate beta for each time frame
for period, days in time_frames.items():
    if days < len(combined_data):
        # Slice the last 'days' of trading data for the period
        period_data = combined_data.tail(days)
        raw_beta, adjusted_beta = calculate_beta(period_data['Return_FML'], period_data['Return_GSECI'])
        beta_values.append({'Timeframe': period, 'Raw Beta': raw_beta, 'Adjusted Beta': adjusted_beta})

# Convert the list of dictionaries to a DataFrame
beta_df = pd.DataFrame(beta_values)

# Print the beta values in tabular form
print(beta_df.to_string(index=False))


bottom of page