RealTest User Guide
RealTest User Guide

 

 

Navigation: Realtest Script Language > Script Sections > Data Section >

DataValueFile Items

 

 

 

 

Most Data Section items in most scripts will specify formulas to calculate the data values. 

DataValueFile items are a special exception to this rule. Rather than calculating their values, these items read them from a CSV file.

This feature can be thought of as a way to add any number of additional columns with data from external sources to your OHLCV bar data after having already imported it.

To use a DataValueFile your Data section needs two special elements:

1.One or more DataValueFile statements to specify the path(s) to the CSV file(s) containing your custom data.

2.One or more named Data items (columns) with #DataValueFile as their definition in place of a formula

The CSV files are formatted as follows:

Date

Symbol

myData1

myData2

myData3

etc.

2020-01-02

AAPL

123.45

234.56

345.67

 

2020-01-03

AAPL

234.56

345.67

456.78

 

2020-01-04

AAPL

345.67

456.78

567.89

 

etc.

 

 

 

 

 

 

The first row is a header row with Date and Symbol as the first two columns, in that order. Any number of additional columns can follow these first two. The names of these columns must match the #DataValueFile item names in your Data section.

Inside the file, columns must be delimited with commas, not semicolons etc. Dates can be provided in various formats. Numbers must use period as the decimal separator. Values must not be quoted. All data must be numeric -- RealTest does not allow strings in Data section arrays.

A #DataValueFile Data section item can optionally specify #DVFAlign, #DVFFill and/or #DVFPad to control how non-market dates and missing values are handled.

The Data section for the above CSV file would look like:

Data:
   DataValueFile: c:\my_folder\my_file.csv
   myData1: #DataValueFile
   myData2: #DataValueFile
   myData3: #DataValueFile

Note that these special Data item definitions do not include anything other than the above special tags -- there are no values or formulas.

RealTest will read and process every DataValueFile CSV file declared in the script at the following times:

whenever the entire Data section needs to be recalculated

whenever any #DataValueFile items have been added, modified, removed, renamed or relocated

whenever the last modified time of the file is newer than the last time the section was recalculated

When the DataValueFile CSV file(s) is(are) reloaded, every #DataValueFile item's data array is first re-initialized to all nans.

Then, for each row of each CSV file:

1.The symbol is looked up in the currently-loaded RTD file. If not found, log an error and proceed to the next row.

2.The date is looked up in the symbol's date list. If outside the entire date range of the symbol, proceed to next row without logging anything. If between two existing dates and #DVFAlign was specified, change it to the later of those two dates, otherwise log the incorrect date and proceed to the next row.

3.For each subsequent column with a header name that matches a #DataValueFile item name, read the item value and store it in the appropriate cell of the data array.

4.At the end of the file processing, if #DVFPad or #DVFFill were specified, loop over all values of all symbols. If Fill was specified (which takes precedence over Pad) then change each missing value (nan) to the last found value, else if Pad was specified then change each nan to 0.

At this point the data from the file(s) are in memory just as if they had been calculated by Data item formulas, and can be referenced by any formula in the script in all the usual ways.

 

 

 

 

Copyright © 2020-2026 Systematic Solutions, LLC