Sunday, 24 November 2019

quantopian lecture mean, standard deviation

A low standard deviation indicates that the values tend to be close to the mean of the set, while a high standard deviation indicates that the values are spread out over a wider range.

import numpy as np
import matplotlib.pyplot as plt

start = '2018-01-01'
end = '2019-02-01'
data = get_pricing(['MSFT'], fields='price', start_date=start, end_date=end)

_, ax = plt.subplots()

mean = data.mean().values
std = data.std().values

ax.plot(data.index, data)
ax.axhline(mean)
ax.axhline(mean + std, linestyle='--')
ax.axhline(mean - std, linestyle='--')

plt.title("Mcrosoft Prices")
plt.ylabel("Price")
plt.xlabel("Date");
plt.legend(['stock price', 'Mean', '+/- 1 Standard Deviation'])

reference:
https://www.quantopian.com/lectures/instability-of-estimates
https://en.wikipedia.org/wiki/Standard_deviation

No comments:

Post a Comment