Rs
Module 5Vectors & IteratorsLesson 3 of 822 min

windows & Log Returns

Pair consecutive prices into returns with windows(2).

windows

rust
for w in prices.windows(2) {
    let r = w[1] / w[0] - 1.0;
}

Log returns

rust
(w[1] / w[0]).ln()

Log returns add over time and match continuous models (GBM, BS).

Challenge

Compute sample variance of log returns (n-1).

Tips
  • windows(2) needs >=2 points
  • ln is natural log
  • Keep prices positive

Try it live

windows & Log ReturnsRust 2021
Loading editor…
Output
Press Run to compile and execute.