The currency module defines currencies of various types. As of this release, there are only a handful yet defined.
TradePath(rcv, work, out)
A 3-tuple of Currency objects, describing the path of a foreign exchange trade. The first element is the source currency, the second the reference currency of the account, and the third the destination currency.
x.__init__(...) initializes x; see help(type(x)) for signature
TradeGain(rcv, gain, out)
A 3-tuple of numerical values, describing the result of a change in foreign exchange rates. The first element is the value due to the prior rate, the second is the gain due to the rate change, and the third element is the final sum.
x.__init__(...) initializes x; see help(type(x)) for signature
The exchange module contains functionality to enable conversion between currencies.
An exchange is a lookup container for currency exchange rates.
It behaves just like a Python dictionary, but has some extra methods.
The approach Tallywallet uses is to associate each rate against a key which is a 2-tuple of Currency. By convention, the first element of this key is the source currency, and the second is the destination. The values of the exchange mapping can therefore be considered as gain from one currency to the next.
Return the value stored against key.
This method overrides the standard behaviour of dict.get. It infers the values of missing keys as follows:
- The rate of a currency against itself is unity.
- The rate of one currency against another is the reciprocal of the reverse rate (if defined).
x.__init__(...) initializes x; see help(type(x)) for signature
Return the calculated outcome of converting the amount val via the TradePath path.
Calculate the gain related to a change in exchange rates. The self object contains the latest rates, and the historic ones are passed as an argument to this method.
Parameters: | prior – An Exchange object which contains the rates existing prior to those in the self object. |
---|---|
Return type: | TradeGain |
The ledger module defines Ledger and some associated classes.
This enumeration contains definitions for the roles played by a column in a Ledger.
x.__init__(...) initializes x; see help(type(x)) for signature
Column(name, currency, role)
A 3-tuple, describing a column in a Ledger.
x.__init__(...) initializes x; see help(type(x)) for signature
This class implements the fundamental operations you need to perform Adjusted Cost Base accounting.
Parameters: |
|
---|
The Fundamental Accounting Equation is this:
Assets - Liabilities = Capital + Income - Expenses - Dividends
Currency trading gains are counted as income. For practical purposes, the FAE is often rearranged to be:
Assets + Expenses + Dividends = Capital + Income + Liabilities
This property evaluates both sides of this second equation, and determines if they are equal or not.
Returns: | A tuple of lhs, rhs, status |
---|
Calculates the effects of a change in exchange rates.
Supply an Exchange object and an optional sequence of columns. If no columns are specified then all are assumed.
The columns are recalculated (but not committed) against the new exchange rates.
This method will generate a sequence of 3-tuples; (TradeGain, Column, Exchange).
This output is compatible with the arguments accepted by the commit method.
Applies a trade to the ledger.
If you supply an exchange argument, trade may be a TradeGain object. In this usage, a trading account in the currency of the ledger column will accept any exchange gain or loss.
Otherwise, trade should be a number. It will be added to the specified column in the ledger.
Tallywallet has chosen RSON as the serialisation format for a Ledger. It’s a readable serial object notation which can be processed by text utilities or converted into Python objects.