Hi,

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) ;

//CGAR Calc
V3 = (V1 / V2);
\$V4 = (1/10);
V5 = (POWER(V3,POWER=\$V4) - 1)*100;
V5

The script works fine, no problem at all.

What I now want, is to calculate the spread/difference of the rolling 10-year yield of the S&P 500 Total Return Index and the REX Performance Index.

Since I use for both charts/calculations the same script, how can I calculate the spread?

Thanks

Thomas

Hi Thomas,

You would need to start with a GetData() function. So on the S&P chart you would get the data for the German Bond.

eg

GB1 = GetData(code={select the code});

While it is not necessary, I would also add the SP into a variable so it makes the script easy to follow

eg

SP1 = Close(); // assuming this script is added to a S&P chart - if not you can also do a GetData() here.

Then you can use these in your scripts.

eg your first line would become

VS1 = CLOSE(SP1, PERIODAMOUNT=1) ;
VG1 = CLOSE(GB1, PERIODAMOUNT=1) ;
etc

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).

Hope that helps

Mathew

We have the Annual Rate of Return function ARR() that should work. For 10 years:

SP1 = GETDATA(CODE=SPX:WI);
ARR(SP1, PERIODAMT=10)

Hi Mathew, Hi Darren,

thank you for your tips. I managed the issue and it works fine.

Thanks

Thomas