Explanation 1
The live starter code is self-contained and uses only runner-compatible functions.
Loading
Lesson 14 of 22
Document provenance, align calendars, define returns, and interpret quote direction before modelling.
Motivation
Return code can be mathematically correct and economically reversed when an adjustment field, currency quote, or calendar rule is misunderstood.
Why this matters
Document provenance, align calendars, define returns, and interpret quote direction before modelling.
Packages and data
Base R; xts, zoo, quantmod, tidyquant, and PerformanceAnalytics are optional.
Explanation 1
The live starter code is self-contained and uses only runner-compatible functions.
Explanation 2
Book-only outputs are labelled when the separate source dataset or advanced package was not supplied.
Explanation 3
R code, paths, function names, and formulas remain left-to-right in every locale.
Terminology
Price ratio minus one; compounds multiplicatively.
Pt/P(t-1)-1
Difference in log price; adds across time.
log(Pt)-log(P(t-1))
Units of one currency per another.
USD/CAD is CAD per USD
Notation and formulas
Rt = Pt/P(t-1)-1; rt = log(Pt)-log(P(t-1))
Simple and log returns are close for small movements but differ in tails and compounding.
Worked example
Scenario
How close are simple and log returns for a short USD/CAD teaching path?
R check
fx <- c(1.32,1.34,1.31,1.36,1.35,1.38)
simple <- 100*(fx[-1]/head(fx,-1)-1)
log_return <- 100*diff(log(fx))
print(data.frame(simple,log_return,difference=simple-log_return))
print(sum(log_return)/100)
print(log(tail(fx,1)/fx[1]))Because the quote is CAD per USD, a positive return means one U.S. dollar buys more Canadian dollars. Limitation: This tiny embedded path is not live market data and is not an investment recommendation.
Visual
The quote moves within a narrow range before return conversion.
R connection
Run the self-contained starter code in the protected STATLAB R runner. The code prints an auditable result and avoids network or unrestricted file access.
Live R Lab
Run a self-contained example, verify its output, and explain one limitation for financial data and return series.
Ready to run
Common mistake
Do not log interest-rate levels as though they were positive asset prices, and do not reverse quote interpretation.
STATLAB Tip
Record source, code, field, currency, time zone, adjustment, coverage, and retrieval date.
Guided practice
Scenario
Invert the quote and verify that log returns change sign.
Compare your result with the definition, units, and model assumptions—not only with a target number.
Exercises
Complete these without looking at the selected solutions. More than one defensible program may exist.
Explanation 1
Verify cumulative log return identity.
Explanation 2
Detect missing months in a date sequence.
Explanation 3
Explain why yields crossing zero need another transformation.
Selected solutions
These are compact solution routes. Confirm dimensions, units, and any changed modelling choices.
Explanation 1
sum(diff(log(fx))) equals log(tail(fx,1)/fx[1]).
Explanation 2
setdiff(seq(min(date),max(date),by='month'),date)
Explanation 3
A percentage change or log is undefined/problematic at zero or negative levels.
Chapter summary
Document provenance, align calendars, define returns, and interpret quote direction before modelling.
Explanation 1
Provenance is part of the model.
Explanation 2
Simple returns compound; log returns add.
Explanation 3
Quote units determine meaning.
Explanation 4
Calendar alignment must be explicit.
Terminology
log returns
Use in Financial Data and Return Series.
wealth index
Use in Financial Data and Return Series.
calendar alignment
Use in Financial Data and Return Series.
dated series
Use in Financial Data and Return Series.
References and provenance
Safavi (2026), Chapter 14; Bank of Canada Valet documentation. Student notes: Mohammad Safavi, Ph.D., STATLAB Academy, Version 1.0.
Resource
The authoritative 125-page English PDF accompanies this native lesson.
DownloadReflection
Name the assumption, evidence you would seek, and how the recommendation might change.
Exit check
Reach 70% to complete the chapter. Explanations appear after submission.
Checkpoint
Question 1 of 2. Answered 0/2. Passing score: 70%.