How do I get monthly returns and a 12-month return from daily prices?
Turn daily closes into month-end closes and monthly returns with resample, check a month against the daily returns, compute a 12-month return, and see when a 250-day return covers another period.
After this lesson, you can compute a stock’s monthly and 12-month price returns from its daily closes.
How do I get a monthly return from daily closes?
wide.resample("ME").last() takes each stock’s last close of every calendar month, and .pct_change() on those month-end closes gives the monthly returns. BBB closed November 2025 at 27.61 dollars and December at 30.54, a December return of 10.61%, and CCC lost 12.31%.
\[
R_m = \frac{P_m}{P_{m-1}} - 1
\]
Here \(P_m\) is the close on the last trading day of month \(m\).
The panel holds made-up daily closes in dollars per share of three stocks on the New York Stock Exchange’s trading days from 3 January 2023 to 31 December 2025, one row per stock and date. .pivot() turns it into one column per stock, as in the lesson on pivot and melt. Each month’s row carries the label of its last calendar day, so November’s row reads Sunday 30 November and holds Friday 28 November’s close. The product of December’s daily growth factors gives the same monthly return, because the middle closes cancel, as in the lesson on cumprod.
monthly.pct_change(12) divides each month-end close by the close 12 months earlier, so the return on 31 December 2025 covers all of 2025. AAA gained 7.09% in 2025, BBB gained 21.72% and CCC lost 16.47%.
\[
R_{m,12} = \frac{P_m}{P_{m-12}} - 1
\]
A return over 250 trading days, wide.pct_change(250), covers the same period only in a year with 250 trading days. 2024 had 252, so AAA’s 250-day return on 31 December 2024 starts at the close of 3 January 2024 and gives −15.03%, while its 12-month return starts at the close of 29 December 2023 and gives −12.71%. In 2025, which had 250 trading days, both give 7.09%. These are price returns without dividends.
The following box computes the 12-month returns and compares AAA’s two returns at both year ends.