|
LoadIPVFromFile |
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 this function call.
See also LoadExternalData function.
This function requires that all IPV's are created and defined. 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. Note that if used in the Before Simulation script, to avoid overwriting the data with the default value, the IPV should be set as Simulation Scope.
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.
No "Date" parameter is used in this function.
Syntax
loaded = LoadIPVFromFile( fileName, [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.LoadIPVFromFile( externalFileName, "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
This will will load data into the dates supplied, and the remainder of the IPV will be at the default value.
Indexing works like a normal IPV depending on whether this IPV was setup for auto indexing or not. Auto indexing is recommended for this function. For example, using the above data on 20050715:
value = instrument.beta ' returns 1.112 value = instrument.beta[1] ' returns default value value = instrument.beta[2] ' returns default value
Note that this function will load date and time data into an IPV as well. The file format would then be Date, Time, column1, column2. This format will only work correctly if the instrument data is also intraday data. Note that all date time combos in the file must also be present in the instrument data file.
|