Пример #1
0
SeriesFactorSet StrategyPosition::_matchFactors(const SeriesFactorMultiSetFrom& sfsAll) const
{
  SeriesFactorSet sfsStrategy;

  // Extract current factor
  for( SeriesFactorMultiSetFrom::const_iterator citer = sfsAll.begin(); citer != sfsAll.end(); ) {

    // Get current factor
    SeriesFactor currentFactor = *citer;
    double acc = currentFactor.factor();

#ifdef DEBUG
    cout << "Analyzing Position daily factor from " << currentFactor.from_tm() << " to " << currentFactor.to_tm()
	 << " factor " << currentFactor.factor() << endl;
#endif

    // Accumulate all the following factors with the same from/to date
    SeriesFactorMultiSetFrom::const_iterator citer_next = citer;
    while( ++citer_next != sfsAll.end() && citer_next->from_tm() == currentFactor.from_tm() && citer_next->to_tm() == currentFactor.to_tm() ) {
#ifdef DEBUG
      cout << "Found daily factor with same from/to dates, factor " << citer_next->factor() << endl;
#endif
      acc *= citer_next->factor();
    }

    // Add cumulated factor
    sfsStrategy.insert(SeriesFactor(currentFactor.from_tm(), currentFactor.to_tm(), acc));

    // Start from first SeriesFactor with different from/to date
    citer = citer_next;
  }

  return sfsStrategy;
}
Пример #2
0
bool SeriesFactorSet::insert( const SeriesFactor& sf )
{
  if( ! __SeriesFactorSet::insert(sf).second )
    return false;

  // Cache new overall factor for performance
  _factor *= sf.factor();

  return true;
}