class quotek::data::records

records is a class that is is a quotek::data::record container

Public Functions


Class Constructor

records(std::vector<std::tuple<long, float, float>> &data)

Class constructor 2. Takes a vector of (timestamp,value,spread) tuples to construct a records object.

  • data -

    vector of (long,float,float) tuples.

records(std::vector<float> &data)

Class constructor 3. Takes a vector of float values to construct a records object. With this constructor, spread is systematically left to 0 and timestamp ranges (

  • data -

    vector of float.

records(std::vector<quotek::data::record> &data)

Class constructor 4. Takes a vector of quotek::data::record values to construct a records object.



Class Destructor

quotek::data::record &operator[](const int &i)

[] Operator

int search(long search_timestamp)

search performs a binary search inside a vector of records given a timestamp.

index of the found record element inside the dataset.
  • recs -

    the record dataset to search in

  • search_timestamp -

    the timestamp to search for inside the dataset.

quotek::data::records sample(long time_inf, long time_sup)

sample is a method to extract a subvector of records from a vector of records, given starting and ending timestamps. Note: timestamps can be negative, in which case the real timestamps are time() + time_inf, time() + time_sup.

resampled dataset containing only the data in time interval [time_inf, time_sup]
  • recs -

    the record dataset to extract sample from.

  • time_inf -

    epoch timestamp for first element of sample.

  • time_sup -

    epoch timestamp for the last element of sample.

quotek::data::records extract(int start_offset, int size)

to create a new subvector.

extraced dataset containing data in interval [start_offsret, start_offset + size]
  • recs -

    record dataset to extract data from.

  • start_offset -

    the element index from which to start extract

  • size -

    the size of the extract.

quotek::data::records extract(int n)

Alternative extract function, for extraction of the last elements of a quotek::data::records container.

a quotek::data::records container containing the n last elements of the object.
  • n -

    number of last elements to add in the returned container.

quotek::data::records down_sample(int period, float tick, std::string method)

Downsample reduces the amount of points in the dataset by agrregating data in “period” intervals. How down sampling methods work:

  • close: Simply takes the last price over aggregated time period.
  • HL2: Takes high and low price over aggregated time period and makes average.
  • typical: Takes high, low and close prices over time period and makes average.
  • OHLC4: Takes open, high, low and close prices over time period and makes average.
the new, down sampled dataset.
  • period -

    size of the aggregate, in seconds.

  • tick -

    tick exprimed in seconds of records dataset. down sampling method. Method can be either “close”, “HL2”, “typical”, “OHLC4”.

Note about down sampling: spread values are not kept in resulting dataset it would not make any sense to do so. therefore, they’re all 0 in resulting dataset.

std::vector<quotek::data::record> &get_data()

Retrieves a vector of quotek::data::record.

std::vector<long> export_timestamps()

Retrieves a vector that contains all the timestamps of the dataset.

std::vector<float> export_values()

Retrieves a vector that contains all the values of the dataset.

std::vector<float> export_spreads()

Retrieves a vector that contains all the spreads of a dataset.

quotek::data::record &last()

last returns last vector element.

size_t size()

returns size of container.

void append(quotek::data::record &r)

Adds new entry to records container (record form)

void append(float value)

Adds new entry to records container (value only)

void append(long timestamp, float value)

Adds new entry to records container (no spread)

void append(long timestamp, float value, float spread)

Adds new entry to records container (with spread)

void append(quotek::data::records &recs)

concatenates 2 records datasets to 1

std::string str(const bool add_timestamps)

str takes the data inside the records container and transforms it to a json-formated string.

the content of the records container, formatted as a JSON string.
  • add_timestamps -

    if true, record timestamp will be added to the string.

quotek::data::record min()

finds record which has the smallest value.

quotek::data::record max()

finds record which has the highest value.

Eigen::VectorXd to_vector()

Similar to export_values, but instead of returning an std::vector<float>, it returns an Eigen::VectorXd (dvector) data structure.

all the values alligned inside an Eigen::VectorXd (dvector)

Eigen::MatrixXd to_matrix(const bool add_timestamps)

Converts the quotek::data::records structure to an Eigen::MatrixXd (dataset) structure.

an Eigen::MatrixXd (dataset) representation of the data.
  • add_timestamps -

    tells if timestamps must be added to vector or not.


The code below will show you how to manipulate records containers to store and retrieve time-series data.

#include <quotek/record.hpp>
#include <iostream>

using namespace quotek::data;

int main() {

  //First we create a vector of float values as fake data.
  std::vector<float> vals = { 4530, 4575, 4890, 4235, 4144, 4356, 4588, 4720, 4989 };

  //Then we can import these values inside a records container.
  records r1(vals);

  //We can iterate through this container with a simple loop:
  for (int i=0; i< r1.size(); i++  ) {

    //we assign a fake timestamp and spread value to record at position i
    r1[i].timestamp = time(0);
    r1[i].spread = 0;

    //Prints the value of record at position i
    std::cout << r1[i].value << std::endl;


  //To append some data in the container, you must use the append() function:

  //Also works, it will not assign any value to timestamp and spread for the newly added record.

  //Alternatively you can create a record object then append it to the container:
  record trec;
  trec.timestamp = time(0);
  trec.value = 4794;
  trec.spread = 0;