Country: Senegal
You are in the Senegal edition. Type your country to switch.
Nigeria
Africa
Loading every country…
No country matches. Check the spelling, or choose "Any country" for the Global edition.
You are learning in the Senegal edition, with examples in cfa francs and from Senegal.
Your learning profile
Financial Data Lab · Lesson 2 of 8
Lab 2: computing returns in code
This lab turns a column of prices into daily returns, cumulative returns, annualised volatility and maximum drawdown in Python, and shows how to check every figure against a hand calculation on a small invented sample. It also explains simple against log returns and why returns must be computed per ticker.
This lesson is complete in writing. A video for it is on its way.
What you will learn
- By the end you can compute daily simple returns and log returns for each share in a price table with pandas.
- You can compute a cumulative return by compounding, and explain why adding returns gives the wrong answer.
- You can compute daily and annualised volatility and the maximum drawdown in code.
- You can check every figure against a hand calculation on a small invented sample.
Key terms in this lesson
- Simple return
- The change in price, plus any income, divided by the starting price over one period. Simple returns compound by multiplying, not by adding.
- Log return
- The natural logarithm of the end price divided by the start price. Log returns add up across periods, which is useful in statistics, but they differ slightly from the returns an investor actually ea…
- Drawdown
- The fall in value from a peak to a later low, usually shown as a percentage.
- Step 1: Returns multiply, they do not add, not started
- Step 2: The sample file and the return code, not started
- Step 3: Cumulative return and volatility, not started
- Step 4: Maximum drawdown in code, not started
- Step 5: Testing the code before you trust it, not started
About 8 min of reading
Step 1 of 5
Returns multiply, they do not add
Opening this step…
Step 2 of 5
The sample file and the return code
This step opens when you finish the one above.
Step 3 of 5
Cumulative return and volatility
This step opens when you finish the one above.
Step 4 of 5
Maximum drawdown in code
This step opens when you finish the one above.
Step 5 of 5
Testing the code before you trust it
This step opens when you finish the one above.
Key takeaways
The key takeaways open when you finish every step.
Lesson quiz
6 questions. You need 85% to pass.
The quiz opens when you finish every step.
Read first
Stockertim Learn is education. It explains how investing works and never recommends buying or selling anything.
Popular this week: Basics: BeginnerSenegalese markets: Beginner