You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
GnuCash supports indirect commodity quoting. For example, if the price database contains the valuation of a hypothetical instrument X in EUR and the valuation of EUR to USD, then gnucash is able to provide the value of instrument X in USD. Currently Piecash raises the GncConversionError (in Commodity.currency_conversion) if there is no direct quote in price database.
I am currently using the following modification to the currency_conversion method:
def currency_conversion(self, currency):
"""
Return the latest conversion factor to convert self to currency
Attributes:
currency (:class:`piecash.core.commodity.Commodity`): the currency to which the Price need to be converted
Returns:
a Decimal that can be multiplied by an amount expressed in self.commodity to get an amount expressed in currency
Raises:
GncConversionError: not possible to convert self to the currency
"""
# conversion is done from self.commodity to commodity (if possible)
sc2c = self.prices.filter_by(currency=currency).order_by(Price.date.desc()).first()
if sc2c:
return sc2c.value
# conversion is done directly from commodity to self.commodity (if possible)
c2sc = currency.prices.filter_by(currency=self).order_by(Price.date.desc()).first()
if c2sc:
return Decimal(1) / c2sc.value
**"""
Indirect conversion workaround
"""
priced_in = []
ind = 0
for pr in self.prices:
if pr.currency not in priced_in:
priced_in.append(pr.currency)
for curr in priced_in:
ind = self.currency_conversion(curr) * curr.currency_conversion(currency)
if ind:
return ind
"""
End workaround
"""**
raise GncConversionError("Cannot convert {} to {}".format(self, currency))
The text was updated successfully, but these errors were encountered:
Hi,
GnuCash supports indirect commodity quoting. For example, if the price database contains the valuation of a hypothetical instrument X in EUR and the valuation of EUR to USD, then gnucash is able to provide the value of instrument X in USD. Currently Piecash raises the GncConversionError (in Commodity.currency_conversion) if there is no direct quote in price database.
I am currently using the following modification to the currency_conversion method:
The text was updated successfully, but these errors were encountered: