Measuring Stock Momentum from Adjusted Prices in R
Summary
The document describes a simple way to calculate and inspect stock momentum in R as part of a factor-investing exercise. The contributor uses adjusted price histories and momentum or rate-of-change functions from a technical-analysis package, then plots the resulting series with a zero reference line. For a rough cross-sectional comparison, they mark observations with nonnegative momentum, count those observations for each ticker, and rank the counts.
This is presented as an exploratory analysis of momentum as a market anomaly, not as a trading system. The approach does not specify a lookback period, portfolio formation and rebalancing rules, transaction costs, or risk adjustment. Counting positive readings also discards the magnitude of returns and may be affected by repeated, overlapping observations. The post offers a basic implementation idea, while explicitly describing its ranking method as simplistic and unsuitable as evidence of trading performance.
Key ideas
- Momentum can be computed from adjusted price series using rate-of-change functions.
- Plotting momentum against a zero line helps distinguish positive from negative readings.
- Counting positive readings by ticker gives a simple way to rank stocks.
- The proposed count ignores momentum magnitude and lacks portfolio and cost rules.
- The example is for exploratory factor analysis rather than trading evaluation.
Tags
Full text
# how to implement momentum strategy for stocks in R # how to implement momentum strategy for stocks in R Good morning, I'm implementing factor investing strategies to choose stocks to insert in a portfolio. I have calculated low volatility factor and now I would to calculate momentum of each stock so then I can confront and choose them. I'm using R Studio. I haven't understood how to implement momentum, if I have to calculate cumulative returns series simply or what. Can someone helps me? Thanks in advance! ## Answer by Chariot Black (score 2) https://quant.stackexchange.com/a/59525 Thanks to @user42108 and @amdopt for yours answers! I solved in this way: I've finding functions `momentum` and `ROC` of `TTR` package. In that package there are a lot of function to implement momentum strategies. I've downloaded time series with `tseries` and I've calculated momentum on adjusted prices. Then I putted the vector of momentum values and the 'zoo' object that contained prices and tickers side by side, and I generated multiple momentum charts, highlighted the zero axis. Then, to test the results, I created a new vector in which I assigned the value "1" to the momentum values >= 0 and the value "0" otherwise. I counted the 1's for each symbol (using the `aggregate` function) and sorted everything in descending order. Maybe it's a very simplistic way, but not having to use it for trading purposes, I made it enough. I investigate the momentum intended as a market anomaly and not for trading purposes. Sorry for my english, I'm Italian, I've been improving it :D ## Answer by user42108 (score 1) https://quant.stackexchange.com/a/59510 There are a number of resources online for momentum strategies in R, e.g. https://rviews.rstudio.com/2019/05/29/momentum-investing-with-r/ or https://alphaarchitect.com/2019/07/11/momentum-quality-and-r-code/. I'd guess R Bloggers probably covered this, too. You might want to start with those and see if they answer your question(s).
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.