Covariance
Covariance¶
In financial markets, we can expect that to some extent assets are going to move together. Below, we have a simulated stock price. We will begin seeing what its relationship to the broader market is.
In [20]:
plt.plot(range(len(ts_stock)),ts_stock)
plt.xlabel("t")
plt.ylabel("Stock Price")
plt.title("Stock 1 Price")
plt.show()
How does it look compared to the overall market returns?
In [21]:
#Compare to the market returns
plt.plot(range(len(ts)), ts, label="Market")
plt.plot(range(len(ts_stock)), ts_stock, label="Stock 1")
plt.xlabel("t")
plt.ylabel("Stock Price")
plt.title("Stock Price vs. Market Price")
plt.legend()
plt.show()
The first thing we might ask when comparing these two is what is the difference between their HPR? We can easily find it below.
In [22]:
#Compute HPR
HPR_market = ts[-1] / ts[0] - 1
HPR_stock = ts_stock[-1] / ts_stock[0] - 1
print("Market HPR: {}".format(HPR_market))
print("Stock HPR: {}".format(HPR_stock))
What about standard deviations?
In [23]:
#Compute standard deviation
sd_market = np.std(market_returns)
sd_stock = np.std(stock_returns)
print("Market Standard Dev: {}".format(sd_market))
print("Stock Standard Dev: {}".format(sd_stock))
And daily return.
In [24]:
#Compute mean daily return
mu_market = np.mean(market_returns)
print(mu_market)
mu_stock = np.mean(stock_returns)
print(mu_stock)