I use a script to calculate the rolling 10-year yield of the S&P 500 Total Return Index and for a German bond total return index called “REX Performance Index”.
The script for monthly data is:
//Get current and 10 year offset closing prices
V1 = CLOSE(PERIODAMOUNT=1) ;
V2 = CLOSE(PERIODAMOUNT=1, 120) ;
Now, a better way to get the yield is just to use the Change() function. The trouble with going back “x” bars is that as soon as you change time frame the calculation is wrong (120 days will not give you the right value).
CS1 = Change(SP1, INT_TYPE=Year, INT_COUNT=10);
YS1 = (POWER(CS1 , POWER=$V4) – 1)*100; // to get it to a yearly compounded figure (we might have to add a CAGR function).