piecash.core.commodity module¶
-
class
piecash.core.commodity.
Price
(commodity, currency, date, value, type='unknown', source='user:price')[source]¶ Bases:
piecash._declbase.DeclarativeBaseGuid
A single Price for a commodity.
-
date
¶ date object representing the day at which the price is relevant
- Type
-
value
¶ the price itself
- Type
-
object_to_validate
(change)[source]¶ yield the objects to validate when the object is modified (change=”new” “deleted” or “dirty”).
For instance, if the object is a Split, if it changes, we want to revalidate not the split but its transaction and its lot (if any). split.object_to_validate should yeild both split.transaction and split.lot
-
-
class
piecash.core.commodity.
Commodity
(namespace, mnemonic, fullname, fraction=100, cusip='', quote_flag=0, quote_source=None, quote_tz='', book=None)[source]¶ Bases:
piecash._declbase.DeclarativeBaseGuid
A GnuCash Commodity.
-
namespace
¶ CURRENCY for currencies, otherwise any string to group multiple commodities together
- Type
-
mnemonic
¶ the ISO symbol for a currency or the stock symbol for stocks (used for online quotes)
- Type
-
quote_source
¶ the quote source for GnuCash (piecash always use yahoo for stock and quandl for currencies
- Type
-
base_currency
¶ The base_currency for a commodity:
if the commodity is a currency, returns the “default currency” of the book (ie the one of the root_account)
if the commodity is not a currency, returns the currency encoded in the quoted_currency slot
- Type
-
accounts
¶ list of accounts which have the commodity as commodity
- Type
list of
piecash.core.account.Account
-
transactions
¶ list of transactions which have the commodity as currency
- Type
-
prices
¶ iterator on prices related to the commodity (it is a sqlalchemy query underneath)
- Type
iterator of
Price
-
currency_conversion
(currency)[source]¶ Return the latest conversion factor to convert self to currency
-
currency
¶ 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
-
-
update_prices
(start_date=None)[source]¶ Retrieve online prices for the commodity:
for currencies, it will get from quandl the exchange rates between the currency and its base_currency
for stocks, it will get from yahoo the daily closing prices expressed in its base_currency
- Parameters
start_date (
datetime.date
) – prices will be updated as of the start_date. If None, start_date is today7 days. (-) –
Note
if prices are already available in the GnuCash file, the function will only retrieve prices as of the max(start_date, last quoted price date)
Todo
add some frequency to retrieve prices only every X (week, month, …)
-
object_to_validate
(change)[source]¶ yield the objects to validate when the object is modified (change=”new” “deleted” or “dirty”).
For instance, if the object is a Split, if it changes, we want to revalidate not the split but its transaction and its lot (if any). split.object_to_validate should yeild both split.transaction and split.lot
-