Announcement

Collapse
No announcement yet.

YieldCurve.efs

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • YieldCurve.efs

    File Name: YieldCurve.efs

    Description:
    Plots the yield curve as a non-price study using the 3-month, 6-month, 5-year, 10-year and 30-year yields.

    Formula Parameters:
    Color: Text - cyan
    Y-Axis Increment (Pixels) - 10
    Color: Yield Points - yellow
    Color: Yield Lines - yellow
    Y-Axis Upper limit - 10

    Notes:
    Requires version 7.9 or higher.

    Download File:
    YieldCurve.efs



    EFS Code:
    PHP Code:
    /*********************************
    Provided By:                                                      
        Interactive Data Corporation (Copyright c eSignal) 2010.      
        All rights reserved. This sample eSignal Formula Script (EFS) 
        is for educational purposes only. Interactive Data Corporation
        reserves the right to modify and overwrite this EFS file with 
        each new release.                                             

    Description:        
        Yield Curve
        
    Version:            2.0  04/26/2010
        
    Formula Parameters:                     Default:
        Color: Text                Cyan
        Color: Yield Points             Yellow
        Color: Yield Lines              Yellow
        Y-Axis Increment (Pixels)       10
        Y-Axis Upper limit              10

    Notes:
       - GB symbols were changes with -PX in version 2.0

    **********************************/

    function preMain() {  
        
    setStudyTitle("Yield Curve");
        
    setShowCursorLabel(false);
        
    setDefaultBarBgColor(Color.black);
        
    setShowTitleParameters(false);
        
        var 
    fp1 = new FunctionParameter("TextFg"FunctionParameter.COLOR);
            
    fp1.setName("Color: Text");
            
    fp1.setDefault(Color.cyan);

        var 
    fp2 = new FunctionParameter("Yinc"FunctionParameter.NUMBER);
            
    fp2.setName("Y-Axis Increment (Pixels)");
            
    fp2.setLowerLimit(1);
            
    fp2.setDefault(10);

        var 
    fp3 = new FunctionParameter("cYieldDots"FunctionParameter.COLOR);
            
    fp3.setName("Color: Yield Points");
            
    fp3.setDefault(Color.yellow);

        var 
    fp4 = new FunctionParameter("cYieldLines"FunctionParameter.COLOR);
            
    fp4.setName("Color: Yield Lines");
            
    fp4.setDefault(Color.yellow);

        var 
    fp5 = new FunctionParameter("nYmax"FunctionParameter.NUMBER);
            
    fp5.setName("Y-Axis Upper limit");
            
    fp5.setLowerLimit(0);
            
    fp5.setDefault(10);
    }

    var 
    aSym = new Array(6);
    //note: 2YR bond - no access through EFS.
    aSym[0] = "BIL M3-PX";  // 3 mo
    aSym[1] = "BIL M6-PX";  // 6 mo
    aSym[2] = "";           // 2 yr  
    aSym[3] = "$FVX";       // 5 yr  
    aSym[4] = "$TNX";       // 10yr  
    aSym[5] = "$TYX";       // 30yr  

    var aMaturities = new Array(6);
    aMaturities[0] = new Array(2);
    aMaturities[1] = new Array(2);
    aMaturities[2] = new Array(2);
    aMaturities[3] = new Array(2);
    aMaturities[4] = new Array(2);
    aMaturities[5] = new Array(2);
    aMaturities[0][0] = "3";
    aMaturities[1][0] = "6";
    aMaturities[2][0] = "2yr";
    aMaturities[3][0] = "5yr";
    aMaturities[4][0] = "10yr";
    aMaturities[5][0] = "30yr";
    aMaturities[0][1] = 2;
    aMaturities[1][1] = 10;
    aMaturities[2][1] = 25;
    aMaturities[3][1] = 55;
    aMaturities[4][1] = 100;
    aMaturities[5][1] = 300;

    var 
    cTextFg Color.cyan;
    var 
    cTextBg Color.black;
    var 
    g_cYieldDots null;
    var 
    g_cYieldLines null;
    var 
    nYieldPos null;
    var 
    nYieldPos1 null;

    // pixel increments for x and y scale
    var nY 10;  // 1.00 yeild increment = 10 pixels
    var nX 1;  // space in pixels between x-axis labels (1 mo = 1 pixel)

    var bInit false;

    function 
    main(YincTextFgcYieldDotscYieldLinesnYmax) {    
        var 
    nState getBarState();
        
        if (
    getCurrentBarIndex() < -1) return;

        if (
    bInit == false) {
            
    cTextFg TextFg;
            
    g_cYieldDots cYieldDots;
            
    g_cYieldLines cYieldLines;
            
    //g_nLineThick = nLineThick;
            
    nY Yinc;
            
    bInit true;
        }

        
        if (
    nState == BARSTATE_NEWBAR) {        
            
    // draw x y axis 
            
    drawTextPixel(15020"t"Color.whiteColor.white
                
    Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.BOTTOM,
                
    null10"x-axis"1999);
            
    drawTextPixel(15020"t"Color.whiteColor.white
                
    Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.LEFT,
                
    null10"y-axis"9991);
                
            
    // draw x and y axis labels
            
    drawTextPixel(1030"Yield Curve"cTextFgcTextBg,
                
    Text.LEFT|Text.RELATIVETOTOP|Text.RELATIVETOLEFT|Text.BOLD|Text.FRAME,
                
    null10"title");
            
    drawTextPixel(801"Yield(\%)"cTextFgcTextBg,
                
    Text.LEFT|Text.RELATIVETOTOP|Text.RELATIVETOLEFT,
                
    null10"xLabel");
            
    drawTextPixel(1002"Maturity:"cTextFgcTextBg,
                
    Text.LEFT|Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT,
                
    null10"yLabel");
            
    // draw x axis scale labels
            
    var 0;
            for (
    06i++) {
                if (
    != 2) {
                    
    nYmax Math.max(nYmaxclose(0aSym[i]));
                }
            }
            
    nYmax Math.round(nYmax);
            
    0;
            while (
    <= (nY*nYmax)) {
                var 
    txt = (i/nY);
                if (
    Math.round(txt) < 10txt "0" txt.toFixed(2);
                else 
    txt txt.toFixed(2);
                
    drawTextPixel(12520+(i), txtcTextFgcTextBg
                    
    Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM,
                    
    null9"x-axis"+i);            
                    
    += (nY);
            }
            
            
    // draw y axis maturity labels and yields
            
    0;
            for (
    06i++) {
                
    // maturity labels
                
    drawTextPixel(150+(aMaturities[i][1]), 2aMaturities[i][0], cTextFgcTextBg
                    
    Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.BOTTOM,
                    
    null10"y-axis"+i);            
                
    // yields
                
    if (!= 2) {
                    
    nYieldPos1 nYieldPos;
                    
    nYieldPos getY(i);
                    if (
    0drawYieldLine(nYieldPosnYieldPos1i);
                    
    drawTextPixel(150+(aMaturities[i][1]), nYieldPos+2"u"cYieldDotscTextBg
                        
    Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM,
                        
    "Wingdings"5"yield"+i);            
                }
            }
        }
        
        return;
    }


    function 
    getY(i) {
        var 
    close(0sym(aSym[i]));
        return (
    20 + (n*nY));
    }

    function 
    drawYieldLine(xx1i) {
        var 
    nRise x1;
        var 
    1;
        if (
    == 3j--;
        var 
    nRun 150 + (aMaturities[i][1] - aMaturities[j][1]);
        var 
    nSlope nRise/nRun;
        
        var 
    start 150 aMaturities[j][1] +5;
        var 
    end 150 aMaturities[i][1]-0;
        for (var 
    cntr startcntr endcntr++) {
            
    drawTextPixel(cntrx1+(cntr*nSlope), "'"g_cYieldLinescTextBg
                
    Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.TOP,
                
    null5"yieldLine"+cntr+"_"+i);
        } 
        
        return;

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation
Working...
X