-
-
Save quantra-go-algo/63b3dd2be4842d67aa950915b9dbb896 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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