Skip to content

Instantly share code, notes, and snippets.

@quantra-go-algo
Last active January 2, 2024 00:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quantra-go-algo/63b3dd2be4842d67aa950915b9dbb896 to your computer and use it in GitHub Desktop.
Save quantra-go-algo/63b3dd2be4842d67aa950915b9dbb896 to your computer and use it in GitHub Desktop.
# We will import the necessary libraries
import numpy as np
import pandas as pd
import yfinance as yf
from tabulate import tabulate
import scipy
# Plotting
import matplotlib.pyplot as plt
import seaborn
import matplotlib.mlab as mlab
#Statistical calculation
from scipy.stats import norm
# For warnings suppression
import warnings
warnings.filterwarnings("ignore")
# We will import the daily data of Amazon from yahoo finance
# Calculate daily returns
df = yf.download("AMZN", "2020-01-01", "2022-01-01")
df = df[['Close']]
df['returns'] = df.Close.pct_change()
# Now we will determine the mean and standard deviation of the daily returns
# Plot the normal curve against the daily returns
mean = np.mean(df['returns'])
std_dev = np.std(df['returns'])
df['returns'].hist(bins=40, density=True, histtype='stepfilled', alpha=0.5)
x = np.linspace(mean - 3*std_dev, mean + 3*std_dev, 100)
plt.plot(x, scipy.stats.norm.pdf(x, mean, std_dev), "r")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment