The ts_index() function

The ts_index() function converts from a time stamp to an index (offset) for a regular time series.

Syntax

mi_integer 
ts_index(ts_tsdesc   *tsdesc, 
          mi_datetime *tstamp)
tsdesc
The time series descriptor returned by ts_open().
tstamp
The time stamp to convert.

Description

Consider a time series that starts on Monday, January 1 and keeps track of weekdays. Calling ts_index() with a time stamp argument that corresponds to Monday, January 1, would return 0; a time stamp argument corresponding to Tuesday, January 2, would return 1; a time stamp argument corresponding to Monday, January 8, would return 5; and so on.

The equivalent SQL function is GetIndex.

Returns

An offset into the time series. If the time stamp falls before the time series origin, or if it is not a valid point in the calendar, -1 is returned; otherwise, the return value is always a positive integer.