Portfolio Analysis Basics: Volatility and Sharpe Ratio
By: Shuo Wang
Tags: Investing, Python, Money, Data Science, Quantitative Analysis

Portfolio Analysis Basics: Volatility and Sharpe Ratio

In this story, we are going to discuss why volatility is so important and how to assess its impact on return.

Daily Returns of Four Price Time Series

When we look at a stock or any type of investments, the first thing we care about is usually how much money we can make from it, in other words, the returns of the investments. However, there is actually quite a bit more to it than just that. Here we’ll demonstrate with an example.

First things first, I need some stock prices and their daily returns to do analysis on. So, I am going to generate 4 different price time series and compare them to see which one I want to buy!

Price Simulation

In order to do that, I am going to use the Geometric Brownian Motion (GBM) process that I mentioned in an earlier story (link):

import pandas as pd

import numpy as np def daily_returns(prices): # cur_price / prev_price - 1.0 = daily_returns

res = (prices/prices.shift(1) - 1.0)[1:]

res.columns = ['return']



return res

def brownian_prices(start, end,

mu=0.0001, sigma=0.01, s0=100.0):



bdates = pd.bdate_range(start, end)

size = len(bdates)



np.random.seed(1)

wt = np.random.standard_normal(size) # GBM process

st = s0 * np.cumprod(

np.exp(mu - (sigma * sigma / 2.0)

+ sigma * wt))



return pd.DataFrame(data={'date': bdates,

'price': st}).set_index('date')

With this process, here are my 4 stock price time series:

start = '20100101'

end = '20200101'

returns1 = daily_returns(brownian_prices(start,

end,

mu=0.002,

sigma=0.01,

s0=100.0))



returns2 = daily_returns(brownian_prices(start,

end,

mu=0.002,

sigma=0.02,

s0=100.0))



returns3 = daily_returns(brownian_prices(start,

end,

mu=0.0022,

sigma=0.05,

s0=100.0))



returns4 = daily_returns(brownian_prices(start,

end,

mu=0.0054,

sigma=0.1,

s0=100.0))

Here I have generated 4 GBM daily time series, each with slight different parameters:

price 1: mu = 0.002, sigma = 0.01

price 2: mu = 0.002, sigma = 0.02

price 3: mu = 0.0022, sigma = 0.05

price 4: mu = 0.0054, sigma = 0.1

mu and sigma are standard inputs to the GBM process, mu stands for drift (or growth of the time series) and sigma stands for volatility (the random noise that causes the time series to go up and down in a random walk fashion).

Average Daily Returns

Which one is better, you say?

Suppose I am your best friend, and I tell you: oh yeah, I’ve got this amazing stock, and it returned an average of 1% every day for the past year! You must think this is a great stock, right?

Well, let’s take a look at the average daily returns first then:

print(np.nanmean(returns1))

print(np.nanmean(returns2))

print(np.nanmean(returns3))

print(np.nanmean(returns4)) >>>

0.0021505103073854353

0.002198836614378123

0.0019434904977809336

0.0023861582203702834

Well, all of them have an average daily return of ~0.2%, for the past 10 years… It looks like stock 4 is the best, followed by stock 2, then stock 1 and stock 3…

But hold on, no rush to judgement, let’s take a closer look.

Here are the cumulative returns of each of the price time series:

def cumulative_returns(returns):



res = (returns + 1.0).cumprod()

res.columns = ['cumulative return']



return res cret1 = cumulative_returns(returns1)

cret2 = cumulative_returns(returns2)

cret3 = cumulative_returns(returns3)

cret4 = cumulative_returns(returns4)

Cumulative Returns of the Four Price Time Series

Wow, what happened? I thought stock 4 was supposed to be the best… but it barely made any money! If I invested in stock 4 for 10 years, I would have lost all my investments!

On the other hand, stock 1 did amazing! for the past 10 years it more than tripled my initial investment! (say if I put in 100 dollars on 2010–01–01, I would have 300 dollars by now.)

Stock 2 did almost as well, close to tripling my investment.

However, stock 3 did almost as badly as stock 4, returning nothing for my investment (although I didn’t actually lose my initial investment).