i am currently working on an algorithm for my final project, part of it includes finding if the vector of objects that was imputed from a stock csv file. I was hoping for some feedback on my code and what i have so far.
here are the requirements based upon the stocks closing cost for a day.
Makes a new High
Drops 5 % or more – from High
Rallys 5 % or more(less 7 % ) --from Drop
Drops 5 % or more again – From 2nd top
Data dataContainer::getDoubleTop(vector<Data> vData) {
Data newHigh;
bool firstPeek = false;
int index = 1;
It is not quite clear what you are doing / should do.
Does the order of elements in vData play a role? You do sort, and hence wipe out information about "after".
You can seek both global and local minima/maxima without sorting.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
T
fubar( const std::vector<Data> & vData )
{
// largest element (by getClose) in range [begin,end)
auto allHigh = std::max_element( vData.begin(), vData.end(),
[](const Data &lhs, const Data &rhs) { return lhs.getClose() < rhs.getClose(); } );
// largest element (by getClose) in range (allHigh,end)
auto nextPeak = std::max_element( allHigh+1, vData.end(),
[](const Data &lhs, const Data &rhs) { return lhs.getClose() < rhs.getClose(); } );
// smallest element (by getClose) in range [allHigh,nextPeak)
auto restMin = std::min_element( allHigh, nextPeak,
[](const Data &lhs, const Data &rhs) { return lhs.getClose() < rhs.getClose(); } );
return ...
}