Trading System API  3.0
Library for Simulating and Deploying Trading and Investment Strategies
tsa::series< T > Class Template Reference

class series is a template class representing a sequence of values. More...

#include <TSASeriesTemplate.h>

Inheritance diagram for tsa::series< T >:
tsa::pane_format

Public Member Functions

 series (const series_core &)
 Constructor. More...
 
 series (const std::string &auto_series_name)
 Constructor. More...
 
 series (void)
 Default constructor.
 
 series (const series< T > &other)
 Copy Constructor. More...
 
 series (size_t capacity)
 Constructor. Creates an 'unmanaged' series with a fixed capacity and size 0. More...
 
virtual ~series (void)
 Destructor.
 
size_t capacity (void) const
 Returns the series capacity. Only available for 'unmanaged' series. Throws an exception if the series is 'managed'. More...
 
void clear (void)
 Clears the series. WARNING: This only works for 'unmanaged' series. See is_managed().
 
void copy (const series &other, size_t max_num_values=~(size_t) 0)
 Copies num_values from the other series, starting at position 0. If num_values is 0, it copies the entire series, which will cause the capacity of self to be reset if it is not sufficient. More...
 
bool crosses_above (const series< T > &other) const
 Returns true if self crossed above other on the most recent value. More...
 
bool crosses_above (double threshold) const
 Returns true if self crossed above other on the most recent value. More...
 
bool crosses_below (const series< T > &other) const
 Returns true if self crossed below other on the most recent value. More...
 
bool crosses_below (double threshold) const
 Returns true if self crossed below other on the most recent value. More...
 
const T * data (void) const
 Returns a pointer to the series data. The array length can be determined by calling size(). More...
 
bool empty (void) const
 Returns true if the series is empty. More...
 
void fill_to_capacity (T value)
 Clears the series and then fills it to capacity with given value. More...
 
get_at (size_t position) const
 Returns the value at given position. More...
 
bool is_equal (const series< T > &other) const
 Returns true if self has same data as other. More...
 
bool is_managed (void) const
 Query if this object is managed. More...
 
bool is_owner (void) const
 Query if this object is owner. More...
 
const series< T > & name (const std::string &name) const
 Names the given name. More...
 
series_cref< T > operator() (size_t shift_by) const
 
void operator= (series_cref< T > &)
 
void operator= (const series< T > &other)
 
operator[] (size_t position) const
 Returns the value at given position. More...
 
void plot_as (const std::string &name, const tsa::variant &period=0.0, plot_type type=plot_type::line, tsa::color clr=tsa::color::auto_color, unsigned weight=2) const
 Plot as. More...
 
void plot_as (const std::string &name, const std::vector< tsa::variant > &periods, plot_type type=plot_type::line, tsa::color clr=tsa::color::auto_color, unsigned weight=2) const
 Plot as. More...
 
void plot_info (const plot_info &pi) const
 
const tsa::plot_infoplot_info (void) const
 
void print (std::ostream &stream, size_t max=1000)
 Prints the series to given stream. At most max items will be printed. The leftmost value printed corresponds to the value at position 0. More...
 
void print_v (std::ostream &s, size_t max=1000)
 Prints the series to given stream, one data item per line. At most max items will be printed. The leftmost value printed corresponds to the value at position 0. More...
 
void push (T)
 Adds a new value to the front of the series. The new item will be accessible at position 0. More...
 
void push (const variant &)
 Adds a new value item to the front of the series. The new item will be accessible at index position 0. More...
 
void reserve (size_t capacity)
 Sets the serie's capacity to at least as high as the given capacity argument. It is not possible to shrink capacity, although trying to do so will cause no error. More...
 
void set_size (size_t new_size)
 Sets the size of self to new_size. This is a quick way to 'make space' without the overhead of calling push() for each value. new_size must be smaller or equal to the object's capacity. Values will not be initialized, and the idea is that the values will be initialized by an STL algorithm such as std::transform(). If you need all series values intialized to a particular value, use the fill() member. More...
 
const series< T > shift (size_t _shift_by) const
 Returns a series that is a 'shifted' version of the given in_series argument. The returned series will be shifted by shift places to the right. For a shift value of 3, the current value in the returned series will correspond to the value 3 bars ago in in_series. This function does not allow shifting to the left (into the future). For shifting series 'into the future', see in_stream::set_forward_shift(). More...
 
size_t size (void) const
 Returns the number of values stored in the series. More...
 
virtual bool size_ok (size_t _required_size) const
 Size ok. More...
 
type_t value_type (void) const
 Returns the data type of the values stored by the series. More...
 
void verify_size (size_t reqired_size) const
 Compares the series size to required_size. If the series size is shorter then a lookback_exception is thrown. More...
 
- Public Member Functions inherited from tsa::pane_format
void copy_pane_format (const pane_format &other) const
 
void pane_auto_pane (bool b) const
 
void pane_dotted_grid (bool b) const
 
void pane_grid_color (const tsa::color &c) const
 
void pane_h_line (const h_line &hl) const
 
void pane_h_line (const tsa::color &c, double y_value, int weight) const
 
const std::vector< tsa::h_line > & pane_h_lines (void) const
 
void pane_show_grid (bool b) const
 
void pane_y_max (double max) const
 
const variantpane_y_max (void) const
 
void pane_y_min (double min) const
 
const variantpane_y_min (void) const
 

Static Public Member Functions

static size_t default_capacity (void)
 
static void reset_default_capacity (size_t new_capacity)
 Sets the default capacity of new series to new_capacity. More...
 

Related Functions

(Note that these are not member functions.)

template<typename T >
std::ostream & operator<< (std::ostream &s, series< T > &ser)
 Prints the series to given stream. More...
 

Detailed Description

template<typename T = double>
class tsa::series< T >

class series is a template class representing a sequence of values.

Constructor & Destructor Documentation

template<typename T >
tsa::series< T >::series ( const series_core &  core)

Constructor.

Parameters
parameter1The first parameter.
template<typename T = double>
tsa::series< T >::series ( const std::string auto_series_name)
inline

Constructor.

Parameters
auto_series_nameName of the automatic series.
template<typename T>
tsa::series< T >::series ( const series< T > &  other)

Copy Constructor.

Parameters
otherThe first parameter.
template<typename T>
tsa::series< T >::series ( size_t  capacity)
explicit

Constructor. Creates an 'unmanaged' series with a fixed capacity and size 0.

Parameters
capacityThe capacity.

Member Function Documentation

template<typename T >
size_t tsa::series< T >::capacity ( void  ) const

Returns the series capacity. Only available for 'unmanaged' series. Throws an exception if the series is 'managed'.

Returns
A size_t.
template<typename T >
void tsa::series< T >::copy ( const series< T > &  other,
size_t  max_num_values = ~(size_t)0 
)

Copies num_values from the other series, starting at position 0. If num_values is 0, it copies the entire series, which will cause the capacity of self to be reset if it is not sufficient.

Parameters
otherAnother instance to copy.
max_num_valuesThe maximum number values.
template<typename T>
bool tsa::series< T >::crosses_above ( const series< T > &  other) const

Returns true if self crossed above other on the most recent value.

Parameters
otherThe other.
Returns
true if it succeeds, false if it fails.
template<typename T>
bool tsa::series< T >::crosses_above ( double  threshold) const

Returns true if self crossed above other on the most recent value.

Parameters
thresholdThe threshold.
Returns
true if it succeeds, false if it fails.
template<typename T>
bool tsa::series< T >::crosses_below ( const series< T > &  other) const

Returns true if self crossed below other on the most recent value.

Parameters
otherThe other.
Returns
true if it succeeds, false if it fails.
template<typename T>
bool tsa::series< T >::crosses_below ( double  threshold) const

Returns true if self crossed below other on the most recent value.

Parameters
thresholdThe threshold.
Returns
true if it succeeds, false if it fails.
template<typename T >
const T * tsa::series< T >::data ( void  ) const

Returns a pointer to the series data. The array length can be determined by calling size().

Returns
null if it fails, else a T*.
template<typename T = double>
bool tsa::series< T >::empty ( void  ) const
inline

Returns true if the series is empty.

Returns
true if it succeeds, false if it fails.
template<typename T>
void tsa::series< T >::fill_to_capacity ( value)

Clears the series and then fills it to capacity with given value.

Parameters
valueThe value.
template<typename T >
T tsa::series< T >::get_at ( size_t  position) const

Returns the value at given position.

Parameters
positionThe position.
Returns
at.
template<typename T>
bool tsa::series< T >::is_equal ( const series< T > &  other) const

Returns true if self has same data as other.

Parameters
otherThe other.
Returns
true if equal, false if not.
template<typename T >
bool tsa::series< T >::is_managed ( void  ) const

Query if this object is managed.

Returns
true if managed, false if not.
template<typename T = double>
bool tsa::series< T >::is_owner ( void  ) const
inline

Query if this object is owner.

Returns
true if owner, false if not.
template<typename T >
const series< T > & tsa::series< T >::name ( const std::string name) const

Names the given name.

Template Parameters
TGeneric type parameter.
Parameters
nameThe name.
Returns
A series<T>&
template<typename T >
T tsa::series< T >::operator[] ( size_t  position) const

Returns the value at given position.

Parameters
positionThe position.
Returns
The indexed value.
template<typename T = double>
void tsa::series< T >::plot_as ( const std::string name,
const tsa::variant period = 0.0,
plot_type  type = plot_type::line,
tsa::color  clr = tsa::color::auto_color,
unsigned  weight = 2 
) const
inline

Plot as.

Parameters
nameThe name.
periodThe period.
typeThe type.
clrThe colour.
weightThe weight.
template<typename T = double>
void tsa::series< T >::plot_as ( const std::string name,
const std::vector< tsa::variant > &  periods,
plot_type  type = plot_type::line,
tsa::color  clr = tsa::color::auto_color,
unsigned  weight = 2 
) const
inline

Plot as.

Parameters
nameThe name.
periodsThe periods.
typeThe type.
clrThe colour.
weightThe weight.
template<typename T >
void tsa::series< T >::print ( std::ostream &  stream,
size_t  max = 1000 
)

Prints the series to given stream. At most max items will be printed. The leftmost value printed corresponds to the value at position 0.

Parameters
[in,out]streamThe stream.
maxThe maximum.
template<typename T >
void tsa::series< T >::print_v ( std::ostream &  s,
size_t  max = 1000 
)

Prints the series to given stream, one data item per line. At most max items will be printed. The leftmost value printed corresponds to the value at position 0.

Parameters
[in,out]sThe std::ostream& to process.
maxThe maximum.
template<typename T>
void tsa::series< T >::push ( _v)

Adds a new value to the front of the series. The new item will be accessible at position 0.

Parameters
parameter1The parameter 1 to push.
template<typename T>
void tsa::series< T >::push ( const variant _v)

Adds a new value item to the front of the series. The new item will be accessible at index position 0.

Parameters
parameter1The parameter 1 to push.
template<typename T >
void tsa::series< T >::reserve ( size_t  capacity)

Sets the serie's capacity to at least as high as the given capacity argument. It is not possible to shrink capacity, although trying to do so will cause no error.

Parameters
capacityThe capacity.
template<typename T = double>
static void tsa::series< T >::reset_default_capacity ( size_t  new_capacity)
inlinestatic

Sets the default capacity of new series to new_capacity.

Parameters
new_capacityThe new capacity.
template<typename T >
void tsa::series< T >::set_size ( size_t  new_size)

Sets the size of self to new_size. This is a quick way to 'make space' without the overhead of calling push() for each value. new_size must be smaller or equal to the object's capacity. Values will not be initialized, and the idea is that the values will be initialized by an STL algorithm such as std::transform(). If you need all series values intialized to a particular value, use the fill() member.

Parameters
new_sizeSize of the new.
template<typename T >
const series< T > tsa::series< T >::shift ( size_t  _shift_by) const

Returns a series that is a 'shifted' version of the given in_series argument. The returned series will be shifted by shift places to the right. For a shift value of 3, the current value in the returned series will correspond to the value 3 bars ago in in_series. This function does not allow shifting to the left (into the future). For shifting series 'into the future', see in_stream::set_forward_shift().

Parameters
_shift_byAmount to shift by.
Returns
A series<T>
template<typename T >
size_t tsa::series< T >::size ( void  ) const

Returns the number of values stored in the series.

Returns
A size_t.
template<typename T >
bool tsa::series< T >::size_ok ( size_t  _required_size) const
virtual

Size ok.

Parameters
_required_sizeSize of the required.
Returns
true if it succeeds, false if it fails.
template<typename T >
type_t tsa::series< T >::value_type ( void  ) const

Returns the data type of the values stored by the series.

Returns
A type_t.
template<typename T >
void tsa::series< T >::verify_size ( size_t  reqired_size) const

Compares the series size to required_size. If the series size is shorter then a lookback_exception is thrown.

Parameters
reqired_sizeSize of the reqired.

Friends And Related Function Documentation

template<typename T >
std::ostream & operator<< ( std::ostream &  s,
series< T > &  ser 
)
related

Prints the series to given stream.

Parameters
[in,out]sThe std::ostream& to process.
[in,out]serThe ser.
Returns
The result of the operation.