This instrument function loads data from an external comma separated text file into one or more user created instrument property names. The data column names that match the user's previously added IPV properties names must match for the transfer to succeed.
The IPV property types must be an Auto-Index Numeric or a String series. When the IPV properties are Auto-Index Numeric series Trading Blox Builder will match the dates in the imported text file to align the property values to those same dates in the instrument where they are being added.
Each date available in the text file is less than the instrument's record dates, the instrument record dates that didn't have a matching date in the loaded text file, will leave those instrument records with the default value that Trading Blox Builder assigns when it initializes the user created Auto-Index Numeric or a String series name.
The dates where the default value in the instrument file, the default value will be used when scripting accesses a instrument record date that wasn't updated with data from the imported text file data. A solution to that will provide the last know update to a matching date record is available in an example here:
This function most often is used in the Before Simulation or Before Test script. To make this transfer work, it requires a BPV Instrument Variable to act as an instrument container. This container is needed because the instrument will need to be loaded with an instrument using the LoadSymbol function. This loading function is needed when the script sections where an instrument needs to be loaded does not support automatic Instrument Context.
Once the instrument is loaded, this LoadIPVFromFile function can then load the Instrument Data file information and update the instrument properties that match the data column names.
The LoadIPVFromFile function can work in script sections where the Instrument Context is automatically provided.
Syntax: |
---|
' No "Date" parameter is used with this function. ' is successful, and FALSE when it fails. |
Parameter: |
Description: |
---|---|
filePathName |
The name of the file to open. If no path name is given, it defaults to the location of the instrument data file. |
columnsToSkip |
Add the number of comma separated columns in the file that has the values to be added to the new IPV series properties created to store addition property data. If data is available right after the date column, enter a Zero to specify no columns should be skipped. |
[,myIPVSeries1] |
Adding More Columns is Optional: The name for the first column of data after the date and optional time. |
[,myIPVSeries2] |
Adding More Columns is Optional: The name for the second column of data after the date and optional time. |
[,etc.] |
Adding More Columns is Optional: The name of an additional column of data. |
This function will load date and time data into an IPV as well. To update the date and time, the file format would then be "Date, Time, column1, column2, etc.". This different format will work correctly only when the instrument data is an intraday data series. All date time combinations in the file must also be present in the instrument data file.
For this function example, the process requires the added text files and a IPV Numeric Series Auto-Index Properties to be created before this function can succeed. The column heading names in the text file and in the added IPV Property names must be the same. This example's uses a beta and eps for the column property names.
This image shows how one of the IPV Numeric Series Auto-Index Property used the eps name. The other property created used the beta name for the text column and for the added IPV Property:
This function example used the Before Simulation script section. That script section will only load the added data information once during the entire simulation. Before using the LoadIPVFromFile function in the Before Simulation script section, set the new IPV Numeric Auto-Index Series Property variables to System scope. This scope setting will avoid overwriting any new property data with the IPV's default Block scope setting.
The example text file below will only provide new information every new quarter in the year. This means, dates that are not in the text file columns will be set to the default value for the series. When creating a new numeric IPV property, set the default value to "-1.000000" to indicate the property update is False.
If it needs to be used with a Multi-Step simulation, the Before Test script section can be used so the added data will be refreshed before each parameter test-step execution.
To simplify the use of the example scripts below, we placed the instrument and sample data into the same disk folder location. The instrument symbol is also the first part of the added data sample. The instrument's symbol should be the lead characters in both of the files. In this example, both the symbol and added data information are fictitious symbol files created to provide a more complete example process.
Once the function loads the external property data into the symbol's added numeric series, the names in the sample data that match the names of the added IPV properties will be updated. In this case, the names of the added properties and the column names must be the same: beta & eps.
To access these new IPV properties, they can be accessed in other locations:
IF instrument.beta > 1.2 THEN
OR
IF instrument.eps > instrument.eps[90] THEN
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:
value = instrument.beta ' returns 1.112
value = instrument.beta[1] ' returns default value
value = instrument.beta[2] ' returns default value
Sample Property Data Example: |
---|
' Data is Random information created so the ' transfer process can use the following ' scripts to move the data from the sample ' into the symbol's Property data. ' ------------------------------------------- Date, beta, eps ' ------------------------------------------- ' The dates of the Sample data must match a ' date in the instrument data series for the ' data updating from the external data file ' to be successful. ' ' Added data files must be comma separated values. ' All dates in the added file must also be in the ' instrument file in the YYYYMMDD format. When a ' date in the sample file is not found in the ' instrument file, the added data will not be ' added to the instrument information. |
Example - Step 1: |
---|
Notes: •The "Mkt" variable is a BPV Instrument Type Variable that is the container that holds the loaded instrument. The Sample data in a separate file will move its column data into the instrument's same name properties. •LoadSymbol function loads the text file named column information into instrument symbol information using the Mkt.LoadIPVFromFile function. •In this example, the default location for the Sample data and its symbol-matching instrument are both in the same folder location. This means the script path and file names will be in the same folder in the disk. •The same full path is used to simplify the access and loading of an instrument and its new property. •Place the scripted example statements below into the Before Simulation script section. •Edit the disk and folder information so that is matches the names and path information you are going to use. In this case, there are 12 new IPV Property values to add to an instrument, and the instrument output results show there are 12 update symbol data records in the Results section of this table.
' ================================================================= |
Step 1 Returns: |
iSymbolExist 1 |
Example - Step 2: |
---|
Notes:•This scripting is placed into the BEFORE INSTRUMENT DAY script section. •Its only purpose is to verify and audit the transfer from the new property data file to the instrument's numeric series properties of the same name. •It is also provides a day-of-week name for the data date aligned with the new property data. •Output only shows the dates where the data from the new property values file to the instrument data records is a match. •If any data didn't get transferred, it is likely there is a date that isn't a market day in one of the files. Fix the missing data problem by validating the instrument date and the added property data dates.
' ================================================================= |
Step 2 Returns: |
Symbol,Date, Close, Beta, EPS, DayName |
Missing Property Data: |
---|
In the past, Trading Blox Builder provided the option to get the last known value when there hadn't been an update to the property for all instrument dates. This isn't an option any longer, but it can be obtained by a simple conditional statement that executes in the UPDATE INDICATORS Script Section. ' =================================================================
|
Links: |
---|
See Also: |
Edit Time: 9/21/2020 2:39:02 PM |
Topic ID#: 406 |