![]() |
Trading System API
3.0
Library for Simulating and Deploying Trading and Investment Strategies
|
Class mem_table represents a memory based table. mem_table objects can be used in strategies both for input and output. Note that memory requirements can grow rapidly. By default, the size of mem_table objects is limited to 2 million records. This limit can be reset via the size_limit(size_t) member. More...
#include <TSAMemTable.h>
Public Member Functions | |
mem_table (void) | |
Constructs an instance with a single field of type float8. | |
mem_table (int col_count) | |
Constructs an instance with field_count fields, all of type float8. More... | |
mem_table (const mem_table &other) | |
Copy Constructor. More... | |
mem_table (const mem_table &&other) | |
Constructor. More... | |
mem_table (const column_defs &col_def) | |
Constructs a new instance with a structure as defined by col_def. More... | |
virtual | ~mem_table (void) |
Destructor. | |
virtual void | cmp__evaluate_bar (const date_time &) override |
void | columns (const column_defs &data_def) |
Sets the table's schema. The schema defines the type, name, sequence and size (for string fields) of each field. More... | |
class column_defs | columns (void) const |
Returns the table's column structure. | |
bool | is_equal (const mem_table &other, double fp_allowance=0.0) |
Returns true if both schema and data of self are identical with other. More... | |
virtual void | isa__get_price_bar (const date_time &, instrument_price_bar &) override |
Abstract member to be implemented by derived classes. In derived classes, this member should populate priceBar with data corresponding to the current strategy date_time. If no corresponding price data exists for the given strategy date_time, then the most recently available price data may be returned, or else an exception must be thrown. More... | |
virtual date_time | isa__get_record_timestamp (void) override |
This member must be overridden, and must return the current record's timestamp which may or may not correspond to the strategy's current timestamp. More... | |
virtual bool | isa__get_time_of_next_bar (date_time &nextDateTime, const date_time ¤tDateTime) override |
Abstract member which should return the timestamp of the strategy's next price bar (nextDateTime) when given the strategy's currentDateTime. The member should return true if successful. More... | |
virtual bool | isa__implements_scheduling (void) const override |
Query if this object isa implements scheduling. More... | |
virtual std::string | isa__stream_name (void) const override |
Abstract member. In derived classes should return the data source name (e.g series_base table name). More... | |
void | name (const std::string &name) |
Sets the name. More... | |
const std::string & | name (void) const |
Returns the table name. More... | |
void | operator= (const table &other) |
Assignment operator. More... | |
virtual void | osa__append (const date_time &, std::vector< variant > &) override |
Implement this member in any derived class and to append a new record and time_stamp. More... | |
virtual void | osa__prepare_stream (const std::string &sourceName, const tsa::column_defs &dd) override |
Implement this member in any derived class. This member is called before any records are passed. Use it for initialization purposes, such as creating a new table in a series_base. More... | |
void | size_limit (size_t max) |
Sets the maximum number of records that can be held by self before an exception is thrown. This is to prevent a potential infinite loop from quickly exhausting the computer's memory. More... | |
size_t | size_limit (void) const |
Returns the maximum number of records that can be held by self. More... | |
![]() | |
virtual | ~out_stream_adaptor (void) |
Destructor. | |
virtual void | cmp__finalize (void) override |
Override this member in any derived class. It will be invoked when the strategy is finalized. Use it to deallocate memory or close any streams. | |
![]() | |
virtual void | cmp__post_evaluate_bar (const date_time &) |
bool | is_registered_with_strategy (void) const |
void | register_with_strategy (strategy *) |
![]() | |
in_stream_adaptor (void) | |
Constructor. | |
~in_stream_adaptor (void) | |
Destructor. | |
size_t | close_field_position (void) const |
Returns the index of the 'close' field. More... | |
virtual void | cmp__finalize (void) override |
void | current_value (const variant &value) |
Sets the current value. More... | |
bool | get_is_strategy_scheduler (void) const |
Returns true. More... | |
size_t | high_field_position (void) const |
Returns the index of the 'high' field. More... | |
bool | is_connected (void) const |
Returns true if the object state is 'connected'. More... | |
size_t | low_field_position (void) const |
Returns the index of the 'low' field. More... | |
size_t | open_field_position (void) const |
Returns the index of the 'open' field. More... | |
void | set_connected (bool is_connected_flag=true) |
Sets the object state to is_connected_flag. More... | |
void | stream_name (const std::string &stream_name) |
Sets the data source_name. More... | |
const std::string & | stream_name (void) const |
Returns the data source name. More... | |
virtual void | isa__set_forward_shift (size_t) |
![]() | |
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... | |
Record Operations | |
variant * | operator[] (size_t) const |
virtual class record | record (void) |
void | read (size_t index, class record &) |
virtual void | append (const class record &, append_flag_type flag=error_on_duplicate_timestamp) |
size_t | size (void) const |
Returns the number of records in self. | |
bool | empty (void) const |
Returns true if table has records. More... | |
date_time | first_timestamp (void) const |
Returns the timestamp of the first record. The first timestamp is by default the lowest (oldest). More... | |
date_time | last_timestamp (void) const |
Returns the timestamp of the last record. The last timestamp is by default the highest (most recent) record time. More... | |
void | clear (void) |
Deletes all records in self. The table's column structure is retained. | |
const variant & | at (size_t record_pos, size_t col_pos) const |
Returns the value at recordIndex and fieldIndex. More... | |
void | update (size_t record_pos, size_t col_pos, const variant &value) |
Sets the value indexed by col_pos and record_pos. The record must already exist! | |
date_time | timestamp (size_t record_pos) const |
void | delete_range (const date_time &start, const date_time &end) |
Deletes all records with timestamps between start and end (inclusive). | |
void | delete_range (size_t start, size_t end) |
Deletes all records between start index and end index (inclusive). | |
void | resize__drop_oldest (size_t newSize) |
Deletes enough records, starting with the oldest, to set the number of records to newSize. | |
void | truncate (const date_time &new_max_timestamp) |
void | append (const mem_table &other) |
Appends the records from other to self. For this operation to succeed, both tables must share compatible schemas. Furthermore, there must not be any overlap of record timestamps. | |
Bulk Data | |
void | copy (fast::table &db_table) |
Makes self a copy of db_table. | |
void | read_db_table (fast::database &db, const std::string &tableName) |
void | populate_random_records (size_t numRecords, const date_time &start, const duration &ts, bool someAsNIL=true) |
Column Operations | |
void | reset_column_count (size_t num_cols) |
void | reset_column_type (size_t column_pos, type_t new_type, size_t length=5) |
Resets the column type. More... | |
void | rename_column (size_t column_position, const std::string &new_name) |
Renames the column at column_position to new_name. More... | |
void | reset_column_properties (size_t column_position, const std::string &new_name, type_t new_type, size_t length=5) |
Resets the column properties of column at given column_position. More... | |
void | add_column (const std::string &name, const variant &type_and_default_value, size_t length=5) |
This member adds a new column to self and can be used even when self already contains data which will not be lost. The type_and_default_value argument will be used as template for all values in new column. The length argument is only relevant if the variant passed as type_and_default_value is of type string. More... | |
const std::string & | column_name (size_t position) const |
Returns the name of the column at the given position position. More... | |
type_t | column_type (size_t position) const |
Returns the type of the column at the given position position. More... | |
size_t | column_position (const std::string &column_name) const |
Returns the position of the column with given column_name. More... | |
bool | column_exists (const std::string &column_name) const |
Returns true if a column with a given column_name exists. More... | |
virtual size_t | column_count (void) const |
Returns the number of columns in the table's. More... | |
size_t | column_field_length (size_t column_position) const |
Returns the size of the column's value field. The return value (in bytes) is only relevant for fields of type_t::string. More... | |
Class mem_table represents a memory based table. mem_table objects can be used in strategies both for input and output. Note that memory requirements can grow rapidly. By default, the size of mem_table objects is limited to 2 million records. This limit can be reset via the size_limit(size_t) member.
tsa::mem_table::mem_table | ( | int | col_count | ) |
Constructs an instance with field_count fields, all of type float8.
col_count | Number of columns. |
tsa::mem_table::mem_table | ( | const mem_table & | other | ) |
Copy Constructor.
other | The other. |
tsa::mem_table::mem_table | ( | const mem_table && | other | ) |
Constructor.
other | The other. |
tsa::mem_table::mem_table | ( | const column_defs & | col_def | ) |
Constructs a new instance with a structure as defined by col_def.
col_def | The column definition. |
void tsa::mem_table::add_column | ( | const std::string & | name, |
const variant & | type_and_default_value, | ||
size_t | length = 5 |
||
) |
This member adds a new column to self and can be used even when self already contains data which will not be lost. The type_and_default_value argument will be used as template for all values in new column. The length argument is only relevant if the variant passed as type_and_default_value is of type string.
name | The name. |
type_and_default_value | The type and default value. |
length | The length. |
const variant & tsa::mem_table::at | ( | size_t | record_pos, |
size_t | col_pos | ||
) | const |
Returns the value at recordIndex and fieldIndex.
record_pos | Zero-based index of records. |
col_pos | Zero-based index of columns. |
|
virtual |
bool tsa::mem_table::column_exists | ( | const std::string & | column_name | ) | const |
Returns true if a column with a given column_name exists.
column_name | Name of the column. |
size_t tsa::mem_table::column_field_length | ( | size_t | column_position | ) | const |
Returns the size of the column's value field. The return value (in bytes) is only relevant for fields of type_t::string.
column_position | The column position. |
const std::string & tsa::mem_table::column_name | ( | size_t | position | ) | const |
Returns the name of the column at the given position position.
position | The position. |
size_t tsa::mem_table::column_position | ( | const std::string & | column_name | ) | const |
Returns the position of the column with given column_name.
column_name | Name of the column. |
type_t tsa::mem_table::column_type | ( | size_t | position | ) | const |
Returns the type of the column at the given position position.
position | The position. |
void tsa::mem_table::columns | ( | const column_defs & | data_def | ) |
Sets the table's schema. The schema defines the type, name, sequence and size (for string fields) of each field.
data_def | The data definition. |
bool tsa::mem_table::empty | ( | void | ) | const |
Returns true if table has records.
date_time tsa::mem_table::first_timestamp | ( | void | ) | const |
Returns the timestamp of the first record. The first timestamp is by default the lowest (oldest).
bool tsa::mem_table::is_equal | ( | const mem_table & | other, |
double | fp_allowance = 0.0 |
||
) |
Returns true if both schema and data of self are identical with other.
other | The other. |
fp_allowance | The allowance. |
|
overridevirtual |
Abstract member to be implemented by derived classes. In derived classes, this member should populate priceBar with data corresponding to the current strategy date_time. If no corresponding price data exists for the given strategy date_time, then the most recently available price data may be returned, or else an exception must be thrown.
date_time | The date time. | |
[in,out] | priceBar | The price bar. |
Implements tsa::in_stream_adaptor.
|
overridevirtual |
This member must be overridden, and must return the current record's timestamp which may or may not correspond to the strategy's current timestamp.
Implements tsa::in_stream_adaptor.
|
overridevirtual |
Abstract member which should return the timestamp of the strategy's next price bar (nextDateTime) when given the strategy's currentDateTime. The member should return true if successful.
This member is important when 'externally scheduling' a strategy. If the derived component is set as TIME_MASTER, then the strategy will retrieve the 'scheduling sequence' via this member.
It is important to properly handle the condition that arises when the strategy date_time reaches the timestamp of last record in the source table, at which point this member must return false.
Scheduling a strategy internal beyond this point won't be possible.
[in,out] | nextDateTime | The next date time. |
currentDateTime | The current date time. |
Implements tsa::in_stream_adaptor.
|
overridevirtual |
Query if this object isa implements scheduling.
Implements tsa::in_stream_adaptor.
|
overridevirtual |
Abstract member. In derived classes should return the data source name (e.g series_base table name).
Implements tsa::in_stream_adaptor.
date_time tsa::mem_table::last_timestamp | ( | void | ) | const |
Returns the timestamp of the last record. The last timestamp is by default the highest (most recent) record time.
void tsa::mem_table::name | ( | const std::string & | name | ) |
Sets the name.
name | The name. |
const std::string & tsa::mem_table::name | ( | void | ) | const |
Returns the table name.
void tsa::mem_table::operator= | ( | const table & | other | ) |
Assignment operator.
other | The other. |
|
overridevirtual |
Implement this member in any derived class and to append a new record and time_stamp.
time_stamp | The time stamp. | |
[in,out] | record | The record. |
Implements tsa::out_stream_adaptor.
|
overridevirtual |
Implement this member in any derived class. This member is called before any records are passed. Use it for initialization purposes, such as creating a new table in a series_base.
stream_name | Name of the stream. |
field_list | List of fields. |
Implements tsa::out_stream_adaptor.
void tsa::mem_table::rename_column | ( | size_t | column_position, |
const std::string & | new_name | ||
) |
Renames the column at column_position to new_name.
column_pos | The column position. |
new_name | New name of the column. |
void tsa::mem_table::reset_column_properties | ( | size_t | column_position, |
const std::string & | new_name, | ||
type_t | new_type, | ||
size_t | length = 5 |
||
) |
Resets the column properties of column at given column_position.
column_index | Zero-based index of the column. |
new_name | Name column name. |
new_type | New column type. |
length | The column field length. |
void tsa::mem_table::reset_column_type | ( | size_t | column_pos, |
type_t | new_type, | ||
size_t | length = 5 |
||
) |
Resets the column type.
column_pos | Zero-based position of the column. |
new_type | The new type. |
length | The column field length (for strings). |
void tsa::mem_table::size_limit | ( | size_t | max | ) |
Sets the maximum number of records that can be held by self before an exception is thrown. This is to prevent a potential infinite loop from quickly exhausting the computer's memory.
max | The maximum. |
size_t tsa::mem_table::size_limit | ( | void | ) | const |
Returns the maximum number of records that can be held by self.