Saturday, 23 November 2019

quantopian lecture histogram

import numpy as np
import matplotlib.pyplot as plt

start = '2019-01-01'
end = '2019-11-20'
data = get_pricing(['AAPL', 'MSFT'], fields='price', start_date=start, end_date=end)

data.columns = [e.symbol for e in data.columns]

data['AAPL'].plot();
plt.title("Apple Prices")
plt.ylabel("Price")
plt.xlabel("Date");

#price histogram - how many days stock is at certain price during 2019
plt.hist(data['AAPL'], bins=20)
plt.xlabel('Price')
plt.ylabel('Number of Days Observed')
plt.title('Frequency Distribution of AAPL Prices, 2019');

#return histogram - how many days stock performs daily in certain percentage
R = data['AAPL'].pct_change()[1:]

plt.hist(R, bins=20)
plt.xlabel('Percent Return in a day')
plt.ylabel('Number of Days Observed')
plt.title('Frequency Distribution of AAPL Returns, 2019');


No comments:

Post a Comment