MCPcopy Index your code
hub / github.com/Audio4Linux/JDSP4Linux / timeSeriesToOhlc

Method timeSeriesToOhlc

3rdparty/qcustomplot/qcustomplot.cpp:27405–27442  ·  view source on GitHub ↗

! A convenience function that converts time series data (\a value against \a time) to OHLC binned data points. The return value can then be passed on to \ref QCPFinancialDataContainer::set(const QCPFinancialDataContainer&). The size of the bins can be controlled with \a timeBinSize in the same units as \a time is given. For example, if the unit of \a time is seconds and single OHLC/Ca

Source from the content-addressed store, hash-verified

27403 data.
27404*/
27405QCPFinancialDataContainer QCPFinancial::timeSeriesToOhlc(const QVector<double> &time, const QVector<double> &value, double timeBinSize, double timeBinOffset)
27406{
27407 QCPFinancialDataContainer data;
27408 int count = qMin(time.size(), value.size());
27409 if (count == 0)
27410 return QCPFinancialDataContainer();
27411
27412 QCPFinancialData currentBinData(0, value.first(), value.first(), value.first(), value.first());
27413 int currentBinIndex = qFloor((time.first()-timeBinOffset)/timeBinSize+0.5);
27414 for (int i=0; i<count; ++i)
27415 {
27416 int index = qFloor((time.at(i)-timeBinOffset)/timeBinSize+0.5);
27417 if (currentBinIndex == index) // data point still in current bin, extend high/low:
27418 {
27419 if (value.at(i) < currentBinData.low) currentBinData.low = value.at(i);
27420 if (value.at(i) > currentBinData.high) currentBinData.high = value.at(i);
27421 if (i == count-1) // last data point is in current bin, finalize bin:
27422 {
27423 currentBinData.close = value.at(i);
27424 currentBinData.key = timeBinOffset+(index)*timeBinSize;
27425 data.add(currentBinData);
27426 }
27427 } else // data point not anymore in current bin, set close of old and open of new bin, and add old to map:
27428 {
27429 // finalize current bin:
27430 currentBinData.close = value.at(i-1);
27431 currentBinData.key = timeBinOffset+(index-1)*timeBinSize;
27432 data.add(currentBinData);
27433 // start next bin:
27434 currentBinIndex = index;
27435 currentBinData.open = value.at(i);
27436 currentBinData.high = value.at(i);
27437 currentBinData.low = value.at(i);
27438 }
27439 }
27440
27441 return data;
27442}
27443
27444/* inherits documentation from base class */
27445void QCPFinancial::draw(QCPPainter *painter)

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.45
atMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected