history_iterators.cpp
This code exemplifies how to use History iterators to perform Gaussian statistic analyses on historical data.
00001 00002 // initialize a History 00003 History h(...); 00004 00005 // print out the mean value and its standard deviation. 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 // Another possibility: print out the maximum value. 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 // or the minimum, this time the STL way: 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