Trading System API  3.0
Library for Simulating and Deploying Trading and Investment Strategies
tsa::in_stream Class Reference

Record stream class. Represents a standardised interface to all data sources. Instances rely on delegates to provide access to specific data sources. Delegates must derive from class in_stream_adaptor. More...

#include <TSAStreams.h>

Inheritance diagram for tsa::in_stream:
tsa::object

Public Member Functions

 in_stream (void)
 Constructor.
 
 in_stream (const in_stream &)
 Copy Constructor.
 
virtual ~in_stream (void)
 Destructor.
 
in_stream_adaptoradaptor (void) const
 Returns a reference to the delegate object.
 
in_stream_adaptoradaptor_ptr (void) const
 Returns the pointer to the delegate object.
 
date_time begin (void)
 Returns the date_time corresponding to the start of the underlying data source. Only call this function if the underlying in_stream_adaptor is reading from an existing stream that has a defined beginning and end, such as a database table. More...
 
void connect (const std::string &stream_name)
 Connects self to a data source with given source_name.
 
void connect (in_stream_adaptor &stream_adaptor)
 Connects self to given stream_adaptor.
 
date_time end (void)
 Returns the date_time corresponding to the end of the underlying data source. Only call this function if the underlying in_stream_adaptor is reading from an existing stream that has a defined beginning and end, such as a database table. More...
 
size_t field_count (void) const
 Returns the number of fields.
 
bool field_exists (const std::string &field_name) const
 Returns true if a field with given field_name exists.
 
size_t field_index (const std::string &field_name) const
 Returns the zero based index of the given field_name.
 
const std::stringfield_name (size_t index) const
 Returns the name of the field at given index.
 
tsa::type_t field_type (const std::string &field_name) const
 
void init_auto_series (void)
 Initializes auto-series. Auto-series are the 'named' series that correspond to frequently used field names, such as 'open', 'close', 'bid', 'ask', etc. These are accessible as hard coded class members of type auto_series. See the library's user guide for further information.
 
bool is_init (void) const
 Returns true if a delegate has been set.
 
const series_core & operator() (size_t index) const
 Returns the series corresponding to the field at given index. More...
 
const series_core & operator() (const std::string &field_name_) const
 Returns the series corresponding to the field with given field_name_. More...
 
void set_forward_shift (size_t shift_)
 Forces the stream to 'look into the future' by shift_ bars. This only works for simulations for which the data series is already known. This allows the implementation of smoothing functions such as moving averages which are shifted into the future by half their period. More...
 
size_t size (void)
 Returns the number of records in the underlying data source. Only call this function if the underlying in_stream_adaptor is reading from an existing stream that has a defined beginning and end, such as a database table. More...
 
const std::stringsource (void) const
 Returns the name of the underlying data source, such as the name of a series_base table.
 
date_time timestamp (void) const
 Returns the timestamp of the record on which the cursor is currently positioned. Note that this does not necessarily correspond to the strategy timestamp (see strategy::timestamp()). If a strategy reads from multiple data streams, one of which is missing a record for a given date (holiday), then the stream will return the most recent record instead and the record timestamp will not match the timestamp returned by strategy::timestamp(). More...
 
void verify_is_init (void) const
 Throws an exception of no delegate has been set.
 
- Public Member Functions inherited from tsa::object
 object (void)
 Constructor.
 
virtual ~object (void)
 Destructor.
 
const char * class_name (void) const
 Returns the class name as returned by the 'Real Time Type Information' (RTTI) mechanism. More...
 
bool has_same_class_as (const object &other) const
 Returns true if self has the same type as other object. More...
 

Auto Series

Auto-series are the 'named' series that correspond to frequently used field names, such as 'open', 'close', 'bid', 'ask', etc. These are accessible as hard coded class members of type auto_series. Note that the library automatically creates series for all fields in a given data stream, not just the names listed below. However, if the field name does not correspond to one of the auto_series objects below, users must access the series via operator(). Record field names must be spelled exactly as the corresponding auto_series object for this mechanism to work!

is.connect(<...>);
//. . .
double close = is.close[0]; //hard coded field name - auto_series close member
//or
double net_income = is("net_income")[0]; //standard access using operator() with field name or index.

See the library's user guide for further information.

series< double > open
 Built in series object corresponding to stream field 'open'.
 
series< double > high
 Built in series object corresponding to stream field 'high'.
 
series< double > low
 Built in series object corresponding to stream field 'low'.
 
series< double > close
 Built in series object corresponding to stream field 'close'.
 
series< double > volume
 Built in series object corresponding to stream field 'volume'.
 
series< double > bid
 Built in series object corresponding to stream field 'bid'.
 
series< double > ask
 Built in series object corresponding to stream field 'ask'.
 
series< double > bidsize
 Built in series object corresponding to stream field 'bidsize'.
 
series< double > asksize
 Built in series object corresponding to stream field 'asksize'.
 
series< double > last
 Built in series object corresponding to stream field 'last'.
 
series< double > price
 Built in series object corresponding to stream field 'price'.
 
series< double > value
 Built in series object corresponding to stream field 'value'.
 
series< double > openint
 Built in series object corresponding to stream field 'openint'.
 

Detailed Description

Record stream class. Represents a standardised interface to all data sources. Instances rely on delegates to provide access to specific data sources. Delegates must derive from class in_stream_adaptor.

Member Function Documentation

date_time tsa::in_stream::begin ( void  )

Returns the date_time corresponding to the start of the underlying data source. Only call this function if the underlying in_stream_adaptor is reading from an existing stream that has a defined beginning and end, such as a database table.

Returns
A date_time.
date_time tsa::in_stream::end ( void  )

Returns the date_time corresponding to the end of the underlying data source. Only call this function if the underlying in_stream_adaptor is reading from an existing stream that has a defined beginning and end, such as a database table.

Returns
A date_time.
const series_core & tsa::in_stream::operator() ( size_t  index) const

Returns the series corresponding to the field at given index.

Parameters
indexZero-based index of the.
Returns
The result of the operation.
const series_core & tsa::in_stream::operator() ( const std::string field_name_) const

Returns the series corresponding to the field with given field_name_.

Parameters
field_name_Name of the field.
Returns
The result of the operation.
void tsa::in_stream::set_forward_shift ( size_t  shift_)

Forces the stream to 'look into the future' by shift_ bars. This only works for simulations for which the data series is already known. This allows the implementation of smoothing functions such as moving averages which are shifted into the future by half their period.

Parameters
shift_The shift.
size_t tsa::in_stream::size ( void  )

Returns the number of records in the underlying data source. Only call this function if the underlying in_stream_adaptor is reading from an existing stream that has a defined beginning and end, such as a database table.

Returns
A size_t.
date_time tsa::in_stream::timestamp ( void  ) const

Returns the timestamp of the record on which the cursor is currently positioned. Note that this does not necessarily correspond to the strategy timestamp (see strategy::timestamp()). If a strategy reads from multiple data streams, one of which is missing a record for a given date (holiday), then the stream will return the most recent record instead and the record timestamp will not match the timestamp returned by strategy::timestamp().

Returns
A date_time.