8. Foundational Probability Concepts and Their Applications
Activity 8.01: Using the Normal Distribution in Finance
Solution:
Perform the following steps to complete this activity:
- Using pandas, read the CSV file named
MSFT.csv
from thedata
folder:import pandas as pd import numpy as np import scipy.stats as stats import matplotlib.pyplot as plt %matplotlib inline msft = pd.read_csv('../data/MSFT.csv')
- Optionally, rename the columns so they are easy to work with:
msft.rename(columns=lambda x: x.lower().replace(' ', '_'),\ Â Â Â Â Â Â Â Â Â Â Â Â inplace=True)
- Transform the
date
column into a properdatetime
column:msft['date'] = pd.to_datetime(msft['date'])
- Set the
date
column as the index of the DataFrame:msft.set_index('date', inplace = True)
- In finance, the daily returns of a stock are defined as the percentage change of the daily closing price...