Spread Calculation

Optuma Forums Optuma Scripting Spread Calculation

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #56667
    AvatarThomas F.
    • Topics: 44
    • Replies: 49
    • Posts: 93

    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

    #56671
    MathewMathew
    • Topics: 28
    • Replies: 1,276
    • Posts: 1,304

    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

    #56675
    DarrenDarren
    • Topics: 48
    • Replies: 329
    • Posts: 377

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

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

    #56677
    AvatarThomas F.
    • Topics: 44
    • Replies: 49
    • Posts: 93

    Hi Mathew, Hi Darren,

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

    Thanks

    Thomas

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Pin It on Pinterest

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close