<aside> 📌 When determining what stock to invest or include in an investment portfolio, it is important for us to consider not only the returns of the stock but also the potential risk. In order to capture them when making investment considerations. In 1966, William Sharpe develop a ratio called the reward-to-variability ratio.
</aside>
<aside> 📌 In this project, I will be using 2016 stock data to determine which one among the three investment choices(Amazon, Facebook, and S&P 500 index fund) has a higher Sharpe ratio, therefore a better investment option.
</aside>
# Importing modules
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
%matplotlib inline
# Reading in the data
stock_data = pd.read_csv('datasets/stock_data.csv', parse_dates = True,
index_col = ['Date']).dropna()
benchmark_data = pd.read_csv('datasets/benchmark_data.csv', parse_dates =
True, index_col = ['Date']).dropna()
# Display summary for stock_data & benchmark_data
stock_data.describe()
benchmark_data.describe()
# visualize the stock_data visibile as pic1
stock_data.plot( title = 'Stock Data',subplots = True)
# plot the benchmark_data visibile as pic2
benchmark_data.plot(title = 'S&P 500',subplots = False)
pic1:
pic2
#since the data is not the daily return
#of the two investment options, we have to first calculate the
#percentage change
stock_returns = stock_data.pct_change()
sp_returns = benchmark_data['S&P 500'].pct_change()
# plot the daily returns of fb and SP500 visible as pic 3,4
stock_returns.plot()
sp_returns.plot()
pic 3
pic4
#then we need to calculate the excess return of the fb and Amz stocks
excess_returns = stock_returns.sub(sp_returns,axis = 0)
avg_excess_return = excess_returns.mean()
sd_excess_return = excess_returns.std()
#plots are visibile as pic 5,6,7
excess_returns.plot();
avg_excess_return.plot.bar(title = 'Mean of the Return Difference');
sd_excess_return.plot.bar(title =
'Standard Deviation of the Return Difference');
# calculate the annualized sharpe ratio(2016)
# annual_factor is calculated by square rooting the number of trading days
daily_sharpe_ratio = avg_excess_return.div(sd_excess_return)
annual_factor = np.sqrt(5*52-8)
annual_sharpe_ratio = daily_sharpe_ratio.mul(annual_factor)
# plot the annualized sharpe ratio visible as pic 8
annual_sharpe_ratio.plot.bar(title =
'Annualized Sharpe Ratio: Stocks vs S&P 500');
**Therefore, we can safely conclude that according to the 2016 data,
Amazon perform significantly better compare to Facebook and S&P500.
That means we as investors should probably invest in Amazon.**
pic5
pic6