Skip to content

Commit

Permalink
check for out bound index for ohlcv table
Browse files Browse the repository at this point in the history
  • Loading branch information
silvadom committed Dec 19, 2024
1 parent 5908fed commit 63094ce
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 43 deletions.
34 changes: 19 additions & 15 deletions samples/sources/processors/atr/AtrProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,27 @@ TaskArray AtrProcessor::Evaluate(
for(size_t id=0; id < symbolsCount; ++id)
{
size_t j = id * nfields + 1; // add 1 to skip first column timestamp
int numColumns = dataRef.ohlcvRecord->num_columns();
//std::iota(std::begin(colIds), std::end(colIds), j);
dataRef.lock.Lock();
auto highColumn = dataRef.ohlcvRecord->column(j+field+1);
auto lowColumn = dataRef.ohlcvRecord->column(j+field+2);
auto closeColumn = dataRef.ohlcvRecord->column(j+field+3);
dataRef.lock.Unlock();
if(highColumn && lowColumn && closeColumn && outdata)
if((j+field) < static_cast<size_t>(numColumns))
{
const double* highs = castTableColumn<double>(highColumn);
const double* lows = castTableColumn<double>(lowColumn);
const double* closes = castTableColumn<double>(closeColumn);
std::vector<const double*> fieldsValues = {highs,lows,closes};

bool result = AverageTrueRange(
id, fieldsValues, numSamples, aSize, outdata, winSize, field, nfields,
&errorVal, atrCache.prevAtrs.data(), atrCache.prevCloses.data(), normalized, scale);
counter += (int)result;
dataRef.lock.Lock();
auto highColumn = dataRef.ohlcvRecord->column(j+field+1);
auto lowColumn = dataRef.ohlcvRecord->column(j+field+2);
auto closeColumn = dataRef.ohlcvRecord->column(j+field+3);
dataRef.lock.Unlock();
if(highColumn && lowColumn && closeColumn && outdata)
{
const double* highs = castTableColumn<double>(highColumn);
const double* lows = castTableColumn<double>(lowColumn);
const double* closes = castTableColumn<double>(closeColumn);
std::vector<const double*> fieldsValues = {highs,lows,closes};

bool result = AverageTrueRange(
id, fieldsValues, numSamples, aSize, outdata, winSize, field, nfields,
&errorVal, atrCache.prevAtrs.data(), atrCache.prevCloses.data(), normalized, scale);
counter += (int)result;
}
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions samples/sources/processors/ema/EmaProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ TaskArray EmaProcessor::Evaluate(
for(size_t id=0; id < symbolsCount; ++id)
{
size_t j = id * nfields + 1; // add 1 to skip first column timestamp
int numColumns = dataRef.ohlcvRecord->num_columns();
//std::iota(std::begin(colIds), std::end(colIds), j);
dataRef.lock.Lock();
auto fieldColumn = dataRef.ohlcvRecord->column(j+field);
dataRef.lock.Unlock();
if(fieldColumn && outdata)
if((j+field) < static_cast<size_t>(numColumns))
{
const double* fieldValues = castTableColumn<double>(fieldColumn);
bool result = ExpMovingAverage(
id, fieldValues, numSamples, aSize, outdata, winSize, field,
nfields, &errorVal, emaCache.values.data(), normalized, scale);
counter += (int)result;
dataRef.lock.Lock();
auto fieldColumn = dataRef.ohlcvRecord->column(j+field);
dataRef.lock.Unlock();
if(fieldColumn && outdata)
{
const double* fieldValues = castTableColumn<double>(fieldColumn);
bool result = ExpMovingAverage(
id, fieldValues, numSamples, aSize, outdata, winSize, field,
nfields, &errorVal, emaCache.values.data(), normalized, scale);
counter += (int)result;
}
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions samples/sources/processors/roc/RocProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,21 @@ TaskArray RocProcessor::Evaluate(
for(size_t id=0; id < symbolsCount; ++id)
{
size_t j = id * nfields + 1; // add 1 to skip first column timestamp
int numColumns = dataRef.ohlcvRecord->num_columns();
//std::iota(std::begin(colIds), std::end(colIds), j);
dataRef.lock.Lock();
auto fieldColumn = dataRef.ohlcvRecord->column(j+field);
dataRef.lock.Unlock();
if(fieldColumn && outdata)
if((j+field) < static_cast<size_t>(numColumns))
{
const double* fieldValues = castTableColumn<double>(fieldColumn);
bool result = RateOfChange(
id, fieldValues, numSamples, aSize, outdata, winSize,
field, nfields, &errorVal, rocCache.values, scale);
counter += (int)result;
dataRef.lock.Lock();
auto fieldColumn = dataRef.ohlcvRecord->column(j+field);
dataRef.lock.Unlock();
if(fieldColumn && outdata)
{
const double* fieldValues = castTableColumn<double>(fieldColumn);
bool result = RateOfChange(
id, fieldValues, numSamples, aSize, outdata, winSize,
field, nfields, &errorVal, rocCache.values, scale);
counter += (int)result;
}
}
}
}
Expand Down
24 changes: 14 additions & 10 deletions samples/sources/processors/rsi/RsiProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,22 @@ TaskArray RsiProcessor::Evaluate(
for(size_t id=0; id < symbolsCount; ++id)
{
size_t j = id * nfields + 1; // add 1 to skip first column timestamp
int numColumns = dataRef.ohlcvRecord->num_columns();
//std::iota(std::begin(colIds), std::end(colIds), j);
dataRef.lock.Lock();
auto fieldColumn = dataRef.ohlcvRecord->column(j+field);
dataRef.lock.Unlock();
if(fieldColumn && outdata)
if((j+field) < static_cast<size_t>(numColumns))
{
const double* fieldValues = castTableColumn<double>(fieldColumn);
bool result = RelativeStrengthIndex(
id, fieldValues, numSamples, aSize, outdata, winSize, field,
nfields, &errorVal, caches.upAvgs.data(), caches.downAvgs.data(),
caches.prevRsis.data(), caches.prevPrices.data(), scale);
counter += (int)result;
dataRef.lock.Lock();
auto fieldColumn = dataRef.ohlcvRecord->column(j+field);
dataRef.lock.Unlock();
if(fieldColumn && outdata)
{
const double* fieldValues = castTableColumn<double>(fieldColumn);
bool result = RelativeStrengthIndex(
id, fieldValues, numSamples, aSize, outdata, winSize, field,
nfields, &errorVal, caches.upAvgs.data(), caches.downAvgs.data(),
caches.prevRsis.data(), caches.prevPrices.data(), scale);
counter += (int)result;
}
}
}
}
Expand Down

0 comments on commit 63094ce

Please sign in to comment.