33 : date(date), quantityAmount(0), payLegPrice(payLegPrice),
34 receiveLegPrice(receiveLegPrice), unrealized(unrealized) {}
38 out << std::setw(12) << std::left <<
"positions"
39 << std::setw(12) << std::right <<
"pay"
40 << std::setw(12) << std::right <<
"receive"
41 << std::setw(10) << std::right <<
"qty"
42 << std::setw(14) << std::right <<
"delta"
43 << std::setw(10) << std::right <<
"open" << std::endl;
45 for (
const auto& i : dailyPositions) {
47 out << std::setw(4) <<
io::iso_date(i.first) <<
" " << std::setw(12) << std::right
48 << std::fixed << std::setprecision(6) << dailyPosition.
payLegPrice << std::setw(12)
49 << std::right << std::fixed << std::setprecision(6) << dailyPosition.
receiveLegPrice
50 << std::setw(10) << std::right << std::fixed << std::setprecision(2)
51 << dailyPosition.
quantityAmount << std::setw(14) << std::right << std::fixed
52 << std::setprecision(2) << dailyPosition.
riskDelta << std::setw(10) << std::right
53 << std::fixed << std::setprecision(2)
78 const ext::shared_ptr<SecondaryCosts>& secondaryCosts)
79 :
Commodity(secondaryCosts), commodityType_(
std::move(commodityType)) {}
90 if (toUnitOfMeasure != fromUnitOfMeasure) {
103 const Date& evaluationDate) {
104 if (fromCurrency != toCurrency) {
106 fromCurrency, toCurrency,
108 if (fromCurrency == exchRate.
target())
109 return 1.0 / exchRate.
rate();
110 return exchRate.
rate();
117 const Date& evaluationDate)
const {
123 Real unitCostUomConversionFactor =
127 Real unitCostFxConversionFactor =
129 baseCurrency, evaluationDate);
130 return unitCost.
amount().
value() * unitCostUomConversionFactor
131 * unitCostFxConversionFactor;
138 Real totalQuantityValue,
139 const Date& evaluationDate)
const {
147 if (ext::any_cast<CommodityUnitCost>(&i->second) !=
nullptr) {
151 ext::any_cast<CommodityUnitCost>(i->second),
152 evaluationDate) * totalQuantityValue;
154 Money(baseCurrency, value);
155 }
else if (ext::any_cast<Money>(&i->second) !=
nullptr) {
156 const Money& amount = ext::any_cast<Money>(i->second);
157 Real fxConversionFactor =
163 amount.
value() * fxConversionFactor);
166 }
catch (
const std::exception& e) {
167 QL_FAIL(
"error calculating secondary costs: " << e.what());
ext::shared_ptr< SecondaryCosts > secondaryCosts_
SecondaryCostAmounts secondaryCostAmounts_
UnitOfMeasure & unitOfMeasure()
const Money & amount() const
const UnitOfMeasure & unitOfMeasure() const
static Real calculateUomConversionFactor(const CommodityType &commodityType, const UnitOfMeasure &fromUnitOfMeasure, const UnitOfMeasure &toUnitOfMeasure)
void setupArguments(PricingEngine::arguments *) const override
Real calculateUnitCost(const CommodityType &commodityType, const CommodityUnitCost &unitCost, const Date &evaluationDate) const
CommodityType commodityType_
EnergyCommodity(CommodityType commodityType, const ext::shared_ptr< SecondaryCosts > &secondaryCosts)
void calculateSecondaryCostAmounts(const CommodityType &commodityType, Real totalQuantityValue, const Date &evaluationDate) const
void fetchResults(const PricingEngine::results *) const override
static Real calculateFxConversionFactor(const Currency &fromCurrency, const Currency &toCurrency, const Date &evaluationDate)
const CommodityType & commodityType() const
exchange rate between two currencies
const Currency & target() const
the target currency.
Decimal rate() const
the exchange rate (when available)
ExchangeRate lookup(const Currency &source, const Currency &target, Date date=Date(), ExchangeRate::Type type=ExchangeRate::Derived) const
virtual void fetchResults(const PricingEngine::results *) const
const Currency & currency() const
static UnitOfMeasureConversionManager & instance()
access to the unique instance
Real conversionFactor() const
the conversion factor
UnitOfMeasureConversion lookup(const CommodityType &commodityType, const UnitOfMeasure &, const UnitOfMeasure &, UnitOfMeasureConversion::Type type=UnitOfMeasureConversion::Derived) const
Unit of measure specification
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
detail::iso_date_holder iso_date(const Date &d)
output dates in ISO format (yyyy-mm-dd)
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
std::map< Date, EnergyDailyPosition > EnergyDailyPositions
ext::shared_ptr< YieldTermStructure > r
EnergyDailyPosition()=default
Unit-of-measure conversion manager.