history_iterators.cppThis code exemplifies how to use History iterators to perform Gaussian statistic analyses on historical data.
History h(...);
GaussianStatistics s;
s.addSequence(h.vdbegin(),h.vdend());
cout << "Historical mean: " << s.mean() << endl;
cout << "Std. deviation: " << s.standardDeviation() << endl;
History::const_valid_iterator max = h.vbegin(), i=max, end = h.vend();
for (i++; i!=end; i++)
if (i->value() > max->value())
max = i;
cout << "Maximum value: " << max->value()
<< " assumed " << DateFormatter::toString(max->date()) << endl;
bool lessthan(const History::Entry& i, const History::Entry& j) {
return i.value() < j.value();
}
History::const_valid_iterator min =
std::min_element(h.vbegin(),h.vend(),lessthan);
cout << "Minimum value: " << min->value()
<< " assumed " << DateFormatter::toString(min->date()) << endl;
|