Represents a Currency, which is the Unit of Measure for Money
Represent the rate of exchange between two currencies
Represent the rate of exchange between two currencies
the base or "Fixed" currency (usually a value of 1 currency unit, but not required)
the counter or "Variable" currency
0.1
Represents a quantity of Money.
Represents a quantity of Money.
Money is similar to other quantities in that it represents an amount of something - purchasing power - and it is measured in units - currencies.
The main difference is that the conversion rate between currencies can not be certain at compile. (In fact it may not always be so easy to know them at runtime as well.)
To address this diversion from the way most other quantities work, Money overrides several of the standard methods and operators to ensure one of two rules is followed:
1) this and that are in the same currency, or 2) there is in an implicit MoneyContext in scope (which may or may not have the applicable exchange rate)
Methods and operations applied to moneys of different currencies may throw a NoSuchExchangeRateException if the implicit MoneyContext does not contain the Rate(s) necessary to perform the conversion.
The defaultMoneyContext includes USD as the default currency, a list of ~20 other currencies and NO exchange rates
0.1
MoneyContext
MoneyContext
Provides a context for Money specific operations.
When provided as an implicit parameter, the defaultCurrency will be used by the Money factory when no other currency is provided.
Provides for cross-currency conversions.
Will act as an implicit parameter to cross currency operations to allow for easy conversions
Currency used when none is supplied to the Money factory
Collection of Exchange Rates used for currency conversions
0.1
Represents a price
Represents a price
A price is an squants.Ratio between a quantity of squants.market.Money and some other squants.Quantity
Quantity Type
Money
Quantity
0.1
Factory singleton for Money
Support for Money DSL
Squants Market API
Market Types are similar but not quite the same as other quantities in the library.
The primary type, squants.market.Money, is derived from Quantity, and its Units of Measure are Currencies. However, because the conversion multipliers between units can not be predefined, many of the behaviors have been overridden and augmented to realize correct behavior.
squants.market.Prices represent a Ratio between Money and some other Quantity. Prices can be created from ratios of Money and a Quantity
Multiplying a Price * Quantity will yield Money amount that represents the cost of the quantity
and multiplying Price * Money will yield the corresponding Quantity amount
squants.market.CurrencyExchangeRates represent conversion rates between currencies. Use them to explicitly convert Money values in one currency to values in another.
squants.market.MoneyContext provide the implicit context necessary to perform cross-currency operations on Money values with conversions automatically applied.
Some binary math operations will work on Moneys of like Currency with no MoneyContext in scope. Attempts to perform these operations on Moneys of dissimilar currencies will throw an exception at runtime.
Other operations, including direct conversions to other currencies, require a MoneyContext and will not compile without it. However, there is no compile time check to determine if the correct exchange rates will be available at runtime. Operation requiring conversion without the required rates available will throw a NoSuchExchangeRateException at runtime.
The defaultMoneyContext uses the USD as the default and provides a list of ~20 common currencies, and NO exchange rates. If your application requires something different you should initialize your own implicit MoneyContext
0.1