Module 2 (Risk Analytics):
Part 2: Behavior of Returns
Dr Hamed Ghoddusi
Some Cases and Applications
With the basics we learnd in Part 1, we can implement a few
real-world empirical or analytical cases.
Back-testing trading strategies
Quantifying risk and risk bounds
Calculating Beta for stocks and testing CAPM theory
Checking seasonal effects in stock market (e.g., day of the week or
month effect)
Portfolio optimization and risk management
We need to calculate returns for most applications
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 2 / 40
Why Returns?
Unlike prices, returns are scale-free
Example: asset price going from $50 to $60 has the same economic
meaning of going from $500 to $600
Price changes: $10 versus $100
Returns: 20% in both cases
Unlike prices, returns have some desirable statistical properties
Returns are stationary but prices are typically not
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 3 / 40
Some Real-World Example: Goldman-Sachs Stock Returns
Figure: GS Stock Returns
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 4 / 40
Calculating Daily Returns
Calculate the daily returns from the closing prices.
# Calculate daily returns using Adjusted Close prices
aapl_returns <- dailyReturn(AAPL, type = "log")
# View the first few returns
head(aapl_returns)
The ‘dailyReturn‘ function calculates log returns. What is a log
return?
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 5 / 40
Alternative: Calculating Daily Returns Manually
Calculate the daily returns from the adjusted closing prices without
using ‘dailyReturn‘.
# Assuming AAPL is an xts object with Adjusted Close p
# Calculate log returns manually
aapl_log_returns <- diff(log(Cl(AAPL)))
# View the first few log returns
head(aapl_log_returns)
Log returns: first taking the natural logarithm (‘log‘) of the adjusted
closing prices (‘Cl(AAPL)‘) and then computing the difference
between consecutive log prices (‘diff‘ function).
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 6 / 40
Plotting AAPL Daily Returns
Visualize the daily returns to assess volatility and trends.
# Plot the daily returns
chartSeries(aapl_returns,
main = "AAPL Daily Log Returns (2020-2023)
TA = "addVo();addBBands()",
theme = chartTheme("white"))
The ‘chartSeries‘ function creates a chart of daily log returns,
enhanced with volume (Vo) and Bollinger Bands (BBands) for
additional analysis.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 7 / 40
Asset Returns
Let Pt be the price of an asset at time t, and assume no dividend.
Pt −Pt−1
One-period simple net return: rt = Pt
Pt−1 −1= Pt−1
Example: one-month return
Pt −Pt−k
The k-period simple net return: rt (k) = Pt
Pt−k −1= Pt−k
Example: three-month return
Gross return = 1 + net return = Rt = Pt
Pt−1
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 8 / 40
Asset Returns
Example: Table below gives five daily closing prices of Apple stock in
December 2011. The 1-day gross return of holding the stock from 12/8 to
12/9 1 + Rt = 393.62/390.66 ≈ 1.0076 so that the daily simple return is
0.76%, which is (393.62 − 390.66)/390.66.
Date 12/02 12/05 12/06 12/07 12/08 12/09
Price($) 389.70 393.01 390.95 389.09 390.66 393.62
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 9 / 40
Continuous Compounding (Optional Content)
The power of compounding for an example with interest rate 10% per
year
We go from nominal 10% annual rate to monthly, weekly, daily, ...
compounding
Type #(payment) Periodic Rate Effective (Net)
Annual 1 0.1 $1.10000
Semi-Annual 2 0.05 $1.10250
Quarterly 4 0.025 $1.10381
Monthly 12 0.0083 $1.10471
Weekly 52 0.1
52 $1.10506
Daily 365 0.1
365 $1.10516
Continuously ∞ $1.10517
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 10 / 40
Continuous Compounding and Log Returns (Optional
Content)
Continuous compounding: limN→∞ (1 + N)
i N
= ei
If we start from P0 :
Pn = P0 e [r ×n]
r is the interest rate, P0 is the initial price, and n is the number of
periods.
Present value: P = Fe [−r ×n]
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 11 / 40
Differential of Logarithmic Function
For a differentiable function f (x ):
df (x )
d[ln f (x )] =
f (x )
Applied to a price variable P:
dP
d[ln P] ≈
P
Interpretation: The change in the log of a variable is approximately its
percentage change.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 12 / 40
Log Differences as Percentage Changes
In discrete time:
Pt
ln Pt − ln Pt−1 = ln
Pt−1
When changes are small:
Pt Pt − Pt−1
ln ≈ = %∆P
Pt−1 Pt−1
So:
∆ ln Pt ≈ percentage change in P
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 13 / 40
Example: Log Difference vs. Percentage Change
Suppose Pt−1 = 100 and Pt = 105
Percentage change:
105 − 100
= 0.05 = 5%
100
Log difference:
ln(105) − ln(100) = ln(1.05) ≈ 0.0488 ≈ 4.88%
Observation: Log difference is slightly lower than simple return.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 14 / 40
Log Plots and Growth Interpretation
Plotting the level of a time series shows its absolute size.
Plotting the log of the series emphasizes its growth rate.
Why? Because:
Yt − Yt−1
ln Yt − ln Yt−1 ≈ = growth rate
Yt−1
A straight line in a log plot implies a constant growth rate over time.
Widely used in macroeconomics and finance to assess trend stability.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 15 / 40
Example: MSFT Stock Price (1990–2025) and Its Log
MSFT Stock Price (Level)
$400
$300
Price (USD)
$200
$100
$0
1990 2000 2010 2020
Log of MSFT Stock Price
6
4
log(Price)
1990 2000 2010 2020
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 16 / 40
Log Returns
The standard convention in finance
rt = ln(1 + Rt ) = ln PPt−1
t
= pt − pt−1 ,
where pt = ln(Pt )
Note: as a convention, lower-case letters typically show log values.
Remember Taylor’s expansion and approximation for ln(1 + Rt )
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 17 / 40
Log Returns
Multi period log return:
rt (k) = ln[1 + Rt (k)]
= ln[(1 + Rt )(1 + Rt−1 ) . . . (1 + Rt−k+1 )]
= ln(1 + Rt ) + ln(1 + Rt−1 ) + · · · + ln(1 + Rt−k+1 )
= rt + rt−1 + · · · + rt−k+1 .
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 18 / 40
Continuously compounded (or log) return
Example Consider again the Apple stock price.
1 What is the log return from 12/8 to 12/9:
2 Answer: rt = ln(393.62) − ln(390.66) = 0.75%.
3 What is the log return from day 12/2 to 12/9?
4 Answer: rt (4) = ln(393.62) − ln(389.7) = 1%.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 19 / 40
Portfolio Return
Portfolio return: N assets
N
Rp,t =
X
ωi Rit
i=1
Example: An investor holds stocks of IBM, Microsoft and CitiGroup.
Assume that her capital allocation is 30%, 30% and 40%. Use the
monthly simple returns in Table 1.2 of the text. What is the mean simple
return of her stock portfolio?
Answer: E (Rt ) = 0.3 × 1.35 + 0.3 × 2.62 + 0.4 × 1.17 = 1.66.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 20 / 40
Distributional properties of returns
Question: what is the distribution of {rit ; i = 1, . . . , N; t = 1, . . . , T }?
See an example below on Goldman-Sachs
Figure: Histogram of GS Stock Returns
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 21 / 40
Four Major Moments
First moment: mean or expectation of X
Second central moment: Variance of X
Third (central) moment: Skewness (symmetry)
" #
(X −µx )3
S(x ) = E σx3
Forth (central) moment: kurtosis (fat-tails)
" #
(X −µx )4
K (x ) = E σx4
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 22 / 40
Distributional properties of returns
Why are the mean and variance of returns important?
They are concerned with long-term return and risk, respectively.
Why is return symmetry of interest in financial study?
Symmetry has important implications in holding short or long financial
positions and in risk management.
Why is kurtosis important?
Related to volatility forecasting, efficiency in estimation and tests, etc.
High kurtosis implies heavy (or long) tails in distribution.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 23 / 40
R Commands: Check Four Moments of Normal
Distribution
x=rnorm(100)
hist(x,20)
mean(x)
var(x)
skewness(x)
kurtosis(x)
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 24 / 40
Distributional properties of returns
Under normality assumption
Ŝ(x ) ∼ N(0, T6 )
K̂ (x ) − 3 ∼ N(0, 24
T )
Note that we are talking about the distribution of moment estimators!
Sample skew and kurtosis are used to test for normality!
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 25 / 40
R Commands
# This code generates sets of normal random variables
# (with 1000 observations in each)
s=vector()
for (i in 1:100){
x=rnorm(1000)
s[i]=skewness(x)
}
# Look at the histogram of skewness of 100 samples
hist(s,30,main="Histogram for Sample Skewness")
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 26 / 40
Distributional properties of returns
2 Test for tail thickness:
K̂ (x ) − 3
K∗ = p ∼ N(0, 1)
24/T
if normality holds.
Decision rule:
Reject Ho of normal tails if |K ∗ | > Zα/2 or p-value is less than α
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 27 / 40
R Commands
require(tseries)
[Link](x)
# Generate a new variable y = xˆ2
# Obviously, y is not normal
y=xˆ2
[Link](y)
# Generate a new variable z = x+ 10
# Z is still normal
z=x+10
[Link](z)
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 28 / 40
Returns in the Real-World
Empirical distrubution of asset returns tends to be skewed to the left
with heavy tails and has a higher peak than normal distribution
Figure: Comparison of empirical IBM return densities (solid) with Normal
densities (dashed)
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 29 / 40
Checkin Autocorrelation in Stock Returns
Autocorrelation, also known as serial correlation, is the correlation of
a signal with a delayed copy of itself as a function of delay.
Importance: Identifies patterns and trends in stock returns, impacting
trading and risk management.
Positive vs. Negative Autocorrelation and their implications.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 30 / 40
Autocorrelation in Stock Returns
Mathematically, for a time series yt , autocorrelation for lag k is
defined as:
E [(yt − µ)(yt+k − µ)]
R(k) =
σ2
where:
E is the expected value operator,
µ is the mean of the time series,
σ 2 is the variance of the time series,
t is the time index, and
k is the lag.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 31 / 40
Understanding Autocorrelation in Stock Returns
A more intuitive mathematical representation for a time series yt at
lag k is given by:
(yt − ȳ )(yt+k − ȳ )
PN−k
R(k) = t=1
t=1 (yt − ȳ )
PN 2
where:
ȳ is the mean of the time series,
N is the total number of observations in the time series,
t is the time index, and
k is the lag.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 32 / 40
Setup in R
# Load the necessary package
if(!requireNamespace("tseries", quietly = TRUE))
[Link]("tseries")
library(tseries)
Ensure the ‘tseries‘ package is installed and loaded.
Although ‘acf‘ is available in base R, ‘tseries‘ offers additional
functionality for time series analysis.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 33 / 40
Calculating Autocorrelation in R
autocorr_result <- acf(stock_returns, [Link] = 1,
plot = FALSE)
print(autocorr_result$acf)
This calculates and prints the autocorrelation at lag 1.
‘[Link] = 1‘ specifies the maximum lag period we’re interested in.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 34 / 40
Analyzing Autocorrelation of Returns
# Calculate and plot autocorrelation
acf(aapl_returns, [Link] = 20, main="AAPL Returns Aut
This visualizes the autocorrelation in Apple’s daily returns up to 20
lags.
Autocorrelation analysis helps identify patterns in the returns that
could be significant for trading strategies.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 35 / 40
Introduction to Stock Price Risk
Stock price risk refers to the uncertainty or variability in stock prices.
For investors, it is a critical measure to quantify probability and
magnitude of gains and losses
Volatility is often used as a measure of risk, indicating how much
stock prices fluctuate over a specific period.
We will calculate and interpret historical volatility as a measure of risk.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 36 / 40
Understanding Volatility
Volatility represents the standard deviation of returns for a stock over
a given timeframe.
Higher volatility indicates higher risk and potentially higher returns or
losses.
Historical volatility can be calculated using past stock returns.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 37 / 40
Calculating Historical Volatility in R
# Assuming 'aapl_returns' contains Apple's daily retur
# Calculate historical volatility (annualized)
volatility <- sd(aapl_returns) * sqrt(252)
# Print the calculated volatility
print(volatility)
This calculation assumes ‘aapl returns‘ are daily returns.
√
The 252 is used to annualize volatility, assuming 252 trading days in
a year.
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 38 / 40
Converting Volatility over Frequencies
The general rule is that if we calculate volatility using one frequency
(e.g., daily), the volatility at another frequency scales with sqrt of
time scale
This is called the “square root” rule of volatility
Examples.
√
Daily to monthly: √
∗ 20
Daily to annual: ∗ 256
√
Monthly to annual: ∗ √12
Quarterly to annual: ∗ 4
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 39 / 40
Moving Window Model for Volatility
Simplest model using a window of historical returns to estimate
volatility.
Assumes equal weight to all observations in the window.
# R Code Example
library(TTR)
historical_returns <- diff(log(AAPL$[Link]))
volatility_ma <- runSD(historical_returns, n = 20) * s
Hamed Ghoddusi (CalPoly) Stock Price and Returns April 9, 2025 40 / 40