Class 1: Tue 6 Oct 2026 · Slides:
Week1 Slides.pdf · Code:
Week1_plot_prices.Rmd,
Week1_two_asset_frontier.Rmd · Textbook pp. 5–9 and
87–91
How to use this guide: read Part A tonight (about 30 minutes). Don’t try to memorise anything; just aim to get the idea. Tomorrow, keep it open next to the slides. When the professor puts up a formula, find it here and read the plain-English version.
Every later week builds on this. Week 2 finds the best portfolio. Weeks 4–7 measure how bad the bad days can get (VaR and Expected Shortfall). All of it starts from “a column of returns”.
| Term | Plain English |
|---|---|
| Asset | Anything you can buy that has a price: a share (BHP, CBA), a bond, a currency. |
| Price, P_t | What one unit costs at time t. |
| Return | How much your money grew (or shrank) over a period, as a fraction. 0.05 = 5%. |
| Simple net return, R_t | (new price ÷ old price) − 1. “I made 5%.” |
| Simple gross return, 1 + R_t | new price ÷ old price. “My $1 became $1.05.” |
| Log (continuously compounded, cc) return, r_t | log(new price) − log(old price). Almost the same as the simple return; easier to add up over time. |
| Ex post | Looking backwards: actual past data you can compute. |
| Ex ante | Looking forward: future returns, which are random and unknown. |
| Dividend, D_t | Cash a company pays its shareholders. |
| Ex-dividend date | The day the share starts trading without the right to the upcoming dividend. The price drops by about the dividend amount. |
| Stock split | e.g. 1 share becomes 2 shares and the price halves. Nobody got richer or poorer. |
| Adjusted price | A price series that Yahoo Finance has “cleaned” so that dividends and splits don’t look like gains or losses. |
| Long | You own the asset. You profit when it goes up. |
| Short | You borrowed the asset and sold it. You profit when it goes down. |
| Portfolio | A collection of assets. |
| Weight, w_i | The fraction of your money in asset i. Weights add up to 1. A negative weight means short. |
| Variance, σ² | The average squared distance from the mean, i.e. how spread out returns are. |
| Standard deviation (SD), σ | √variance. This is the course’s basic measure of risk. It’s in the same units as returns (e.g. 4% per week). |
| Covariance, σ_ij | Do two assets move together (positive), opposite to each other (negative), or unrelated (≈0)? |
| Correlation, ρ | Covariance rescaled to sit between −1 and +1. It’s easier to read. |
| Mean-SD diagram | A plot with risk (SD) on the x-axis and expected return on the y-axis. |
| Minimum variance portfolio (MVP) | The mix with the lowest possible risk. |
| Efficient frontier | The upper part of the curve, above the MVP: the best return for each level of risk. |
| Risk-free rate, r_f | The return on a “safe” asset like a government bill. |
| Sharpe ratio | (return − risk-free rate) ÷ SD. Extra return earned per unit of risk. |
| Skewness / kurtosis | Shape of the distribution: is it lopsided, and how fat are the tails (how often extreme days happen)? |
🧠 Story. You buy two things: a $10 share and a $500 share. Both rise by $5. Did they do equally well? No: one grew by half, the other barely moved. Prices depend on scale; returns don’t. Returns let you compare a $10 share with a $500 share, or 2006 with 2024.
Why the slides say returns are better (likely quiz material): - They’re scale-free: they don’t depend on how big the price is. - Their statistical behaviour is nicer. Prices trend and wander; returns bounce around a fairly stable average. - The variance/SD of returns measures risk. - Real-world returns share common patterns (“stylised facts”), such as fat tails.
Say it in one sentence: we analyse returns because they measure growth as a percentage, so assets and time periods can be compared, and their spread (SD) measures risk.
🧠 Story. You put $100 in a jar on Monday and it’s worth $105 on Friday. Your gross return is 1.05 (“each dollar became $1.05”). Your net return is 0.05 (“I made 5%”).
🔢 Formula decoded.
\[R_t = \frac{P_t}{P_{t-1}} - 1 = \frac{P_t - P_{t-1}}{P_{t-1}}\]
Worked example: \(P_{t-1}\) = 100, \(P_t\) = 110 → \(R_t\) = 110/100 − 1 = 0.10 = 10%.
Key fact: the worst possible return is −1 (−100%), when the asset becomes worthless. A price can’t go below 0.
Multi-period (k periods). To get a return over several weeks, multiply the gross returns:
\[1 + R_t(k) = (1+R_t)(1+R_{t-1})\cdots(1+R_{t-k+1}) = \frac{P_t}{P_{t-k}}\]
That’s why simple returns are also called compound returns.
Worked example (the trap!): the price goes 100 → 110 → 99. - Week 1: +10%. Week 2: 99/110 − 1 = −10%. - Adding them gives 10% − 10% = 0%. Wrong! You actually lost money: 99/100 − 1 = −1%. - Multiplying gives (1.10)(0.90) − 1 = 0.99 − 1 = −1%. Correct.
Say it in one sentence: the simple net return is profit divided by what you paid; over several periods you multiply gross returns, you don’t add net returns.
🧠 Story. Simple returns have to be multiplied over time, which is fiddly. Log returns are a clever re-scaling that turns multiplying into adding. And for normal-sized moves (under ~10%) they’re practically the same number as simple returns.
🔢 Formula decoded.
\[r_t = \ln(1+R_t) = \ln\!\left(\frac{P_t}{P_{t-1}}\right) = \ln P_t - \ln P_{t-1}\]
To convert back: \(R_t = e^{r_t} - 1\).
| Simple return R | Log return r = ln(1+R) | Gap |
|---|---|---|
| 1% | 0.995% | tiny |
| 10% | 9.53% | small |
| 50% | 40.5% | big |
| −50% | −69.3% | very big |
| −99% | −460% | huge (heads to −∞) |
Patterns to remember (textbook p. 7): - They always have the same sign. - Log returns are smaller than simple returns, whether positive or negative (−69% is “smaller” than −50%). - The gap is tiny for small moves and big for large, especially large negative, moves. - So: daily returns are almost identical in both measures; yearly returns differ more.
Why log returns add up. The log of a product is a sum of logs:
\[r_t(k) = r_t + r_{t-1} + \dots + r_{t-k+1}\]
Same example, 100 → 110 → 99: ln(1.10) = 0.0953 and ln(0.90) = −0.1054. Add them to get −0.01005. Convert back: e^(−0.01005) − 1 = −1%. ✅ Correct, just by adding.
Why the professor cares (slide 10): later we treat future returns as random variables. Sums of random variables are much easier to handle than products. For example, if each week’s log return is normal, the k-week log return is normal too, with mean kμ and variance kσ².
But: portfolio calculations use
simple returns (slide 24). You’ll see the code compute
log returns first, then convert: exp(log_return) - 1.
Say it in one sentence: log returns ≈ simple returns for small moves, and they add up over time, which makes the maths over many periods easy; portfolios still use simple returns.
🧠 Story. You own a share worth $100. The company pays you a $2 dividend, so $2 cash lands in your bank. On the ex-dividend day the share drops to $98, because the company has $2 less in it. Did you lose money? No. You have $98 of share plus $2 of cash, so you’re even. If you only looked at the price, you’d wrongly record a −2% “loss”.
🔢 Formula decoded (dividend \(D_t\) paid during the period):
\[R_t = \frac{P_t + D_t}{P_{t-1}} - 1 \qquad r_t = \ln(P_t + D_t) - \ln(P_{t-1})\]
Just add the dividend back to the end price.
Worked example: \(P_{t-1}\) = 100. A $2 dividend is paid. \(P_t\) = 97. - Naive (price only): 97/100 − 1 = −3% ❌ (too pessimistic) - Dividend-adjusted: (97 + 2)/100 − 1 = −1% ✅
The slide example is BHP, which went ex-dividend on 5 Sept 2019 for USD 1.56. The longer your data, the more these errors pile up.
The Yahoo Finance way (slides 14–17). Instead of fixing returns, Yahoo fixes the price history. Working backwards from today, it shrinks every earlier price by a multiplier each time a dividend was paid:
\[M_{t-1} = 1 - \frac{D_t}{P_{t-1}} = \frac{P_{t-1}-D_t}{P_{t-1}}\]
The return you get from these adjusted prices is
\[\frac{\tilde P_t}{\tilde P_{t-1}} = \frac{P_t}{P_{t-1} - D_t}\]
Same example: 97/(100 − 2) − 1 = 97/98 − 1 = −1.02%. That’s very close to −1%, but not identical to the textbook formula. The slides point this out deliberately: textbook gross return = (P_t + D_t)/P_{t−1}; Yahoo = P_t/(P_{t−1} − D_t). Both fix the problem; they’re just slightly different conventions.
Stock splits. If 1 share becomes 4, the price drops to ¼, but nobody lost 75%. Yahoo’s adjusted price also corrects for this. It’s very important for stocks like Apple, which has split several times.
In R: quote = "Adjusted" gives you the
cleaned series. "Close" is the raw price.
Say it in one sentence: dividends and splits make the raw price drop without investors losing money, so we use adjusted prices (or add the dividend back) to get true returns.
🧠 Story. - Long: you buy a share for $100 and sell it later for $110. Profit $10. You win when the price rises. - Short: you borrow a share from your broker and sell it now for $100. Later you buy it back for $90 and return it. Profit $10. You win when the price falls.
Short-selling = “sell first, buy back later”. In a portfolio it shows up as a negative weight.
Weights example: you have $1,000. You short $500 of stock B (getting $500 cash), then buy $1,500 of stock A. - w_A = 1500/1000 = 1.5, w_B = −500/1000 = −0.5. They still sum to 1 ✅.
Say it in one sentence: long means you own it and gain if it rises; short means you sold it without owning it and gain if it falls, which shows up as a negative portfolio weight.
🧠 Story. Put 60% of your money in BHP and 40% in CBA. If BHP makes 10% and CBA makes 5%, your total is 0.6×10% + 0.4×5% = 8%. It’s just a weighted average.
🔢 Formula decoded. - \(X_0\) = total money invested; \(X_{0i}\) = money in asset i. - Weight \(w_i = X_{0i}/X_0\), and the weights sum to 1. - Value at the end: \(X_1 = \sum_i (1+R_i) w_i X_0\). - Portfolio return: \(R_p = \sum_i w_i R_i\) - Expected portfolio return: \(E(R_p) = \sum_i w_i E(R_i)\). Again, a weighted average of each asset’s expected return.
Say it in one sentence: the portfolio’s (expected) return is the weighted average of the assets’ (expected) returns, using the money weights.
🧠 Story. Picture an umbrella seller and an ice-cream seller. Each one alone has a risky income, because it depends on the weather. If you own both businesses, a rainy day hurts ice cream but helps umbrellas. Your total income is steadier than either one alone. That’s diversification, and it works because the two move in different directions (low or negative covariance).
🔢 Formula decoded (two assets, weight α in asset 1 and 1 − α in asset 2):
\[\text{Var}(R_p) = \alpha^2\sigma_1^2 + (1-\alpha)^2\sigma_2^2 + 2\alpha(1-\alpha)\sigma_{12}\]
General form for n assets (slide 31): \(\text{Var}(R_p) = \sum_i w_i^2\sigma_i^2 + 2\sum_{i<j} w_i w_j \sigma_{ij} = \mathbf{w}'V\mathbf{w}\) - w = the column of weights; V = the variance-covariance matrix (variances on the diagonal, covariances off it). “w′Vw” is just compact matrix notation for the same sum. You’ll see it a lot in Week 2.
Worked example (made-up weekly numbers): - Stock A: mean 1.0%, SD 4%. Stock B: mean 0.5%, SD 2%. Correlation ρ = 0.2, so σ_AB = 0.2 × 0.04 × 0.02 = 0.00016. - 50/50 portfolio: - Mean = 0.5(1.0%) + 0.5(0.5%) = 0.75% - Var = 0.25(0.0016) + 0.25(0.0004) + 2(0.5)(0.5)(0.00016) = 0.0004 + 0.0001 + 0.00008 = 0.00058 - SD = √0.00058 = 2.41% - The naive weighted average of the SDs would be 3%. Diversification brought it down to 2.41%.
How correlation changes the 50/50 portfolio’s SD:
| Correlation ρ | 50/50 SD | Meaning |
|---|---|---|
| +1 | 3.00% | Perfectly together: no diversification benefit at all |
| +0.2 | 2.41% | Some benefit |
| 0 | 2.24% | More benefit |
| −1 | 1.00% | Perfect opposites: maximum benefit |
Say it in one sentence: portfolio risk depends on each asset’s risk and on how they move together; the lower the correlation, the more the risks cancel, so portfolio SD is below the weighted average of SDs (unless ρ = 1).
🧠 Story. Try every possible mix of A and B (0% A, 1% A, 2% A … 100% A) and plot each one as a dot: risk (SD) on the x-axis, expected return on the y-axis. The dots trace a curve bending to the left, like a bullet or the nose of a plane. - The left-most point is the minimum variance portfolio (MVP): the safest possible mix. - The upper half of the curve, above the MVP, is the efficient frontier. - The lower half is inefficient. For any point on it, there’s a point directly above with the same risk but more return. No sensible investor picks a point below the frontier (that’s the slide 34 “why?” question).
Worked example (same A and B):
| Weight in A (α) | Mean | SD | |
|---|---|---|---|
| 0% (all B) | 0.50% | 2.00% | |
| 14.3% | 0.57% | 1.91% | ← MVP: less risky than B alone! |
| 25% | 0.63% | 1.96% | |
| 50% | 0.75% | 2.41% | |
| 75% | 0.88% | 3.14% | |
| 100% (all A) | 1.00% | 4.00% | |
| 150% (short B) | 1.25% | 5.88% | short positions extend the curve |
Notice that adding some of the riskier stock A to B lowered the risk below B on its own (1.91% < 2.00%). That’s diversification in action. It also means “all in B” sits on the inefficient lower part: the MVP gives you more return for less risk.
(For two assets the MVP weight on asset 1 is α* = (σ₂² − σ₁₂)/(σ₁² + σ₂² − 2σ₁₂) = (0.0004 − 0.00016)/(0.00168) = 0.143. Good to recognise, but the R code finds it by just trying lots of α values.)
Slide 35: who picks what? A risk-averse investor sits near the MVP, at the bottom-left of the frontier. A risk-preferring (risk-seeking) investor moves up and to the right for higher expected return. With more than 2 assets, the efficient frontier and the MVP still exist (that’s Week 2).
The shape depends on σ₁₂ (slide 32): lower correlation makes the curve bend further left (more benefit). With ρ = +1 it’s a straight line.
Say it in one sentence: plotting all mixes on a risk-vs-return chart gives a curve; its left-most point is the minimum variance portfolio, and only the upper part (the efficient frontier) is worth choosing, because it gives the most return for each level of risk.
🧠 Story. Two investments: one earned 10% with wild swings, the other 8% and very steady. Which is “better”? The Sharpe ratio scores reward per unit of risk: how much extra return (above a safe bank-type return) you got for each unit of SD you put up with. Higher is better.
🔢 Formula decoded.
\[\text{Sharpe} = \frac{E(R_p) - r_f}{\sigma_p}\]
Worked example: risk-free rate 0.05% per week. - A: (1.0% − 0.05%)/4% = 0.24 - B: (0.5% − 0.05%)/2% = 0.23 - 50/50: (0.75% − 0.05%)/2.41% = 0.29 ← better than either stock alone, thanks to diversification!
Watch out: only compare Sharpe ratios calculated over the same frequency (weekly vs weekly). Also, the returns, r_f and SD must all be on the same time scale.
Say it in one sentence: the Sharpe ratio is excess return over the risk-free rate divided by SD, i.e. reward per unit of risk; higher is better.
This isn’t on the Week 1 slides, but it’s a recommended reading and it sets up Weeks 4–7 (extreme losses). - Skewness = lopsidedness. Negative skew means a long tail of big losses. A normal distribution has skew 0. - Kurtosis = how fat the tails are, i.e. how often extreme days happen. A normal distribution has kurtosis 3. Above 3 means “fat tails”: crashes happen more often than the normal bell curve predicts. A t-distribution with 5 degrees of freedom has kurtosis 9. - Why it matters: real stock returns have kurtosis well above 3. If you assume a normal distribution, you underestimate the risk of a crash. The rest of the course (GARCH, copulas, extreme value theory) largely exists to deal with this.
Say it in one sentence: real returns have fatter tails (kurtosis > 3) than the normal distribution, so extreme losses are more common than a bell curve suggests.
Before class: these files need the
tseriespackage, which isn’t installed yet. Run this once in RStudio’s Console (it needs internet):install.packages(c("tseries", "quadprog", "fGarch", "copula", "fExtremes", "timeSeries", "moments"))That covers every package the whole course uses.
How to run an Rmd (from the file itself): open it in RStudio and click the green ▶ on each grey chunk, top to bottom. The output appears under each chunk. Knit produces a full HTML report.
Week1_plot_prices.Rmd: BHP prices to returns| Code | What it does | Plain English |
|---|---|---|
library(tseries) |
Loads the package | “Switch on the toolbox that can download stock prices.” |
start_date <- "2006-01-01" /
ticker <- "BHP" |
Stores settings in named boxes | <- means “put this value into this name”. |
get.hist.quote(instrument = ticker, start = start_date, quote = c("Close","Adjusted"), retclass = "zoo", compression = "w") |
Downloads from Yahoo Finance | Gets BHP’s raw closing price and adjusted price,
weekly ("w"; "d" = daily,
"m" = monthly), as a zoo object (a time
series: values with dates attached). |
price <- bhp_data[, "Close"] |
Takes one column | [rows, columns]: blank rows means all rows, so this
means “every row of the Close column”. |
plot(price, ...) then
lines(adjusted_price, ...) |
Draws the raw price, then adds the adjusted one | col = colour, lwd = line width,
main = title. |
log_return <- diff(log(adjusted_price)) |
The key line | log() takes the log of every price. diff()
subtracts each value from the next. So this is exactly r_t = ln P_t − ln
P_{t−1}. |
simple_return <- exp(log_return) - 1 |
Converts log to simple | R_t = e^{r_t} − 1 |
par(mfrow = c(2,1)) |
Layout | “Put 2 plots stacked in 1 column.” |
abline(h = 0, ...) |
Adds a horizontal line at 0 | Helps you see gains and losses. |
plot(simple_return, log_return) +
abline(a=0, b=1) |
Scatter plot with a 45° line | Points on the line mean the two measures are equal. They drift off the line at the extremes. |
How to read the output: - Price plot: the adjusted line sits below the close line in earlier years, because older prices get shrunk by all the later dividends. The gap grows the further back you go. - Return plots: wiggly lines bouncing around 0. That’s what returns look like. Look for clusters of big wiggles (e.g. 2008) where calm and wild periods group together. That’s “volatility clustering”, which is Week 4’s topic (GARCH). - Scatter: almost all points lie on the 45° line. Only the big moves bend away, and they bend below the line (log < simple).
The chunk’s student questions, answered: 1. Is the difference important at 1%? No. 1% vs 0.995% is negligible. 2. Symmetric for + and −? No. The gap is bigger for negative returns (−50% gives −69%, but +50% gives +41%). 3. R = −1? log(0) = −∞. Financially, you lost everything (100% loss). - Concept check: why is the unadjusted close misleading around an ex-dividend date? The price drops by the dividend, which looks like a loss, but shareholders received that cash, so there was no real loss.
Week1_two_asset_frontier.Rmd: building the BHP–CBA
frontierThis is the class exercise (slide 36), and very likely what the syndicate task builds on.
| Code | What it does | Plain English |
|---|---|---|
get.hist.quote("BHP.AX", ..., quote = "Adjusted") |
Downloads weekly adjusted prices | .AX = the Australian (ASX) listing. |
merge(BHP = bhp_price, CBA = cba_price, all = FALSE) |
Lines the two series up by date | all = FALSE keeps only dates that both
have. |
na.omit(...) |
Drops rows with missing values | |
log_returns <- diff(log(prices)) /
simple_returns <- exp(log_returns) - 1 |
Same as before, for both columns at once | It uses simple returns because portfolios need them. |
colMeans(simple_returns) |
The mean of each column | Estimates of E(R_BHP) and E(R_CBA). |
apply(simple_returns, 2, sd) |
SD of each column | apply(data, 2, f) = “apply f to each
column” (1 would mean rows). |
cov(simple_returns) |
2×2 covariance matrix V | Diagonal = variances; off-diagonal = σ_BHP,CBA. |
cor(simple_returns) |
2×2 correlation matrix | Easier to read: the BHP–CBA number shows how much they move together. |
alpha <- seq(0, 1, length.out = 150) |
150 weights from 0 to 1 | All the mixes to try. 0–1 only means no short selling. |
expected_portfolio_return <- alpha*mean["BHP"] + (1-alpha)*mean["CBA"] |
E(R_p) for all 150 mixes at once | R does this for the whole vector in one go. |
portfolio_variance <- alpha^2*V["BHP","BHP"] + (1-alpha)^2*V["CBA","CBA"] + 2*alpha*(1-alpha)*V["BHP","CBA"] |
The variance formula from B7, typed out | Line-for-line identical to the maths. |
portfolio_sd <- sqrt(portfolio_variance) |
SD = √Var | We plot SD, not variance. |
which.min(portfolio_variance) |
Position of the smallest variance | Finds the MVP by brute force: it tried 150 mixes and picks the safest. |
plot(portfolio_sd, expected_portfolio_return, type = "l") |
Draws the curve | type = "l" = line. x = risk, y = return. |
points(...), text(...) |
Marks and labels the MVP with a red dot | |
vapply(selected, function(x) which.min(abs(alpha - x)), integer(1)) |
Finds the α closest to 0, 0.25, 0.5, 0.75 and 1 | Only used to print a neat table of 5 example mixes. Don’t stress about this syntax. |
How to read the output: - Mean/SD table: weekly numbers, e.g. a mean of 0.003 means an average of 0.3% per week. Ask which stock is riskier (bigger SD) and which returns more. - Correlation: if it’s well below 1, there’s a diversification benefit. - Frontier plot: the bullet-shaped curve. The red dot is the MVP. The bit above it is the efficient frontier. - The text then says “The MVP allocates X% to BHP and Y% to CBA”. Be ready to interpret that number in words.
Things to try (the file suggests these): - Allow
short selling with
alpha <- seq(-0.5, 1.5, length.out = 250). The curve
extends beyond both stocks. α < 0 means short BHP; α > 1 means
short CBA. - Concept check: why can the portfolio SD fall below
either asset’s SD? Because when correlation is below 1, part of one
stock’s movement cancels the other’s (see B7/B8, and the worked example
where the MVP SD of 1.91% is below B’s 2%).
The Week 1 Rmd files don’t include this, but the outline lists it. Here’s the idea:
rf <- 0.0005 # weekly risk-free rate (an assumption; use what the task gives you)
port_ret <- 0.5*simple_returns[,"BHP"] + 0.5*simple_returns[,"CBA"] # a 50/50 portfolio's weekly returns
sharpe <- mean(port_ret - rf) / sd(port_ret) # mean excess return / SD
sharpe
Try these without looking back. Answers are at the bottom.
diff(log(prices)) produce, and what
does apply(x, 2, sd) do?The afternoon case will probably ask you to repeat the class exercise
with different stocks, dates or frequency. Make sure you can: - [ ]
Download adjusted prices for 2+ tickers and merge them - [
] Compute simple and log returns, and explain why you chose simple
returns for portfolios - [ ] Report the mean, SD, covariance and
correlation, and interpret them in words - [ ] Trace
the two-asset curve, find the MVP, and state its weights - [ ] Allow
short selling and explain what changes - [ ] Compute and compare Sharpe
ratios - [ ] Write every answer as: number → what it means → why
it matters for risk
Exam-style phrasing template: “The minimum variance portfolio holds 62% BHP and 38% CBA, with weekly SD of 3.1%. This is lower than either stock alone because their correlation (0.35) is well below 1, so diversification reduces risk.”
(Fill this in tomorrow, and ask me about anything you write here.)
apply(x, 2, sd)
computes the SD of each column.