vlaranjo / Vasconomics_Materials

24 stars 26 forks source link

Comparison to StockCharts.com Output #1

Closed hayesfj closed 1 year ago

hayesfj commented 3 years ago

Hello ... this is an excellent piece of work. I am new to Python and have been trying to replicate the results I see for RRG graphs on StockCharts.com. I have been testing the symbol VBR (Vanguard Small Cap Value) vs SPY (S&P 500 index), and am getting different results using your formula. I am at a loss as to why. I am using the 1 day change in each. Any thoughts on what I should look at? In the code below VBR01 is the one day change in VBR, and SPY01 is the one day change in SPY.

Thank you!

from numpy import mean, std

periods = 10

Do VBR vs SPY

Calculate JdK - RS - Relative Performance

test1_df['RS'] = (test1_df['VBR01'] / test1_df['SPY01'] -1 )

Normalize the Values

test1_df['rs_ratio'] = 100 + test1_df['VBR01'].rolling(periods).mean() test1_df['10 Day RS'] = 100 + ((test1_df['rs_ratio'] - test1_df['rs_ratio'].rolling(periods).mean()) / test1_df['rs_ratio'].rolling(periods).std() + 1)

Rounding and Excluding NA's

test1_df['10 Day RS'] = test1_df['10 Day RS'].round(2).dropna() test1_df['VBR RS']=test1_df['10 Day RS']

Calculate the Momentum of the RS-ratio

test1_df['rs_momentum']= test1_df['10 Day RS'].pct_change(periods)

Normalize the Values

test1_df['momentum_ratio'] = 100 + test1_df['rs_momentum'].rolling(periods).mean() test1_df['VBR RS Momentum'] = 100 + ((test1_df['momentum_ratio'] - test1_df['momentum_ratio'].rolling(periods).mean()) / test1_df['momentum_ratio'].rolling(periods).std() + 1)

print(test1_df.tail(25))

hayesfj commented 3 years ago

Based on the gradual increase or decrease in the values exhibited by StockCharts views, I suspect the x,y value is more of cumulative value.

vlaranjo commented 3 years ago

Hello, thank you for the nice feedback.

Yes, I noticed that the results are not equal to those of StockCharts. The issue here is that we don't know the parameters used by StocksCharts, that is, the periods there. Also, I assumed that RS Ratio and RS Momenum have the same periods, and it may be that the number of periods used in the calculation of RS Momentumis is different.

hayesfj commented 3 years ago

I agree with you. I have been trying to model this in Google Sheets to see what I could come up with. I can share the spreadsheet on Google with you if you would like. The formula I use is

For JdK RS

  1. Calculate the Relative Strength of two stocks by dividing the first price by the second.
  2. Calculate the PPO of the RS using a 10 and 20 day EMA
  3. Calculate the JdK RS as 100 + 2.5 the PPO

For JdK Momentum

  1. Calculate the PPO of the JdK RS using a 3 and 5 day EMA
  2. Calculate 100 + 2.5 the PPO
  3. The JdK Momentum is the 10 day EMA of the calculation in 2.

VBK vs SPY [image: image.png]

Thanks again

Frank

On Mon, Mar 29, 2021 at 8:51 AM vlaranjo @.***> wrote:

Hello, thank you for the nice feedback.

Yes, I noticed that the results are not equal to those of StockCharts. The issue here is that we don't know the parameters used by StocksCharts, that is, the periods there. Also, I assumed that RS Ratio and RS Momenum have the same periods, and it may be that the number of periods used in the calculation of RS Momentumis is different.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vlaranjo/Vasconomics_Materials/issues/1#issuecomment-809393638, or unsubscribe https://github.com/notifications/unsubscribe-auth/AS5Q3GOSCR2DNN4OCSXLXTLTGCHXDANCNFSM4Z3VTHKQ .

vlaranjo commented 3 years ago

Hi Frank, Let's start from the beginning. VBK or VBR against SPY doesn't appear to be coherent with the proponents of the relative strength analysis given that small cap stocks (VBK) are not part of the large cap spectrum (SPY). If you want to analyze relative strength of market caps (breakdown: small, medium and large) it would be more consistent to use Total Market cap as benchmark. A possible way to do this is to compare: SLY, MDY and SPY against TOTL.

Now when it comes to the formulas, please note that what is publicly available are only guidelines and not the formulas neither the parameters for the JdK RS and Jdk Momentum.

The piece of material that I found to be more informative on the RRG is described in Chapter 2 of book "New Frontiers in Technical Analysis" by Paul Ciana and this chapter is written by Julius de Kempenaer (Jdk) himself.

Some notes below coming from the chapter: Standard relative line is defined as: RS = close security A/close security B Weekly timeframe is used because it suited the longer time horizon of most institutions and showed less noise than a daily timeframe. RS line is still a fairly volatile line so moving averages are used. 10 week and 30 week moving averages are commented. JdK RS-Ratio definition: measures the relative strength of all elements in a universe in such a way that the numerical results are all comparable. [Note: No mention on the moving averages application to RS ratio, but if we take the hints on what was commented before we may use a 10 or 30 week moving averages]

The author moves on to comment the application of moving averages to the JdK RS-Ratio line, more specifically a 9-period trigger-line, and then mentions that "the trigger-line helps to measure is the momentum of the JdK RS-Ratio line". JdK RS-Momentum definition: uniform measure of relative momentum that can be used to further compare elements in a universe against a benchmark and against each other. [Note: It clearly seems that JDK RS-Momentum is calculated by taking the 9 week moving average of the JdK RS-Ratio]

I tried to apply this to XLK vs SPY and compare with Stockcharts. Despite not having a 100% match, the results didn't appear to be so distant. Steps:

  1. Download weekly data for XLK and SPY (from Investing.com)
  2. Calculate the change (as a ratio, not as percentage change) of XLK and SPY prices
  3. Calculate the product for the last 10 weeks of the described in (2) for both XLK and SPY
  4. Divide XLK and SPY's compound returns obtained in (4) and multiply by 100 -> JdK RS-Ratio
  5. Calculate the change (as a ratio, not as percentage change) of JdK RS-Ratio described in (4)
  6. Calculate the average for the last 9 weeks of the obtained in (5) -> JdK RS- Momentum

In the Python code I might have made a wrong interpretation of "normalization" when subtracting the value by the x-period mean and dividing by the x-period standard deviation. On the other hand, the "normalization" here probably just means that the variables are normalized to be expressed in the same unit of measure and fluctuate above/below the same level (100).

Final Note: There are still different interpretations of this as you can see by the commented in this blog: https://futures.io/traders-hideout/33247-julius-de-kempenaer-jdk-relative-rotation-graphs-rrg-aka-jdk-rs-ratio.html

Here one user who read the chapter of the book I mentioned, suggests the below:

  1. Calculate both a 10 and 30 week SMA
  2. Take MACD of above
  3. Create RS Ratio using MACD and Julius proprietary factor (1-99)
  4. Calculate 9 week SMA of RS Ratio
  5. Create RS Momentum of above.
  6. Plot RS Ratio vs. RS Momentum

Thank you, Vasco

Nath5 commented 2 years ago

@vlaranjo Any chance you could post the updated python code for the test you did in the previous comment where the results were more aligned with the StockCharts graphs?

prashantyadavs commented 1 year ago

HI guys can you please share the new calculations m really confused

vlaranjo commented 1 year ago

Hi, I suggest you read the comments above in other to reach to the correct calculations. Additionally, you may refer to "New Frontiers in Technical Analysis" by Paul Ciana, chapter 2 "Everything is Relative Strength is Everything". In this chapter, the content is discussed in depth. Thank you, Vasco

vlaranjo commented 1 year ago

I decided to delete the article and the materials as these could be misleading. I suggest anyone willing to replicate the RRG calculations to follow the notes described in previous comments. Thank you, Vasco