Quantitative Momentum Model Screen

My intent is to build a scan that looks at the past 12 months (starting at the present day, not necessarily going by calendar months) but excludes data from the most recent month. If we denote the oldest month as "Month12" and the most recent month as "Month0" (where the present day is the close of Month0), and if we are using the closing price ($) at month end, then we have the equation:

M = Month()
R = Return()
R(M(X)) = ((close[M(X+1)] - close[M(X)])/close[M(X+1)])+1

where X is an integer such that 0 < X < 12
X = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11; letting us look back 12 months, but pulls 11 months of data, excluding the most recent month

*to clarify, if needed: the NYSE is open an average of 252 days per year, so I figure 252/12 = 21 days = 1 trading month. If the close of Month0 is today, then we have the close of Month1 being 21 days ago, the close of Month2 being 42 days ago, etc. I would like to use this more specific measure of 1 trading month if possible; if not, ToS's default time length of 1 month will do.
*I prefer to measure price changes from close to close instead of from open to close, as open to close excludes any overnight price action that occurs between intervals


From there, I would like to calculate the 11 month cumulative return, which can be expressed as (or in another way if better/more understandable):

R(Cumulative) = R(M(11))*R(M(10))*R(M(9))*R(M(8))*R(M(7))*R(M(6))*R(M(5))*R(M(4))*R(M(3))*R(M(2))*R(M(1))


I would like to use this as a Scan that returns securities with the highest R(Cumulative) value.


I've made several attempts at coding this up, but having difficulty even after referencing anything/everything I can find via colleagues and online searches. I'm newer to ToS and ThinkScripts, doing all I can to bludgeon through this, so any/all help would be vastly appreciated and would definitely encourage me to reciprocate once I'm further along the learning and experience curves.

Kindest Regards.
 
@Autodidact's Paradox I'm not a pro, but . . . maybe try something like this -

As a line plotted on the chart . . .
Code:
declare lower;
def c = close(period = "month"); # monthly close price
def m = ((c - c[1])/c[1]) * 100; # percent change per month by close
plot scan = if c then Sum(m[1],11) else double.nan; # cumulative return past 11 months, not counting current month

and as a scan (set the aggregation to "Month")
Code:
def m = ((close - close[1])/close[1]) * 100;
def x = Sum(m[1],11);
plot scan = x >= 1; # replace 1 with whatever you want

see if it gives the results you're wanting.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

very nice concise mathematical formulation and coding @Pensar

@Autodidact's Paradox should probably include in the title that this is "Cumulative returns over a rolling 12 month period" that is part of several data points used in Quantitative Momentum Modeling, however it is one of the main components of the actual overall modeling strategy.

This strategy reminds me of the "Dogs of the Dow" strategy, however this one can be a bit more complex.
incase other people are interested here's more info on it below:

Basic Momentum Concept
Code:
https://www.cmegroup.com/education/files/jpm-momentum-strategies-2015-04-15-1681565.pdf

Code:
https://github.com/sunami09/Quantitative-Momentum-Strategy

this thread is probably nice to go in the strategy section of this forum @MerryDay

Key component(s) of Quantitative-Momentum-Strategy
References:


Code:
https://cdn.pficdn.com/cms/pgimquantsolutions/sites/default/files/static_files/pdf/QMA_Price_Momentum_or_Information_Momentum.pdf

Code:
https://alphaarchitect.com/wp-content/uploads/2021/08/The_Quantitative_Momentum_Investing_Philosophy.pdf

Code:
https://www.amazon.com/Quantitative-Momentum-Practitioners-Momentum-Based-Selection/dp/111923719X

 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
373 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top