Doxygen

class AggregateDataTransform : public sam_trader::transform::DataTransform
#include <aggregates.h>

Class for aggregating financial data by a desired time span.

Public Functions

AggregateDataTransform(BarColumns, sam_trader::TimeSpan const &base, sam_trader::TimeSpan const &desired)

Constructs an AggregateDataTransform instance with the given parameters.

Parameters:
  • barColumns – The columns containing financial bar data.

  • base – The base time span for the financial data.

  • desired – The desired time span for aggregation.

virtual pd::DataFrame transform(pd::DataFrame const&) const final

Transforms the given financial data by aggregating it at the desired time span.

Parameters:

data – The financial data to transform.

Returns:

The transformed financial data.

virtual std::vector<std::string> getOutputNames() const override

Gets the output names of the transformed financial data.

Returns:

The output names of the transformed financial data.

pd::DataFrame aggregateByDay(pd::DataFrame const &bar) const

Aggregates the given financial data by day.

Parameters:

bar – The financial data to aggregate.

Returns:

The aggregated financial data.

pd::DataFrame aggregateByMinute(const pd::DataFrame &df) const

Aggregates the given financial data by minute.

Parameters:

df – The financial data to aggregate.

Returns:

The aggregated financial data.

Private Members

sam_trader::TimeSpan desiredTimeSpan
sam_trader::TimeSpan baseTimeSpan

The desired time span for aggregation.

struct Bar
#include <aggregates.h>

Struct representing a financial bar.

Public Members

double open = {}
double high = {-std::numeric_limits<double>::infinity()}

Opening price of the bar.

double low = {std::numeric_limits<double>::infinity()}

Highest price of the bar.

double close = {}

Lowest price of the bar.

double volume = {}

Closing price of the bar.

struct DataTransform
#include <data_transform.h>

An abstract base class representing a data transform operation.

Subclassed by sam_trader::transform::AggregateDataTransform, sam_trader::transform::FibRetracementModel, sam_trader::transform::TAModel

Public Types

using Ptr = std::unique_ptr<DataTransform>

A unique pointer to a DataTransform object.

Public Functions

inline DataTransform(BarColumns prices, ColumnPrefix config)

Constructs a DataTransform object with the given BarColumns and ColumnPrefix.

Parameters:
  • prices – The BarColumns to use for the transform.

  • config – The ColumnPrefix for the transform.

virtual pd::DataFrame transform(pd::DataFrame const&) const = 0

Transforms the input DataFrame and returns the transformed DataFrame.

Parameters:

data – The DataFrame to transform.

Returns:

The transformed DataFrame.

virtual std::vector<std::string> getOutputNames() const = 0

Returns the output names of the transform.

Returns:

The output names of the transform.

virtual ~DataTransform() = default

Virtual destructor for the DataTransform class.

Protected Attributes

BarColumns m_barColumns
ColumnPrefix config
struct FibRetracementModel : public sam_trader::transform::DataTransform

Public Functions

inline explicit FibRetracementModel(BarColumns priceNames, Args const &args)

Constructs a new instance of the FibRetracementModel.

Parameters:
  • priceNames – The column names of the prices.

  • args – The arguments for the FibRetracementModel.

virtual std::vector<std::string> getOutputNames() const override

Gets the names of the output columns.

Returns:

The names of the output columns.

virtual pd::DataFrame transform(pd::DataFrame const &bars) const override

Transforms the given bars data using the Fibonacci retracement model.

Parameters:

bars – The bars data to be transformed.

Returns:

The transformed bars data.

Public Members

int64_t depth = -1

Public Static Attributes

static constexpr std::array fibRatios = {0.f, 0.236f, 0.382f, 0.500f, 0.618f, 0.764f, 1.00f}
static constexpr std::array fibColors{"#787b86", "#f44336", "#81c784", "#4caf50", "#009688", "#64b5f6", "#787b86",}
struct Registry

Public Functions

inline int registerTransform(std::string const &name, FunctionInterface const &func)
inline FunctionInterface get(std::string const &name) const

Gets a transformation function from the registry.

Parameters:

name – The name of the transformation function.

Throws:

std::runtime_error – if the transformation function is not in the registry.

Returns:

The transformation function.

Public Members

RegistryWrapper impl
struct RegistryWrapper
#include <registry.h>

A struct to wrap the registry for transformation functions.

Public Static Attributes

static std::unordered_map<std::string, FunctionInterface> registry

Registers a transformation function with the registry.

Param name:

The name of the transformation function.

Param func:

The transformation function.

Return:

The status of the registration.

class TAModel : public sam_trader::transform::DataTransform
#include <ta_model.h>

@A class that extends the DataTransform class, and is used to apply technical indicators on OHLCV data.

Public Functions

TAModel(BarColumns barColumns, ColumnPrefix columnPrefix, std::string const &name, std::vector<double> _options = {})

@Constructs a new TAModel instance.

Parameters:
  • barColumns – A BarColumns instance containing the column names of the OHLCV data.

  • columnPrefix – The prefix to be used in the names of the columns generated by the technical indicator.

  • name – The name of the technical indicator.

  • _options – A vector of doubles containing the options of the technical indicator.

virtual std::vector<std::string> getOutputNames() const override

@Returns a vector of strings containing the names of the columns generated by the technical indicator.

Returns:

A vector of strings containing the names of the columns generated by the technical indicator.

~TAModel() override = default
std::unordered_map<std::string, std::vector<double>> makeOutput(pd::DataFrame const &bars, std::vector<std::string> const &output_names) const

@Constructs a map of vectors of doubles containing the outputs generated by the technical indicator.

Parameters:
  • bars – A DataFrame instance containing the OHLCV data.

  • output_names – A vector of strings containing the names of the columns generated by the technical indicator.

Returns:

A map of vectors of doubles containing the outputs generated by the technical indicator.

std::tuple<std::unordered_map<std::string, std::vector<double>>, int64_t, std::shared_ptr<arrow::Array>> unzip(ColumnPrefix const &columnPrefix, pd::DataFrame const &bars) const

@Unzips a DataFrame instance into a tuple containing a map of vectors of doubles containing the outputs generated by the technical indicator, an int64_t value, and a shared_ptr to an Array instance.

Parameters:
  • columnPrefix – The prefix to be used in the names of the columns generated by the technical indicator.

  • bars – A DataFrame instance containing the OHLCV data.

Returns:

A tuple containing a map of vectors of doubles containing the outputs generated by the technical indicator, an int64_t value, and a shared_ptr to an Array instance.

virtual pd::DataFrame transform(pd::DataFrame const &bars) const override

@Applies the technical indicator on the OHLCV data contained in a DataFrame instance.

Parameters:

bars – A DataFrame instance containing the OHLCV data.

Returns:

A DataFrame instance containing the OHLCV data and the columns generated by the technical indicator.

Public Static Functions

static void initializeDefaults()
static inline auto getDefaultsPath()

Protected Attributes

const ti_indicator_info *info
std::vector<double> options
mutable std::vector<const double*> inputs
mutable std::vector<double*> outputs

Protected Static Attributes

static std::unordered_map<std::string, std::vector<double>> tiIndicatorsDefaults
static std::once_flag lazyInitFlag

Friends

friend std::ostream &operator<<(std::ostream&, TAModel const&)

@Overloads the << operator to output the name of the technical indicator.

Parameters:
  • os – An output stream instance.

  • taModel – A TAModel instance.

Returns:

An output stream instance.

namespace pd
namespace sam_trader
namespace transform

Typedefs

using DataTransformList = std::vector<DataTransform::Ptr>

A vector of DataTransform::Ptr objects.

using Args = std::vector<double>

A type alias for the arguments of a transformation function.

using FunctionInterface = std::function<std::unique_ptr<DataTransform>(BarColumns, Args const&)>

A type alias for the function interface of a transformation function.

Functions

std::set<std::string> extractNames()

@Extracts the names of all the Technical Indicators.

Returns:

A set containing the names of all the Technical Indicators.

std::ostream &operator<<(std::ostream &os, TAModel const &model)

@Overloads the << operator to output the name of the technical indicator.

Parameters:
  • os – An output stream instance.

  • taModel – A TAModel instance.

Returns:

An output stream instance.

Variables

static Registry transformRegistry
const std::set<std::string> ALL_TI = extractNames()
namespace string_literals

A class for performing Fibonacci retracement on price data.

file aggregates.cpp
#include “aggregates.h
file aggregates.h
#include “../common/timespan.h”
#include “data_transform.h
#include “pandas_arrow.h”
file data_transform.h
#include “common/namespace.h”
#include “memory”

Contains the definition of the DataTransform class and related types.

file fib_retrace.cpp
#include “fib_retrace.h
#include “pandas_arrow.h”
#include “span”
file fib_retrace.h
#include “registry.h
#include “ta_model.h
file registry.h
#include “any”
#include “data_transform.h
#include “functional”

Contains definitions for the Transform Registry.

Defines

REGISTER_TRANSFORM(Class, name)

Macro to register a transformation class with the registry.

The global registry of transformation functions.

Parameters:
  • Class – The class to be registered.

  • name – The name of the class in the registry.

file ta_model.cpp
#include “ta_model.h
#include “boost/algorithm/algorithm.hpp”
#include “glog/logging.h”
#include “pandas_arrow.h”
file ta_model.h
#include <cmath>
#include <mutex>
#include “arrow/array.h”
#include “common/macros.h”
#include “data_transform.h
#include “stdexcept”
#include “string”
#include “tulip/indicators.h”
#include “unordered_map”
#include “vector”
dir sam/trading_sim/cpp
dir sam
dir sam/trading_sim/cpp/src
dir sam/trading_sim
dir sam/trading_sim/cpp/src/transforms