Untitled

mail@pastecode.io avatar
unknown
python
a month ago
1.5 kB
1
Indexable
Never
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd

# Your CAAR values and significance
data = [
    [0.386, 0.660, 0.471, 0.680, 1.64, 1.71, -0.32],
    [0.87, 1.15, 0.96, 1.17, 2.12, 2.20, 0.16],
    [1.36, 1.63, 1.44, 1.65, 2.61, 2.68, 0.65],
    [0.99, 1.26, 1.07, 1.28, 2.24, 2.31, 0.28],
    [-0.55, -0.27, -0.46, -0.25, 0.70, 0.78, -1.26],
    [-0.24, 0.03, -0.16, 0.05, 1.01, 1.08, -0.95],
    [-1.09, -0.82, -1.01, -0.80, 0.16, 0.23, -1.80]
]

significance = [
    ["***", "***", "***", "***", "***", "***", "*"],
    ["***", "***", "***", "***", "***", "***", ""],
    ["***", "***", "***", "***", "***", "***", "***"],
    ["***", "***", "***", "***", "***", "***", "*"],
    ["***", "***", "***", "***", "***", "***", "***"],
    ["***", "", "*", "", "***", "***", "***"],
    ["***", "***", "***", "***", "**", "**", "***"]
]

index = [-10, -5, -4, -3, -2, -1, 0]
columns = [0, 1, 2, 3, 4, 5, 10]

# Create a DataFrame for the heatmap
df = pd.DataFrame(data, index=index, columns=columns)

annotations = df.astype(str) + '\n' + pd.DataFrame(significance, index=index, columns=columns)

# Plotting the heatmap
plt.figure(figsize=(12, 8))
heatmap = sns.heatmap(df, annot=annotations, fmt="", cmap="RdYlGn", center=0, linewidths=.5, cbar_kws={'label': 'CAAR'})

# Add titles and labels
plt.title('CAAR and t-statistics from Event Study (Heat Map)')
plt.xlabel(r'$\Gamma_2$')
plt.ylabel(r'$\Gamma_1$')

# Save the figure
plt.savefig("CAAR_Heatmap.png")
plt.show()
Leave a Comment