Extract annualized returns from daily stock returns timetable

24 views (last 30 days)
I have daily stock price data. I have converted into returns data using price2ret. That yields a timetable with daily resolution of stock returns, like this:
MCStest =
500×6 timetable
Time AAP AAPL ABBV ABC ABI1 ABKFQ
__________ ____________________ ____________________ ____________________ ____________________ ____ _____
2020-07-22 0.013707642305162 0.00280409009336856 0.00307992438542299 -0.00326655463454243 NaN NaN
2020-07-23 -0.0068967521334406 -0.0455115537324622 0.0033775143352021 0.00212169432446765 NaN NaN
2020-07-24 -0.00741282613996586 -0.00247725440494493 -0.00938486512623912 -0.00259451795841217 NaN NaN
2020-07-27 -0.00298727460325256 0.0237002892885753 0.000515318702652003 0.00231223732652311 NaN NaN
2020-07-28 -0.00435635367283988 -0.0164328805565214 -0.00463199477558924 -0.0181715901086798 NaN NaN
2020-07-29 0.0138191825300191 0.0191738741676468 0.00310260006427848 0.0117479958593129 NaN NaN
2020-07-30 0.0314407069276961 0.0121001434206156 -0.00999938572708972 -0.0110310038784591 NaN NaN
2020-07-31 -0.0178539309887822 0.0897275956093941 -0.0117658008422978 -0.0193824374329337 NaN NaN
2020-08-03 0.0160483474539514 0.025202338284134 0.0108520693847497 0.0428187978742718 NaN NaN
: : : : : : :
2022-07-05 0.0499263972648275 0.0189303849956542 0.000845532164624849 -0.016976456423204 NaN NaN
2022-07-06 -0.00295788407265366 0.00960725727445775 -0.00909521038280395 -0.00618178240261659 NaN NaN
2022-07-07 0.0122113858017691 0.0239994092995804 -0.00347484374147837 0.00679036580577988 NaN NaN
2022-07-08 -0.0059244785831444 0.00471473565344578 0.00559231602896037 0.0125023736537991 NaN NaN
2022-07-11 -0.00628437471824008 -0.0147578711265199 0.00248609048110571 -0.00862718568208682 NaN NaN
2022-07-12 0.0114959215337574 0.00683370045180129 -0.00502521841991656 0.000422275898180835 NaN NaN
2022-07-13 0.00816289917473986 -0.00253667181964532 -0.00203330492595767 -0.0160565948537854 NaN NaN
2022-07-14 0.00361242103389985 0.0204824905235388 -0.0112390642469217 0.00302005937162174 NaN NaN
2022-07-15 0.0145129259902832 0.011450121509914 0.0211383367689322 0.0192804475390485 NaN NaN
Display all 500 rows.
I would like to compute the annualized returns for each of the stocks in the table. This is proving surprisingly hard to find so I thought I would post the question. There are all kinds of more complex metrics described clearly. How do I compute the annualized returns? Ideally, it'd be nice to be able to do this using either continuous or periodic methods. Also, as you can see I need a method to clear NaN data out of the table and apparently I'm not using rmmissing correctly. I presume there's a simple way to do this without requiring advanced toolboxes that future readers of this question might not have, but toolbox-based functions would be fine too. Would also be great to be able to compute returns from a weighted portfolio of the same returns given a table of returns and a table of weights.
Thank you for your help
  4 Comments
dpb
dpb on 22 Jul 2022
Geometric mean -- the annualized return is the geometric average amount of money earned by an investment each year over a given time period.
CdC
CdC on 22 Jul 2022
Thanks. Could you perhaps show the actual command to do it? Thank you.

Sign in to comment.

Answers (1)

dpb
dpb on 23 Jul 2022
As per retime first syntax and its example,
ttAnnRet=retime(MCStest,'yearly',@geomean);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!