Loads data from external text files and attaches it to particular instruments.



When using the instrument object it must have default context such as in the After Instrument Day script.  Normally this function is used in the Before Simulation or Before Test script, so you need to create a BPV Instrument variable to use.  It must be loaded with an instrument by using LoadSymbol before using the LoadExternalData function call.


See also LoadIPVFromFile function.


Option 1:

Declare columns to be added as Instrument Permanent  (IPV) Auto Index Series Variables, so they can then be accessed using the normal instrument.property usage and plotted.


File Format:

The LoadExternalData call requires comma delimited text files with the first column being a date in the format YYYYMMDD.


This code loads external data files which use the symbol in the name and adds two new instrument properties:




These new properties can be accessed in other scripts like:

IF instrument.beta > 1.2 THEN


IF instrument.eps > instrument.eps[90] THEN


A header is required, but ignored.  To load a  data file with this name, "CL_ExternalData.csv", using the above LoadExternalData the script might use quarterly data:

Date,     beta,  eps
20050115, 1.201, 5.8
20050415, 1.345, 6.2
20050715, 1.112, 5.3
20051015, 1.535, 6.9
20060115, 1.231, 8.4


Option 2:

Columns are not declared, but are created as sparely populated arrays.


Data loaded can be accessed in a similar manner to IPV Series, but it cannot be plotted.  This method is useful for saving memory when running large stock tests, or when the loaded data is quarterly or some other non daily series.  


Option 2 requires the function the data loading must be in Before Simulation script.   Trading Blox Builder keeps only the required data in memory, but it lets you access the above properties as if there was data for each day in the instrument's data file.


The header column names in the file itself are ignored.


For example, on 20050413, the value for the beta property will be 1.201 and on 20050415 after the close the value will be 1.345.  Note that even when using Option 1, creating an IPV, the sparsely populated data will fill in any holes as needed so there is a value at every index.  To retain the holes as a default value, use the LoadIPVFromFile function.


Property indexing uses the instrument's bar indexing.  This mean daily bar data access to the data is available as the daily basis is updated as per the time-frames in the external data file.


For example, using the above data on 20050415 after the close:

value = instrument.beta   ' returns 1.345
value = instrument.beta[1] ' returns 1.201
value = instrument.beta[2] ' returns 1.201



If this function is placed in the Before Test script, it will loaded (refresh the data by reloading it again) before each parameter test run.





loaded = LoadExternalData( fileName, dateColumn [, columnOne ] [, columnTwo ] [, etc. ] )





The name of the file to open.  When a path name is not present, function will use the default location to look for the instrument file.


The name for the column specifying the date -- "date"

[, columnOne ]

Adding More Columns is Optional: The name for the first column of data after the date

[, columnTwo ]

Adding More Columns is Optional: The name for the second column of data after the date

[, etc. ]

Adding More Columns is Optional: The name of an additional column of data.




The variable "portfolioInstrument" is a BPV instrument variable, and is loaded with LoadSymbol prior to the use of this function. The default location for these files is the location of the data for the instrument.  To use a full path, include the "C:\" and any location can be used.


VARIABLES: instrumentCount TYPE: Integer
VARIABLES: externalFileName TYPE: String
' Get the instrument count.
instrumentCount = system.totalInstruments
' Loop initializing each instrument.
FOR index = 1 TO instrumentCount STEP 1
  ' Set the portfolio instrument. "portfolioInstrument" is defined as a BPV Instrument variable.
  portfolioInstrument.LoadSymbol( index )
  ' Get the symbol for the instrument.
  externalFileName = portfolioInstrument.symbol +
  ' Print out the file name.
  PRINT "Loading External File: ", externalFileName
  ' Load the external data.
  IF NOT portfolioInstrument.LoadExternalData( externalFileName,
          "date", "beta", "eps" ) THEN
      PRINT "Could not Load External Data for ", externalFileName
NEXT ' index value


Returns a TRUE value when successful.




See Also:

Instrument Loading


Edit Time: 9/25/2017 09:09:54 AM

Topic ID#: 405


Created with Help & Manual 7 and styled with Premium Pack Version 2.80 © by EC Software