history_iterators.cppThis code exemplifies how to use History iterators to perform gaussianstatistics 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;
00001
00002
00003 History h(...);
00004
00005
00006
00007 GaussianStatistics s;
00008 s.addSequence(h.vdbegin(),h.vdend());
00009 cout << "Historical mean: " << s.mean() << endl;
00010 cout << "Std. deviation: " << s.standardDeviation() << endl;
00011
00012
00013
00014 History::const_valid_iterator max = h.vbegin(), i=max, end = h.vend();
00015 for (i++; i!=end; i++)
00016 if (i->value() > max->value())
00017 max = i;
00018 cout << "Maximum value: " << max->value()
00019 << " assumed " << DateFormatter::toString(max->date()) << endl;
00020
00021
00022
00023 bool lessthan(const History::Entry& i, const History::Entry& j) {
00024 return i.value() < j.value();
00025 }
00026
00027 History::const_valid_iterator min =
00028 std::min_element(h.vbegin(),h.vend(),lessthan);
00029 cout << "Minimum value: " << min->value()
00030 << " assumed " << DateFormatter::toString(min->date()) << endl;
00031
00032
|