|
LoadExternalData |
Top Previous Next |
|
Loads data from external text files and attaches it to particular instruments. Note that if 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 Auto Index Series Variables, so they can then be accessed using the normal instrument.property usage and plotted. Option 2: Columns are not declared, but are created as sparely populated arrays. These can be accessed in a similar manner to IPV Series but cannot be plotted. These are useful to save memory when running large stock tests, and if the loaded data is quarterly or some other non daily series. Function must be placed in Before Simulation script to use this option.
If this function is used in the Before Simulation script the data is loaded just once for the entire simulation. If placed in the Before Test script, it will be loaded (refreshed) before each parameter test run. When using option 2 above, this function must be placed in the Before Simulation script in order for the implicit series to be created on the fly.
The header column names in the file itself are ignored.
Note that 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.
Syntax
loaded = LoadExternalData( fileName, dateColumn, [columnOne, columnTwo, ...] )
Parameters
Example 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 + "_ExternalData.csv"
' 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 ENDIF
NEXT
This code loads external data files which use the symbol in the name and adds two new instrument properties: beta and eps. These new properties can be accessed in other scripts like:
IF instrument.beta > 1.2 THEN
or
IF instrument.eps > instrument.eps[90] THEN
File Format The LoadExternalData call requires comma delimited text files with the first column being a date in the format YYYYMMDD. A header is required, but ignored.
A data file, "CL_ExternalData.csv", which corresponds to the above LoadExternalData call 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
When using Option 2, Trading Blox keeps only the required data in memory but lets you access the above properties as if there was data for each day in the instrument's data file. 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 so for daily bar data you will have access to the data on a daily basis updated as per the timeframes 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 |