<jupyter_start><jupyter_text>Analysis: Distributions<NAME>What's the distribution of monthly S&P500 returns?Imports and setup:<jupyter_code>import numpy as np
import yfinance as yf
import matplotlib.pyplot as plt
from matplotlib import style
import seaborn as sns
sns.set(font_scale=1)
import pandas as pd
import os

ticker= "SPY"
stock = yf.Ticker(ticker)
data = stock.history(period="max", interval="1d")
# data = pd.read_csv(
#     os.path.abspath("../data/sp_500_max.csv"),
#     sep=","
# )


change = (
    data["Close"].iloc[1:].values /
    data["Close"].iloc[:-1].values
)
change_pct = (change - 1) * 100

hist_xscl = 1
def make_pct_hist():
    fig, ax = plt.subplots(1, 1, figsize=(6.4, 4.8), dpi=200)
    plt.hist(
        x=change_pct,
        bins=np.linspace(-hist_xscl, hist_xscl, 50),
        density=True,
    )
def show_pct_hist():
    plt.xlim(-hist_xscl, hist_xscl)
    plt.yscale('log')
    plt.xlabel(r"Daily Change (%)")
    plt.ylabel(r"Probability Distribution Function")
    plt.title(r"S&P500 Percent Change Day-to-Day")
    plt.tight_layout()
    plt.legend()
    # plt.savefig("C:/Users/User/Downloads/temp.svg")
    plt.show()

make_pct_hist()
show_pct_hist()

from scipy import stats

laplace_params = stats.laplace.fit(
    data = change_pct
)
print(f"laplace_params = {laplace_params}")

make_pct_hist()
x = np.linspace(-hist_xscl, hist_xscl, 300)
plt.plot(x, stats.laplace.pdf(x, *laplace_params))
show_pct_hist()<jupyter_output>laplace_params = (0.06664652979518582, 0.7803555275686522)
{'fraction_non_alphanumeric': 0.14661406969099278, 'fraction_numerical': 0.0440499671268902, 'mean_word_length': 4.26643598615917, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '205411', 'license': 'MIT', 'n_tokens_mistral': 657, 'n_tokens_neox': 609, 'n_words': 112, 'path': 'analysis_distributions/analysis_distributions.ipynb', 'repo_name': 'peterdsharpe/StockMarketAnalysis', 'size': '1527'}