Exemplo n.º 1
0
double ShortPosition::factor( const boost::gregorian::date_period& dp, EODDB::PriceType pt ) const throw(PositionException)
{
  // Verify that input period is contained within position holding period
  if( ! hold_period().contains(dp) )
    throw PositionException("Requested factor period is out of Position range");

  return Price::get(_symbol, dp.begin(), pt) / Price::get(_symbol, dp.end(), pt);
}
Exemplo n.º 2
0
SeriesFactorSet ShortPosition::factors( const boost::gregorian::date_period& dp, EODDB::PriceType pt /*= EODDB::PriceType::ADJCLOSE*/ ) const throw(PositionException)
{
  SeriesFactorSet sfs(_id);

#ifdef DEBUG
  cout << "Extracting daily factors for short position " << _id << " (" << _symbol << ") from " << dp.begin() << " to " << dp.last() << endl;
#endif

  if( ! hold_period().contains(dp) )
    throw PositionException("Requested period is out of range");

  const EODSeries& series = EODDB::instance().get(_symbol);

  EODSeries::const_iterator citer = series.after(dp.begin(), 0);
  if( citer == series.end() )
    throw PositionException("Can't find begin of period in series");

  date prev_date = citer->first;

  for( EODSeries::const_iterator citer = series.after(dp.begin()); citer != series.end(); ++citer ) {

    // If we're over the end of requested period or if the position is closed and we're over the last execution date, then we're done
    if( (*citer).first > dp.last() || (closed() && (*citer).first > last_exec()->dt()) )
      break;

    double f = factor(date_period(prev_date, citer->first), pt);
    sfs.insert(SeriesFactor(prev_date, citer->first, f));

#ifdef DEBUG
    cout << "Previous date: " << prev_date << ", current date: " << citer->first << ", factor: " << f << endl;
#endif

    prev_date = citer->first;
  }

  return sfs;
}
Exemplo n.º 3
0
		string ToString() { return CombineString(Currency.ToString(), DespoitType.ToString(),
									date::to_iso_string(Period.begin()), date::to_iso_string(Period.end()),
									date::to_iso_string(LastUpdateDate));
		}