Announcement

Collapse
No announcement yet.

Function library available to extract symbol data for autotrading and backtesting.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Function library available to extract symbol data for autotrading and backtesting.

    This was a interest and combined effort between myself and Steve Meyer who kindly did all the coding (in a few hours!). I could have done it (highly doubtful), but not nearly as good and it would have taken me a few weeks!

    Our hope is the 10 minutes it takes to read through the comments will be well worth the effort. I definately would not trade an automated strategy again without it.

    This is hopefully a small holiday thank you from myself and Steve to the forum community for all the generous and invaluable assistance.

    Free free to improve and anyone is welcome to maintain it not all the available fields are filled in as I focused on the ones I needed for trading.

    I'm positing part of the library here inline, it's too long to post the entire EFS, and attaching the complete library source.

    Thanks to all of you who have so generously provided invaluable assistance.

    Hope this found to be helpful, it can eliminate some major trading errors (I know).

    PHP Code:
    // Written by Steve Meyer © November 2007                                            
    // Use and/or modify this code freely. If you redistribute it please include this    
    // and/or any other comment blocks and a description of any changes you make.        
    //                                                                                   
    // Dislaimer: For educational purposes only! Obviously, no guarantees what so ever   
    // and use at your own risk.                                                         

    ////////////////////////////////////////////////////////////////////////////
    // SymbolData.efsLib  - Symbol specific data retrieval function library.    
    ////////////////////////////////////////////////////////////////////////////
    //                                                                          
    // 11/21/07            --- INTRODUCTION ---           Glen Demarco          
    //                                                                          
    // The Problem:                                                             
    //                                                                          
    // When initiating Autotrading it soon became apparent that hardcoding      
    // symbol specific information, like trade size,  was necessary.            
    //                                                                          
    // Loading a strategy efs into a SPY chart for example and changing  the    
    // symbol to ES #F without changing the hardcoded size variable in the EFS  
    // and realoading the EFS means the next trade fired will be for 100 ES lots
    // or about a $7 million dollar position versus a 100 SPY $14K, a disaster  
    // waiting(I wish) to happen.                                               
    //                                                                          
    // This problem is compounded when trading multiple symbols simutaneously   
    // which is commonly done when autotrading.The only solution is maintaining 
    // many symbol specific EFS's. For myself this was very time consuming and  
    // error prone. Especially when making minor changes to the EFS that then   
    // had to be repeated many times.                                           
    //                                                                          
    // The Solution:                                                            
    //                                                                          
    // Maintain all the symbol spefific data in a common table to be dynamically
    // retrieved as needed, eliminating the need to ever hard code the data.    
    // This library allows the same strategy EFS to be used for autotrading any 
    // number of symbols. The relevant information per symbol is entered once in
    // the table of data and retrievied by a simple call to the library.        
    //                                                                          
    // The Implementation:                                                      
    //                                                                          
    // SymbolData.efsLib                                                        
    //                                                                          
    // This library contains data and functions to access the data for          
    // various currency, futures, and commodity symbols.                        
    // You must verify the values contained in the fields are correct for       
    // any symbols you use. Stock symbols should use the "default" entry        
    // so you don't need to add stock symbols unless one of the values is       
    // different from the "default" values.                                     
    ////////////////////////////////////////////////////////////////////////////
    //                                                                          
    // Instructions to use library:                                             
    // Save this file as SymbolData.efsLib in eSignal/Function Library,                                             
    // Above Main Must Include   var SL = addLibrary("SymbolData.efsLib");      
    // Define global variable to contain extracted value for ex. var vMinTick   
    // Then to retrieve vMinTick for a give symbol the following instruction    
    // vMinTick = SL.GetTickSize(getSymbol());                                  
    ////////////////////////////////////////////////////////////////////////////

    // Revision History
    // 1.0  Sept, 6, 2007  Steve Meyer
    //      Initial file creation
    // 1.2  Sept 26, 2007 Glen Demarco
    //      added symbols and updated lot size with minimum
    //      Interactive Broker lot size, Glen Demarco
    // 1.3  November 20, Glen Demarco
    //      Added commish column and instruction comment on how to use library
    //      renamed GetIBMin to GetSpreadSize and added function GetCommAmt


    ///////////////////////////////////////////////////////////////////////
    // define array to hold the symbol data. The columns in the array are  
    // as follows:                                                         
    // Symbol string, decimal places in price (-32 = price in 32nds),      
    // Lot size, Margin/leverage, tick size, $1 move = $gain,              
    // Initial Margin, Maintenance Requirements, Start time, end time,     
    // and Interactive Brokers minimum purchase size, spread and comm      
    //                                                                     
    // As an example, stocks would have an entry of:                       
    // "Symbol", 2, 100, 1, 0.01, 100, 0, 0, 930, 1600, 1                  
    // This would indicate that the stock price has 2 decimal places, the  
    // typical lot size is 100 shares, that no margin is used, that the    
    // tick size is 1 cent, and a price change of $1 on 100 shares would   
    // give a $100 gain. There is no Margin or Maintenance requirements,   
    // and stocks trade from 9:30=16:00. You must buy a minimum of 1 share 
    //                                                                     
    // If you add additional columns you must update the ArrayColumns      
    // constant to reflect the new column count, otherwise the returned    
    // values will be incorrect. 


    const ArrayColumns 12;     // update this if you add more columns to the array

    const SymbolData = new Array(
    // make entries one per line for readability purposes

    // default entry needed to ensure we return something. This must be the first entry in the array
    // symbol decimals lot  margin   tick    Pointmove IMargin Maint  start end  spread  commish
        
    "",        2,  100,    1,    0.01,     100,     0,     0,    930,  1600.05,       10,           // default to values to use for stock symbols
        
    //////////////////////////// ****** Add any new symbols below this line *********//////////////////////
        
        
    //  index futures
    // symbol decimals IB Min  margin  mintick   Pointmove  IMargin  Maint start end  spread commish
        
    "AB",      2,  1,        1,      .01,      100,       0,     0,    930,  1600,  1,    5,        // need to fill in move column with real numbers
        
    "SP",      2,  1,        1,      .10,      250,       0,     0,    930,  1600,  1,    5,
        
    "ES",      2,  1,        1,      .25,      50,        0,     0,    930,  1600,  1,    5,
        
    "ND",      2,  1,        1,      .25,      20,        0,     0,    930,  1600,  1,    5,
        
    "NQ",      2,  1,        1,      .10,      0,         0,     0,    930,  1600,  1,    5,
        
    "MV",      2,  1,        1,      .01,      0,         0,     0,    930,  1600,  1,    5,
        
    "YM",      0,  1,        1,      1,        5,         0,     0,    930,  1600,  1,    5,
        
    "SPY",     2,  100,      1,      .01,      100,       0,     0,    930,  1600,  .02,  5,
        
    "QQQQ",    2,  100,      1,      .01,      100,       0,     0,    930,  1600,  .01,  5,
        
    "IWM",     2,  100,      1,      .01,      100,       0,     0,    930,  1600,  .04,  5,
        
    "OIH",     2,  100,      1,      .01,      100,       0,     0,    930,  1600,  .10,  5,
        
    "GOOG",    2,  100,      1,      .01,      100,       0,     0,    930,  1600,  .20,  5,
        

    //  hard currencies
    // symbol decimals IB Min  margin   mintick Pointmove IMargin Maint  start end  spread commish
        
    "EUR",     4,  20000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "HKD",     4,  20000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "GBP",     4,  15000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "JPY",     2,  25000,  10000,    0.01,    100000,   0,     0,    00002400,  1,     5,
        
    "AUD",     4,  35000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "CHF",     4,  30000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5
        
    "CAD",     4,  30000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "NZD",     4,  35000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "EURGBP",  4,  20000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "EURHKD",  4,  20000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "EURJPY",  2,  20000,  10000,    0.01,    100000,   0,     0,    00002400,  1,     5,
        
    "EURCHF",  4,  20000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "EURCAD",  4,  20000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "EURAUD",  4,  20000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "GBPJPY",  2,  15000,  10000,    0.01,    100000,   0,     0,    00002400,  1,     5,
        
    "GBPAUD",  4,  15000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "GBPCAD",  4,  15000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "CHFJPY",  2,  30000,  10000,    0.01,    100000,   0,     0,    00002400,  1,     5,
        
    "AUDCHF",  4,  35000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "AUDJPY",  2,  35000,  10000,    0.01,    100000,   0,     0,    00002400,  1,     5,
        
    "AUDCAD",  4,  35000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "CADJPY",  2,  30000,  10000,    0.01,    100000,   0,     0,    00002400,  1,     5,
        
    "CADCHF",  4,  30000,  10000,    0.0001,  100000,   0,     0,    00002400,  1,     5,
        
    "GBPCHF",  4,  15000,  10000,    0.0001,  100000,   0,     0,    00002400,  1                                
        
    ); // end of SymbolData array definition
        



    ///////////////////////////////////////////////////////////////////////
    //*********************************************************************
    // Functions used to access the SymbolData array.                      
    //*********************************************************************
    ///////////////////////////////////////////////////////////////////////


        
        
    ///////////////////////////////////////////////////////////////////////
    // This function searches thru the SymbolData array looking for a      
    // symbol name that matches the passed in symbol. This function is     
    // used by all the "Get" functions to find the symbol.                 
    // It is not expected that users would call this function directly.    
    //                                                                     
    // input: symbol - the symbol name to find as a string.                
    //                                                                     
    // returns: The index of the symbol in the SymbolData array if a match 
    //          was found. Zero if no match was found.                     
    ///////////////////////////////////////////////////////////////////////
    function GetSymbolIndex(symbol)
    {
        
    // search thru the array looking for a name match. We skip the     
        // default entry. This assumes you have the correct value for the  
        // ArrayColumns constant. If you add additional columns but forget 
        // to update the ArrayColumns value, this search will not work     
        // properly. This code just checks the name field and then skips   
        // forward by ArrayColumns fields to get to the next name field.   
        
    for(var =ArrayColumnsi<SymbolData.lengthi+=ArrayColumns)
            if(
    symbol == SymbolData[i])
                return 
    i;
                
        
    // none of the names matched, so point to the default values        
        
    return 0;
    // end of function GetSymbolIndex


    ///////////////////////////////////////////////////////////////////////
    // This function returns how many digits after the decimal place this  
    // symbol has.                                                         
    //                                                                     
    // input: symbol - the symbol name to find.                            
    //                                                                     
    // returns: The number of digits after the decimal place for the given 
    //          symbol. Returns 0.01 if the symbol wasn't found.           
    ///////////////////////////////////////////////////////////////////////
    function GetDecimalPlaces(symbol)
    {
        return (
    SymbolData[GetSymbolIndex(symbol)+1]);
    // end of function GetDecimalPlaces



    ///////////////////////////////////////////////////////////////////////
    // This function returns the standard lot size for the given symbol.   
    //  The standard lot size is the minimum IB lot size for each sumbol                                                                    
    // input: symbol - the symbol name to find.                            
    //                                                                     
    // returns: The lot size for the given symbol. Returns 100 if the      
    //          symbol wasn't found.                                       
    ////////////////////////////////////////////////////////////////////////////// 
    Attached Files
    Last edited by demarcog; 11-21-2007, 04:11 PM.
    Glen Demarco
    [email protected]
Working...
X