Title: Programmers Guide to Unfair Advantage®


Author: Steven Davis 11/10/99

9/3/2001 - Corrected mmanal.txt and location
1/3/2000 - Changed Stock symbol to 8 characters.
9/21/2000 - Changed Stock Scanning record size to 48 bytes to add futures series.
9/27/2000 - Added Stock Sectors and Industry Groups
11/7/2000 - Adding new fields to mmanalyzer.csv and mmanalyzer.bin
9/7/2001 - Updated Stock Factsheet record for CUSIP addition. 
2/8/2002 - Added some Stock Fundamental fields. 
12/4/2002 - sdbfact2.adm: Added versioning and added some more Stock Fundamental fields.
1/6/2004 - Added descriptions of more of the cdbfact.adm fields.
1/14/2004 - Added section 7, stock adjustment records.
1/29/2004 - Added section 8, cdbadjst.adm
4/26/2004 - Added section 4.9, sdbfacts.csv
7/2/2004 - Modified section 6, to says that the cvf field is the conversion factor.
10/29/2004 - Added DyDm, Total Volume and Total Open Interest to stock scan record format in section 4.6.
1/7/2005 - Added Section 9.
3/22/2005 - Added TenDayBreakoutStudy and BollingerBandsStudy factsheet fields to sdbfact2.adm.
3/28/2005 - Added Intel Byte Ordering link.
4/25/2005 - Added section 4.10 for cdbedit.adm and sdbedit.adm.
5/12/2005 - Added section 4.11 for Market Scanner watch list information.
5/12/2005 - Added section 4.12 for Market Scanner saved scan information.
9/16/2005 - Added section 4.13 for Market Scanner command line argument.
11/8/2005 - Updated 4.1 for the cdbfact.adm new fields.
11/30/2005 - Clarified handling inactive, never existed stocks and active, haven't started stocks in sdbfact2.adm.
11/30/2005 - Added fields 73 and 74 to section 4.1.
12/27/2005 - Added section 4.14 for AmiBroker sector/industry mappings.
2/10/2006 - Added FuturesStartDate and CashStartDate.
4/20/2006 - Added long stock symbols to sdbfact2.adm
7/23/2007 - Added descriptions of more of the cdbfact.adm fields.


1. Overview


Unfair Advantage (UA) is a CSI product.  UA maintains a client-side database of end-of-day stock, futures, mutual fund, and index prices (or quotes).  UA further facilitates third party software back fulfilling ad-hoc requests, maintaining certain published format files, and optionally maintaining secondary databases in industry-standard formats.  Additionally UA provides some research capability for the purposes of debugging data transfer problems.
 

2. API Access Model


UA fulfills ad-hoc requests through an OLE automation interface designated API2.  This allows a client application to search through the set of markets and the series available for each market.  It also allows for any series to be retrieved in binary or ascii formats.  API2 is fully documented in the file c:\ua\uapi\funcspec.doc titled “UNFAIR ADVANTAGE API (API2) FUNCTIONAL SPECIFICATION” hereafter referred to as the API2 document.
 

3. File Access Model

UA also allows for secondary databases to be created and maintained.  This is done through the portfolio manager.

3.1 Portfolio Manager

The Portfolio Manager is fully documented in the UA user’s guide titled UNFAIR ADVANTAGE® REFERENCE MANUAL.  This manual ships with UA.

3.2 UA File Maintenance Model

Since all industry-standard database formats are not all-inclusive, each secondary database UA creates contains only the data the user has specified upon creation.  For example, the user may create a CSI format secondary database with a back-adjusted Corn series, a Gann Contract of Live Cattle, and the nearest-to-expire 10 Eurodollar contracts.  This specification is not trivial and is the source of much customer consternation.

When the user specifies, through the portfolio manager, what the secondary database/databases are which should be created and maintained.  The user is prompted whether immediate creation is requested.  If not, creation is delayed until the next daily update.  Notice that in several supported formats, the secondary database depends in structure on the manor in which it was built.  If the customer were to modify the secondary databases by creation, deletion, or sorting, confusion of third party software may arise.  It is thus best to follow the access guidelines supplied with the industry-standard format.

The customer must request UA contact the CSI servers whenever account information needs to be verified or when the customer wishes to update the database.  It should be pointed out, that the database does not update itself and that the customer must be diligent in this matter.  I do not point this out to be snide, but rather a customer once tried to sue CSI on this point.

The UA database has an intrinsic “current date.”  The “current date” is the last date for which UA has information.  When UA updates, updates available on the “current date” is reacquired to allow for phases data availability and quick-corrections.  Then UA acquires any and all updates, which has since become available.  UA then applies the updates:

1. UA first updates its customer account records.
2. UA updates its own database.
3. UA tries to update any already created secondary databases.
4. Optionally UA displays certain reports.
5. UA displays any broadcast messages.
6. UA updates any published format data files.
7. UA updates any vendor specific data files requested.
8. UA creates/recreates any secondary databases which hadn’t not yet been created or couldn’t not be updated.
9. UA executes the optional after-download-execute setting.

An example of a non-updateable is a second-day detrended series.  Every day, the detrending basis changes and every day, every price in the file could be different.  As such it is easier and more accurate to recreate that database daily.

The actual format of the daily download is compressed, encrypted, and proprietary.  We do not release the format to anyone.  However, an uncompressed, unencrypted file may be created and left for the client if he is flagged as a UA commercial account.  Before you call-up asking for this, be forewarned that it costs upwards of $3000/month for that service.
 

3.3 CSI File Access


UA can maintain a CSI format database.  The format can be found at http://www.csidata.com/formats.html.  There are two significant limitations to this format: (1) every bit is in use, but there are some numbers in the database which can not fit, and (2) negative numbers are not allowed.  Other than that, this is an excellent, quick, low-fragmentation format.
 

3.4 CSIM File Access

UA can maintain a CSIM format database.  The format can be found at http://www.csidata.com/formats.html.  This format can be read by Metastock® as if it were in Metastock format.  CSI has no relationship with Metastock.  There are two significant limitations to this format: (1) it is hard to know if you have found the right series, and (2) Metastock format reads will only recognize one volume and one open interest field.  Other than that, this is an excellent, quick format.  This is no special anti-fragmentation technology though.
 

3.5 Ascii File Access

This is the easiest and most frequently used database format UA can maintain.  A great deal of flexibility is possible if you make full use of the UA Ascii file settings as documented in the UA reference manual.  Major disadvantages are that it is easy to get the wrong series, that the conversion factor (number encoding scheme identifier) is nowhere written, and the updating process is much slower.  The advantage is that it can accurately handle everything currently available.  There is no special anti-fragmentation technology.
 

4.  Exposed Files

4.1 c:\ua\archives\cdbfacts.adm

This file can be read-in, but should not be held as locked.  UA sometimes writes and/or rereads it.

The cdbfacts.adm file is a comma seperated Ascii file.  This file lists the properties of each commodity market included with UA:

1. Csinum
2. Symbol
3. Exchange
4. Name
5. Cvf
6. Units
7. Contract Size (see also 58 below)
8. Point Value
9. Active Months
10. Unused
11. Minimum Tick
12. Unused
13. Unused
14. Second Symbol
15. Unused
16. Unused
17. Currency
18. Start Date
19. CommodityGroup
20. OptionStrikeDivide
21. OptionCvf
22. Unused
23. Unused
24. Option Start Date
25. Unused
26. Unused
27. Unused
28. Unused
29. Unused
30. HasOnlyCash
31. MarketTypeClassification
32. Unused
33. Unused
34. Unused
35. Unused
36. Unused
37. Unused
38. Unused
39. Unused
40. Unused.
41. Unused
42. Unused
43. SingleStockFuture_UnderlyingStockCsinum
44. Unused
45. Unused
46. Unused
47. Unused
48. Unused
49. Unused
50. Unused
51. Unused
52. Unused
53. Unused
54. Unused
55. Unused
56. AverageTotalVolume
57. CSIM Name
58. Contract Size as Number
59. Futures Have Current Volume/OpenInterst (bit 0 for volume, bit 1 for oi)
60. Ten Day Breakout Study
61. Bollinger Bands Study
62. Trading Hours
63. Unused
64. Put/Call Totals scale factor
65. Currently Expiring Contract 0
66. Date on which Contract 0 will expire
67. Currently Expiring Contract 1
68. Date on which Contract 1 will expire
69. Currently Expiring Contract 2
70. Date on which Contract 2 will expire
71. Currently Expiring Contract 3
72. Date on which Contract 4 will expire
73. Deliverable Is Inactive
74. Options are Inactive
75. Futures Start Date
76. Cash Start Date
77. Pit Trade Csinum
78. Unused
79. Unused
80. Unused
81. Futures Category
82. Close Field Type (S=Settle, T=Last Trade, A=Last Activity)

Additional columns may be present and/or unused columns may be used.  For the definitions of these fields, I recommend the API2 documentations.  The Currently Expiring Contract X information contains the expiration dates for the previous contract, the current contract, and the next two contracts when known.

4.2 c:\ua\archives\sdbfacts.adm / sdbfact2.adm

See also 4.9 c:\ua\archives\sdbfacts.csv.

This file can be opened in shared-read-only, binary mode only.  UA maintains a constant shared-read-allowed status on the file.  This is a fixed record file starting with stock 1000 with one header record.  Read the first 4 bytes to verify the version number (101) and get the record length.  Then seek back to head of the file, read one full record, and then the next record is stock 1000.  The records are as follow

typedef struct {
  short VersionNumber; // = 101 for this specification
  short RecordLength; // = 260 currently
  char unused[260-4];
} HeaderRecord;

#define MAX_SYMBOL 20
#pragma pack(push,1)
    typedef struct {
      char FreeFlag; // Free or Inactive or Active
      char unused1[1];
      char OldSymbol[8];
      char Name[40];
      char unused3[12];
      char unused7[4];
      char Symbol[MAX_SYMBOL];
      char SectorCode[2];
      char IndustryCode[2];
      char Exchange[6];
      char CvfSwitchDate[8]; "20060915"
      char Cvf[2];
      char PreSwitchCvf[2];
      char StartDate[8]; // "20060915"
      char StopDate[8]; // "20060915" only read for Inactive
      char OptionCvf[2];
      char OptionStrikeDivide[1];
      char HasStockFundamentalData[1]; // Y or ' '
      char unused6[6];
      float EarningsPerShare; // four byte float
      long OutstandingShares;
      long NumberOfInstitutionalShareHolders;
      float PercentageOfSharesHeldByInstitutions;
      float StockBeta; // four byte float
      float RevenueGrowth5Year; // four byte float
      float PE5YearAverage; //
      float DividendGrowth5Year; // four byte float
      char OptionStartDate[8];
      //char Reserved[180-174];
      float DividendYield; // four byte float
      float LatestAnnualTotalNetIncome; // four byte float
      float LatestAnnualOperatingRevenue; // four byte float
      float IncomeGrowth5Year; // four byte float
      float PriceEarningsRatio; // four byte float
      float EarningsPerShare1QtrAgo, EarningsPerShare2QtrAgo; // four byte float
      float EarningsPerShare3QtrAgo, EarningsPerShare4QtrAgo; // four byte float
      float EarningsPerShareTotalLastYear; // four byte float
      float EPSGrowth5Year; // four byte float
      float TenDayBreakoutStudy, BollingerBandsStudy; // four byte float
       char Reserved[]; // the remainder of the bytes upto RecordLength
    } StockSymbolRecord;
#pragma pack(pop)

The “FreeFlag” is F for free records (no stock ever assigned), I for inactive records (stock assigned, but no longer traded), or A for active records.  There are I records which have a blank name field forwhich there is no data.  These should be treated as an F record.  Since there are some A records which haven't started trading, check with the StartDate field before assuming that the series has data.  Unused fields allow for easy change of field sizes.  The reserved block is for future fields.  Do not make any assumption about Unused or Reserved fields.  The Sector and Industry codes must be cross referenced with the Sectors.adm and Indgroups.adm files.

The float fields consists of four space characters when null.  The HasStockFundamentalData field is helpful to see if any of these fields are likely to have values.

Be warned, that not opening the factsheet in binary mode is the most common source of aggrevation for the customer writing their own programs.  Caching is used by UA, but writes are implemented immediately.

4.3 c:\ua\mmanalyzer.csv

Multi-Market Analyzer (MMA) produces these file on a per-run basis.  MMA is a CSI product often bundled with UA.  These files are a CSV format file.  The format is subject to change and the file is not automatically updated, but rather is produced as a byproduct.  It is included here for convenience.

Suppose that you ran MMA with n series of data.

The first row of mmanalyzer.csv has column headings.

mmanalyzer.csv consists of the following columns.
Column 1 is the date.
Columns 2 to (n+1) are the closing prices lined up by date.
Columns (n+2) to (2*n+1) are the opening prices lined up by date.
Columns (2*n+2) to (3*n+1) are the Davis Unstretched Index values.
Columns (3*n+2) to (4*n+1) are zero.  In some older versions they contain the difference between the two components of the Davis Elasticity Index.
Columns (4*n+2) to (5*n+1) are the Davis Market Leadership Indices.
The (5*n+2) Column is the Davis Stretch Index.
  

4.4 c:\ua\mmanal1.txt, mmanal2.txt, mmanal3.txt

These files are also produced when MMA runs.

mmanal1.txt is redundant.

mmanal2.txt contains the correlation table (n by n).

mmanal3.txt contains the factor analysis results.  Factors being on columns.  The first row of the file is the variance for the factor.  The second row is meaningless.  The remaining n rows give the waits for each commodity in each of the factors.

If you have a large n, the number of columns will exceed the tolerances of all known spreadsheets and/or editors.

4.5 c:\ua\mmanalyzer.bin

As with c:\ua\archives\mmanalyzer.csv, a binary image is provided which is easier to read handle for low-level languages.  The binary file is also created on-demand, and the format may change.

Suppose again that n is the number of futures used.
The first four 4-byte integers are as follows, the Number of Dates (NumDates), the Number of Markets (NumMarkets), the Davis Unstretched Index lead window(UnstretchedWindowSize), and the Davis Elasticity Index window size(LeadIndicatorWindow).
The next four 4-byte integers are reserved.
The next (NumDates) 4-byte integers are the dates of the prices used.
The next (NumMarkets) 4-byte integers are the csinum’s of the markets included.
The next (NumMarkets) 1-byte integers are flags denoting whether the csinum refers to a stock.
The next (NumDates*NumMarkets) 4-byte reals are the prices used in the calculation.
All prices for a given date are consecutive.
The next ((NumDates-UnstretchedWindowSize)*NumMarkets) 4-byte reals are the Davis Unstretched Index values.
The next ((NumDates- UnstretchedWindowSize)*NumMarkets) 4-byte reals were the differences between the two components of the Davis Elasticity Index, but are now zero.
The next (NumDates*(NumMarkets- UnstretchedWindowSize -LeadIndicatorWindow+1)) 4-byte reals are the Davis Market Leadership Index values.
The next (NumDates) 4-byte reals are the Davis Stretch Index values.

4.6 c:\ua\archives\stkscn.bin

This is a fixed record file containing all recent prices for a selection of stocks.  See the UA User Manual for instructions on how to setup UA to create this file.  The record is:

typedef struct {
      long csinum, date;
      char cvf, IsStock, unused1[2];
      float open, high, low, close;
      long vol, oi, dydm, tvol, toi;
    } StockScanFileRecord;

The first record contains all zeros except the csinum which is 102 in this version and the date is the record size in bytes which is 48 in this version.  The ordering is by csinum and then by date.  The conversion factor, cvf, is the conversion factor as documented for API2.  IsStock is 1 for stocks and mutual funds.  It is 0 for futures and cash series.  When reading this file make sure to check the record size and to read through the file accordingly as this will change with later versions of UA.

4.7 c:\ua\archives\Sectors.adm

This file is a CSV file with Sector Code , "Description".

4.8 c:\ua\archives\Indgroups.adm

This file is a CSV file with Sector Code , Industry Code, "Description".
Industries are subsets of sectors.

4.9 c:\ua\archives\sdbfacts.csv

This file is a CSV file with the first row consisting of the column scriptions, and the remaining rows representing stocks in the UA system.  This file is only created if the distribution settings in UA request it.

4.10 c:\ua\archives\cdbedit.adm and sdbedit.adm

Version 102
1006,20050422,6,0,14055,4109,4035,4087,4087,4087,4105,0,0

This file is a CSV file with the first row consisting the version designation.  102 for this specification.  The remaining rows contain either commodity edits (cdbedit) or stock edits (sdbedit).
Edits have at least 13 fields.
Field
Description
csinum
The Market Number for the series
date
The date of the edit.
delivery month
Not used for regular stocks (any number allowed).  For commodities and options, this is the contract month in the format 200612 for the december 2006 contract.
strike price
Zero if not an option.  Positive for calls, Negative for puts.
open
opening price
high
high price
low
low price
close
closing price
closing bid
only used for options
closing ask
only used for options
contract volume
contract volume
contract open interest
Zero if normal stocks.

4.11 c:\ua\scanlist.txt and c:\ua\archives\watchlists\*.txt

These files are ascii files listing markets used by the Market Scanner.  For example, if you create a list of Fidelity mutual funds and store that list, then in the Market Scanner you could pull-up just those markets.  The format of the file is one market per line.  Each line has a data section and a comment section (the comment section may be omitted.)  The sections are delineated by any of the following " \t\r\n;:,".  The data section has the format "symbol(MarketType)" where the symbol may either be a valid UA symbol or a Market Number (csinum).  The MarketType can be either "S", "C", "SN", "CN", or "CF" (lower case is acceptable.)  MarketTypes, which begins with an "S" or "s", result in the symbol being searched for in the stock factsheet.  If the MarketType begins with "C" or "c", then the symbol is search for in the commodity factsheet.

4.12 c:\ua\archives\watchlists\*.scr

This document covers version 106 of these ascii file which store column templates for use in the Market Scanner.  When a user opens one of the templates in the Market Scanner, the studies called for by the template are run, and the column sizes and positions are set according to the template.

There are several sections to the file: Version Section, Display Preferences Section, Column Layout Section, Indicator Section.

The Version Section consists of the line "Version 106".

The Display Preferences Section consists of one line "XX DefaultDisplayNumDigits" where the XX refers to the number of decimal digits to which numbers are to be displayed.

The Column Layout Section begins with a line "YY Num ColumnAssignments" where the YY refers to the number of columns to be allocated.  For each column assignment, there are three lines such as
    PP PrimaryColumnId
    SS SecondaryColumnId
    WW Col Width
The PrimaryColumnId, PP, identifies which study the column concerns.  The SecondaryColumnId, CC, specifies which of the outputs of that study the column displays.  The ColumnWidth, WW, specifies how large the column should be displayed.

The Indicator Section begins with a line "ZZ Num IndicatorColumnList" which the ZZ refers to the number of studies present in the table.  For each study, there are a number of lines broken into the following paragraphs: the General paragraph, the SubColumnList paragraph, and possibly a RankColumn paragraph.

The General Paragraph of the Indicator Section contains the following lines:
    "Csinum" Title
    "" cmd
    0 Deleted
    0 SpecialType
    -8 cdbFieldNumber
    -1 LanguageId
where the Title, in this case Csinum, is the title to be displayed for that study; the cmd, which in this case is empty, refers to the interpreted expression which generates the study; the Deleted flag, in this case 0, means that the study is present is at least one column; the SpecialType can be any of the following values
      CsinumColumn=0,
      SymbolColumn=1,
      NameColumn=2,
      ExchangeColumn=3,
      BlankColumn=4,
      ComputedColumn=5,
      SectorColumn=6,
      IndustryColumn=7,
      CurrencyColumn=8,
      StartDateColumn=9,
      StopDateColumn=10,
      FromFactsheetColumn=19,
      RankingColumn=20,
; the cdbFieldNumber is only meaningful if the SpecialType is FromFactsheetColumn, in that case, the cdbFieldNumber could be one of the following (some only apply to certain types of markets)
    Invalid_FieldNum = 0,
    CsiNum_FieldNum = 1,
    Symbol_FieldNum = 2,
    Exchange_FieldNum = 3,
    Name_FieldNum = 4,
    Cvf_FieldNum = 5,
    Units_FieldNum = 6,
    ContractSizeAsText_FieldNum = 7,
    PointValue_FieldNum = 8,
    ActiveMonths_FieldNum = 9,
    Unused4_FieldNum = 10, //LastTradingDay_FieldNum = 10,
    MinimumTick_FieldNum = 11,
    Unused_Was_BranchNumber_FieldNum = 12,
    Unused_Was_BranchDate_FieldNum = 13,
    SecondSymbol_FieldNum = 14,
    Unused_FieldNum = 15,
    Unused3_Was_Scope_FieldNum = 16,
    Currency_FieldNum = 17,
    StartDate_FieldNum = 18,
    CommodityGroup_FieldNum = 19,
    OptionStrikeDivide_FieldNum = 20,
    OptionCvf_FieldNum = 21,
    FreeFlag_FieldNum = 22, // Stock only
    StopDate_FieldNum = 23, // Stock only
    OptionStartDate_FieldNum = 24,
    Unused2_Was_CurrencySubUnit_FieldNum = 25,
    SwitchCvfStartDate_FieldNum = 26, // Stock only
    PreSwitchCvf_FieldNum = 27, // Stock only
    SectorCode_FieldNum = 28, // Stock only
    IndustryCode_FieldNum = 29, // Stock only
    HasOnlyCash_FieldNum = 30, // not for stocks use only by webmaker currently
    MarketTypeClassification_FieldNum = 31, // not for stocks
    Unused_Was_CusipIdType_FieldNum = 32,
    Unused_Was_CusipId_FieldNum = 33,
    CurrentEarningsPerShare_FieldNum = 34,
    SharesOutstanding_FieldNum = 35,
    NumInstitutionalShareHolders_FieldNum = 36,
    PercentageOfSharesHeldByInstitutions_FieldNum = 37,
    StockBeta_FieldNum = 38,
    RevenueGrowth5Year_FieldNum = 39,
    EPSGrowth5Year_FieldNum = 40,
    DividendGrowth5Year_FieldNum = 41,
    SameAsForSecurityCountingPurposes_FieldNum = 42, // for commodity only
    SingleStockFuture_StockCsinum_FieldNum = 43, // for commodity only
    DividendYield_FieldNum = 44,
    LatestAnnualTotalNetIncome_FieldNum = 45,
    PE5YearAverage_FieldNum = 46,
    LatestAnnualOperatingRevenue_FieldNum = 47,
    IncomeGrowth5Year_FieldNum = 48,
    PriceEarningsRatio_FieldNum = 49,
    HasStockFundamentalData_FieldNum = 50,
    EarningsPerShare1QtrAgo_FieldNum = 51,
    EarningsPerShare2QtrAgo_FieldNum = 52,
    EarningsPerShare3QtrAgo_FieldNum = 53,
    EarningsPerShare4QtrAgo_FieldNum = 54,
    EarningsPerShareTotalLastYear_FieldNum = 55,
    AverageTotalVolume_FieldNum = 56, // for commodity only
    MSName_FieldNum = 57, // for commodity only
    ContractSizeAsNumber_FieldNum = 58,
    FuturesHaveCurrentVOI_FieldNum = 59, // bit 0 = vol, bit 1 = oi
    TenDayBreakoutStudy_FieldNum = 60,
    BollingerBandsStudy_FieldNum = 61,
    TradingHours_FieldNum = 62,
    MinimumTickOfClose_FieldNum = 63,
    PutCallTotalsDivide_FieldNum = 64,
    CurrentExpiringDydm0_FieldNum = 65,
    CurrentExpiringDate0_FieldNum = 66,
    CurrentExpiringDydm1_FieldNum = 67,
    CurrentExpiringDate1_FieldNum = 68,
    CurrentExpiringDydm2_FieldNum = 69,
    CurrentExpiringDate2_FieldNum = 70,
    CurrentExpiringDydm3_FieldNum = 71,
    CurrentExpiringDate3_FieldNum = 72,
    DeliverablesAreInActive_FieldNum = 73, // futures only
    OptionsAreInActive_FieldNum = 74, // futures only
    FuturesStartDate_FieldNum = 75, // futures only
    CashStartDate_FieldNum = 76, // futures only
; and, the LanguageId line refers to what interpreted language the cmd is to be interpreted:
      Unknown_Language = -1,
      VBScript_Language=0,
      PerlScript_Language=1,
      Perl_Language=2,
      JScript_Language=3,
      AnyLanguage_Language=4,

For each study, the General Paragraph is followed by the SubColumnList paragraph. which begins with the line "AA Num SubColumnList".  This identifies how many column descriptions go along with the study.  Each column description consists of a Title and a Sort Direction.  The title line provides the sub-column heading to be used.  The Sort Direction can be -1 for descending, 0 for non-sorted, or 1 for sorted.  At most one column may be sorted.

If the SpecialType is RankingColumn, then there is a RankColumn paragraph.  This paragraph begins with "BB Num Items Ranked".  For each of these items, the following lines are present
  DD csinum
  EE IsStock
  FF rank
  GG percentile
The DD=csinum refers to the Market Number/csinum for the series.  EE=IsStock is 0 if the market is considers a future, and 1 if the market is considered to be a stock.  FF=rank refers to the numerical rank of the issue.  GG=percentile refers into what percentile the issue resides.

4.13 Market Scanner command line

Starting with version 2.9.0, Market Scanner accepts command line arguments.

scan="c:\ua\archives\watchlists\MyScan.scr" This argument causes MS to load the desired layout after the data has been loaded.  If this argument is repeated, the results of the earlier layouts are lost, and only the last layout is visible.

4.14. ABSectors.adm/ABIndustries.adm: AmiBroker Industry and Sector mappings

These two files allow UA to map the current stock sectors and industries to AmiBroker's sectors and industries.  ABSectors.adm has the format

SS,"Name"

Where SS is the two letter UA Sector code see 4.7 for more information.  The Name is the AmiBroker sector to map the stocks into.

ABIndustries.adm has the format

SS,II,"Name"

Where SS is the two letter UA Sector code (see 4.7 for more information), and II is the two letter UA Industry code (see 4.8 for more information.).  The Name is the AmiBroker industry to map the stocks into.


5.  Studies/Indicators

5.1 How to add an indiciator.

UA scans the UA directory for "study*.ini" files.  Each .ini file has a corresponding DLL.  When UA runs a study, it creates an indata file.  UA calls the study function in the studyXXX.dll.  UA reads the outdata file, and plots the results.

5.2 Field Specifier

A field specifier is a character.  r1 is the immediate series.  If there is an overlayed graph, then a second series r2 may be present:

            case 'o': v = r1->open ; break;
            case 'h': v = r1->high ; break;
            case 'l': v = r1->low  ; break;
            case 'c': v = r1->close; break;
            case 'v': v = r1->vol  ; break;
            case 'V': v = r1->tvol ; break;
            case 'i': v = r1->oi   ; break;
            case 'I': v = r1->toi  ; break;
            case '$': v = r1->cash ; break;
            case 'O': v = r2->open; break;
            case 'H': v = r2->high; break;
            case 'L': v = r2->low  ; break;
            case 'C': v = r2->close; break;
            case 'w': v = r2->vol  ; break;
            case 'W': v = r2->tvol ; break;
            case 'p': v = r2->oi   ; break;
            case 'P': v = r2->toi  ; break;
            case 'S': v = r2->cash ; break;

5.3 The StudyXXX.Ini file

UA looks for the following fields in the Ini file.

"study","DESCRIPTION"  The selection description
"study","CHARTLABEL"  The charting abbreviation
"study","Inputs" A string formed from Field Specifiers
"study","Outputs" A string formed from Field Specifiers
"study","MIN" The minimum value attainable (Adjusted if data violates)
"study","MAX" The maximum value attainable (Adjusted if data violates)
"study","SharePriceScale" Use a value of 1 if the return is in price units or zero if not.
"study","MinimumNumDays" The user gets a warning if the number of data days is insufficient.
"study","NUMPARMS" How many parameters the study has (currently limited to 4)
For each parameter, UA looks for a section "parmX" where X is the parameter index (1-4).
parmX,"LABEL" Parameter Label
parmX,"CONTROL" Parameter Control type (EDIT or CHECK)
parmX,"DEFAULT" Default Value (TRUE=1, FALSE=0)
parmX,"TYPE" Parameter Type (INT or FLOAT)

5.4 indata file

A file name "indata" in the UA directory is created to provide the data for the study.  This file is in a space-seperated format.  Suppose that the study is listed to have m inputs.  The first line of the indata file contains the conversion factors for each of these inputs.  The remaining lines begin with the date and then each of the inputs for that date on that line.

5.5 The StudyXXX.dll file

Currently all DLL's must be 16-bit dlls.  The studyXXX.dll must export

    int FAR PASCAL Study( long *argc, long *Iparm, float *Fparm);

The arguments are defined as to be

long argc[5];
float Fparm[256];
long Iparm[256];

Where argc is
      argc[0]  = InDataCount;  (Number of data records in indata)
      argc[1]  = Inputs.GetLength(); (Number of parameters based on the ini file)
      argc[2]  = Outputs.GetLength(); (Number of outputs base on the ini file)
      argc[3]  = Number of Integer parameters
      argc[4]  = Number of Float parameters
FParm and Iparm contain the parameter values.

5.6 The outdata file

The study should write its results to the file "outdata" in the UA directory.  This file has the same format as the indata file.

5.7 To refresh study

As you are developing your study, you may notice that everytime you go to choose a study, it has reread the directory.  Everytime it runs a study, it is reopening the dll.
 

6. CSI data format partial specification


The following is taken from the CSI(R) Format document available at http://www.csidata.com/.  I have included the information about the QMASTER2 and DT2 files.  This is sufficient for Unfair Advantage users who do not need for their code to read data from other sources nor write data for a third party.

OVERVIEW

CSIr Format data is stored in a number of coordinated files all in the same directory.  Another directory may also contain CSI Format data, but there is no coordination of files between different directories.  Every a CSI Format data directory must have a master list file called QMASTER.  Starting with version 2.4.0 of Unfair Advantage, CSI Format data directories also contain a QMASTER2 file.  The QMASTER2 file contains and expands upon the information in the QMASTER file.  If the QMASTER2 file is present, it should be read rather than the QMASTER.

The master list identifies what data series are stored in the CSI Format data directory.  The Nth series described in the master list may have a deleted flag other than ‘0’.  If the deleted flag for the Nth series is ‘0’, then the directory may contain files FXXX.dta or FXXXXXXX.dta and FXXX.dt2 or FXXXXXXX.dt2.  If N is less than 1000, then the FXXX.dta and FXXX.dt2 should be looked for.  If N is 1000 or greater, then FXXXXXXX.dta and FXXXXXXX.dt2 should be looked for.  In either case the XXX represents a zero-filled, right-justified text representation of N.  For example, if N is 56, then you would look for F056.dta and F056.dt2.  If N were 5612, then you would look for F0005612.dta and F0005612.dt2.  Some software sorts the CSI directory.  They do this by rearranging the order of the entries in the QMASTER and QMASTER2 files and by renaming the corresponding data files.  It is important, therefore, to always search the master list file to find the item of interest.  Not to rely on the placement of the data within the master list file to be constant.

The FXXX.dt2/FXXXXXXX.dt2 file contains and expands upon the information contained in the corresponding FXXX.dta/FXXXXXXX.dta file.  If both the FXXX.dta and FXXX.dt2 files are present, the .dt2 file should be preferred.

FILE LAYOUT KEY

The QMASTER file consists of 120 or more QMASTER_REC records.  The QMASTER2 file consists of 120 or more QMASTER2_REC records.  A FXXX.dta/FXXXXXXX.dta file consists of one DTA_HEADER_REC record followed by one or more DTA_DATA_REC.  I should warn you that there may be more DTA_DATA_REC than data, but I will expand upon this later.  A FXXX.dt2/FXXXXXXX.dt2 file consists of one DT2_HEADER_REC record followed by one or more DT2_DATA_REC.  Again, there may be more records than data.

 QMASTER2_REC RECORD LAYOUT

QMASTER2_REC is a 128-byte record.  All binary fields are in Intel byte ordering.  A short is 2 bytes, a long is 4 bytes.

************ Start of QMASTER2_REC description ***********

struct QMASTER2_REC {
 unsigned long csinum;
 unsigned long dydm;
     long strike; // + is call, - is put, 0 is non-option
     short cvf, ocvf;  // conversion factors
     char period[1];   //File Type (D,W,M,Q,A)
     char comstock[1]; //Commodity/Stock Flag (C/S)
 char deleted[1];  //DeletedFlag
 char Unused1[1];
     char name[40];
     char Unused2[15];
     char unit[5];     //Pricing Unit
     char symbol[8];   //Stock or Commodity Symbol
     char Unused3[40];
};

The csinum is identified exchange market.  For example, 2 refers to Live Cattle trade on the Chicago Merchantile Exchange.  49622 refers to the common stock of New Millenium Media Intl trade on the NASDAQ Bulletin Board.  The csinum is only unique when qualified by the comstock flag, however.  For example, Unfair Advantage uses 2000 for both a stock and a commodity even that the stock and the commodity have nothing in common.

The delivery month field, dydm, refers to when the underlying security is deliverable.  Things which are immediately deliverable such as Grain Elevator price of Lean Hogs or which are never delivered such as stocks use the delivery month 54.  Otherwise the format is YYYYMM where YYYY is the year, including century, and MM is the month.  So the March 2002, contract would have the number 200203 in the dydm field.

The strike field, strike, refers to which option, if any, is being described.  A strike value of zero, means that the series is the stock or future itself, and not an option.  A positive value of the strike means that it is a CALL, the option right to buy something at the strike price.  A negative value means that it is a PUT, the option to sell something at the strike price (-strike).

The period field refers to what periodicity the data is summarized into.  The CSI format can handle no periodicity shorter than daily, but Daily, Weekly, Monthly, Quarterly, and Annually are supported.  Be prepared to ignore series with other values.

The combination of comstock, csinum, dydm, strike, and period is unique within a CSI Format data directory.  If the user were to wish to have a short history of Microsoft and a long history, this would not be allowed by Unfair Advantage.  If it were allowed, then since the date is not part of the QMASTER2_REC, you could have two completely duplicate records in the QMASTER2 file and not know which one the user wants you to process!

The deleted flag currently may contain a ‘0’, ‘1’, or ‘9’, though additional values may be assigned in the future.  A ‘0’ means that the record is active.  A ‘1’ means that the user have removed this data, but that it may be readded and updated in the future.  A value of ‘9’ means that the record has never been assigned any data.  Once you see your first ‘9’ record, you are free to stop looking further.
 

 Description of DT2 file

Unfair Advantage users will benefit from having a .DT2 file which extends the
DTA file.  Do not assume this file always exists.  Instead check for its existence and read the DTA file if it doesn’t exist.

************ Start of DT2_HEADER_REC description ***********

DT2_HEADER_REC RECORD LAYOUT

For the DT2 file, we have a header followed by records and then by holiday records as with the DTA file.  The new record length is 68 bytes with no padding bytes.

Structure
  FileEndRecord unsigned 4 byte integer;
  MaximumDatePointer unsigned 4 byte integer
  HighestHigh signed 4 byte integer
  LowestLow signed 4 byte integer
  FirstDate unsigned 4 byte integer (20001231 for example)
  LastDate unsigned 4 byte integer (20001231 for example)
  HighNumberFlag unsigned 1 byte integer (value 2 or greater for DT2)
  Remaining 43 bytes are reserved

All integers are in Intel byte ordering.  The record indices work the same as the DTA file.  The HighestHigh and LowestLow are in points.  The dates are in the form 20001231.  The HighNumberFlag is 2 or greater if there is a DT2 file present.
 

 ************ Start of DT2_DATA_REC description ***********

DT2_DATA_REC RECORD LAYOUT

  date is an unsigned 4 byte integer
  dydm is an unsigned 4 byte integer
  open is an signed 4 byte integer
  high is an signed 4 byte integer
  low is an signed 4 byte integer
  close is an signed 4 byte integer
  cash is an signed 4 byte integer
  ClosingBid is an signed 4 byte integer
  ClosingAsk is an signed 4 byte integer
  vol is an signed 4 byte integer
  oi is an signed 4 byte integer
  tvol is an signed 4 byte integer
  toi is an signed 4 byte integer
  dow is a signed 1 byte integer
  The remaining 15 bytes are reserved

The date is of the format 20001231.  The dydm field is of the format 200101 for the 2001 January contract.  For non-computed contracts this information is redundant with the QMASTER file, but for computed series, this field tells the users which contract was current on that day.  The prices are all in points stored as Intel integers.  The volume and open interest (and their totals) are also integers.  The dow is the same as for the DTA file.

If you are having trouble getting this to read correctly, make sure that you
have used a #pragma pack(1) or equivalent to avoid padding bytes.  Also be sure
that you are reading 4 byte integers with bytes 4, 3, 2, 1 is the
number 0x01020304 which is 16909060, not the Motorola ordering which would have
value 67305985.
 
 

7. Stock Split/Dividend file format

The stock splits, dividends, and capital gains are stored in the files c:\ua\archives\s\aXXXXXXX.txt where XXXXXXX is the Market Number for the first stock in the bundle of 200.  (a0001000.txt, a0001200.txt,...) There are currently three formats to this file 101 which is unencrypted, 102 which is encrypted, and 103 which is encrypted.  Formats 102 and 103 are not public.  Attempts to unencrypt these files put one in violation of the DMCA.  Format 101 is available for commercial and professional users.  The remainder of this section describes format 103.

Here is an example file in format 101:

Version 101
1926,20020328,Div,12
1926,20011130,Cap,546
1003,20020318,Split,1,2

The first line always contains the word Version followed by a space and the version number and a line feed (\r\n.)  The remainder of the file consists of lines demarcated by a line feed (\r\n.)  Each line consists of a number of fields separated by commas.  The first field is the Market Number for the stock to be adjusted.  The second field is the date after(and on) which the change is already factored into the data.  So for example a dividend on 20020328 should be subtracted or divided out of data strictly before that date.  Data on that date should not be modified. 

The third field identifies the kind of adjustment.  There are currently three kinds "Div", "Cap", "Split".  A "Div" record represents a dividend , and a "Cap" record represents a capital gain.  Both contain an amount in the fourth field.  The amount needs to be divided by 1000 to bring it into prices terms (a 10.00 stock which had a .10 dividend would have a 100 value in the fourth field.) 

For a "Split" record, the fourth and fifth fields are old for new which is backwards when compared with most sources.  So a 1,2 split would provide 2 shares for each 1 share the stock holder previously held.  To adjust prices prior to the split date, multiply by the number of old shares and multiply the number of new shares (1/2 in the example.)  To adjust volume, divide by the same number.

8. cdbadjst.adm: Futures Adjustment file format

The futures adjustment file is started at c:\ua\archives\cdbadjst.adm. 

The first line of the file begins with the text "Version " and is followed by the version number of the format in Ascii followed by a carriage return and line feed.  This document only describes format version 101.

If the version is 101, the remainder of the file is Ascii with carriage return and line feed seperating lines.  Each line refers to one future.  Each line is delimited by the comma character.  The first field is the csinum for the future being adjusted.  There are then zero or more adjustment records.

An adjustment record consists of 7 fields.  The first field is the VolumeVsPriceFlag.  The values are 'P' for adjusting price, 'T' for Volume and Open Interest, 'V' for Volume only, and 'O' for Open Interest only. Other values may be present.  The adjustment record should be ignored in that case. 

The second and third field of the adjustment record consists of the mindate and maxdate on which the adjustment should be supplied.  Empty values are taken to be beginning of file and end of file, respectively.

The fourths and fifth field of the adjustment record consists of the mindydm and maxdydm.  This indicates a range of contract months on which the adjustment should be supplied.  Empty values are taken to be first contract and last contract respectively.

The sixth field of the adjustment record consists of the FuturesVsCashFlag.  The values are 'Y' for futures and cash, 'N' for futures only, and 'A' for cash only.  Other values may be present and the adjustment record should be ignored in that case.

The seventh field of the adjustment record consists of the factor.  This is a floating point number which is multiplied by the appropriate data fields to make the adjustment.

If you are interested in this file, than you may also be interested that are a few hardcoded adjustments as well.

The long Guild #174 was quoted as a -3 conversion factor for futures before 199806 and for 199806 and cash before 19980511.

Also 141 and 269 have a different minimum tick for the current contract.

9. GetUaPortfolio.pl: Obtaining Uptodate Vendor Portfolios

The URL http://www.csidata.com/cgi-bin/GetUaPortfolio.pl provides uptodate vendor portfolios.  One more more Vendor Flags must be specified as arguments, and either "DateOnly" must be specified or either "MaxVersion" or "UaVersion".  The return contains Metadata followed by a blank line followed the portfile.adm.  If "BrowserReturn" is specified, then the Metadata and blank line are ommitted.  If "DateOnly" is specified, then the portfile.adm is omitted.

Currently provided Vendor Flags:
"VantPnt5=1" Vantage Point version 5 portfolio
"VantPnt6=1" Vantage Point version 6 portfolio
"VantPnt=X" Vantage Point version X portfolio
"SMM=1" Stock Market Magic portfolio
"OdatFut=1" One Day at a Time Futures portfolio
"OdatStk=1" One Day at a Time Stock portfolio
"NatOrder=1" Natural Order portfolio
"OmniFut=1" Omnitrader Futures portfolio
"OmniStk=1" Omnitrader Stock portfolio

Other Flags:
"DateOnly" Specifies that only the metainformation is to be provided, not the actual portfolio.
"MaxVersion=X" Specifies that the portfolio should conform with portfile.adm format version X.  Only X>=142 are supported
"UaVersion=X" Specifies that the portfolio should conform to the portfile.adm format in UA version X  (The OLE property Version provides the X.)  Only X >=2.7.9 are supported.
"BrowserReturn" Specifies that the metadata is not requested.

The Metadata consists of a number of lines of the format MetaTag:TagValue.  MetaTag currently may be "error" or "valid".  Any other tags should be ignored.  If the MetaTag is "valid" then the TagValue is the last date on which any of the requested portfolios changed.  If the MetaTag is "error" then the TagValue contains an error message, and the portfile.adm part of the message should be ignored if present.

Example, downloading http://www.csidata.com/cgi-bin/GetUaPortfolio.pl?UaVersion=2.7.9&OdatStk=1  will provide a copy of the One Dat at a Time Stock portfolio compatiable with version 2.7.9 prepended by "valid: 20050105\n\n".