CFLib.org – Common Function Library Project

TranslateFuture(Future)

Last updated January 7, 2002

Version: 1 | Requires: ColdFusion 5 | Library: FinancialLib

 
Rated 0 time(s). Average Rating: 0

Description:
This tag is for developers struggling with commodity quotes. A given commodity symbol has an indicator for the year and month of the contract it represents. The month in particular cooresponds to codes dictated by commodity exchanges. This UDF unpacks a futures symbol into it's root, descriptive month, and year, and hands the values back as a structure.

Return Values:
Returns a structure.

Example:

view plain print about
<cfset futuretest = "SPU2,CH2,OH2,NGK2">
<cfloop index="future" list="#futuretest#">
    <cfset FutSym = TranslateFuture(future)>
    <cfoutput>
    Contract Root:  #futSym.Root# <br>
    Contract Month:  #futSym.Month# <br>
    Contract Year:   #FutSym.Year# <br>
    <p>
    </cfoutput>
</cfloop>

Parameters:

Name Description Required
Future The futures symbol. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Translates a Cryptic Futures symbol into a descriptive structure.
 * 
 * @param Future      The futures symbol. 
 * @return Returns a structure. 
 * @author Mark Kruger (Mkruger@cfwebtools.com) 
 * @version 1, January 29, 2002 
 */

function TranslateFuture(Symbol) {
    var    TheYear                =    '';
    var    TheMonth            =    '';
    var SymbolStruct        =    StructNew();
    
    if(Symbol IS NOT '') {
        Symbol                =    replace(Symbol,'0','');
        TheYear                =    '200' &  val(Reverse(Symbol));
        Symbol                =    Replace(symbol,val(reverse(symbol)),'');
        TheMonth            =    right(symbol,1);
        switch(TheMonth)
        {
            case 'F':    {    TheMonth    =    'January';        break;        }
            case 'G':    {    TheMonth    =    'February';        break;        }
            case 'H':    {    TheMonth    =    'March';        break;        }
            case 'J':    {    TheMonth    =    'April';        break;        }
            case 'K':    {    TheMonth    =    'May';            break;        }
            case 'M':    {    TheMonth    =    'June';            break;        }
            case 'N':    {    TheMonth    =    'July';            break;        }
            case 'Q':    {    TheMonth    =    'August';        break;        }
            case 'U':    {    TheMonth    =    'September';    break;        }
            case 'V':    {    TheMonth    =    'October';        break;        }
            case 'X':    {    TheMonth    =    'November';        break;        }
            case 'Z':    {    TheMonth    =    'December';        break;        }                
        }
        
        
        Symbol                =    left(symbol,len(symbol)-1);
        SymbolStruct.Year    =    TheYear;
        SymbolStruct.Root    =    Symbol;
        SymbolStruct.Month    =    TheMonth;
    }
    else {
        SymbolStruct        =    structnew();    
        SymbolStruct.Year    =    '';
        SymbolStruct.Root    =    '';
        SymbolStruct.Month    =    '';
    }
    return(symbolStruct);
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
11 day(s) ago

Will Belden Will Belden added
longTime
17 day(s) ago

James Sleeman James Sleeman added
quickSort
27 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
30 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson