squants

market

package market

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

val money: Money = USD(10)
val length: Length = Meters(1)
val price: Price[Length] = money / length

Multiplying a Price * Quantity will yield Money amount that represents the cost of the quantity

val cost: Money = price * Meters(3.8)

and multiplying Price * Money will yield the corresponding Quantity amount

val budget: Money = USD(250)
val quote: Length = price * budget

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

Since

0.1

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. market
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. case class Currency(code: String, name: String, symbol: String, formatDecimals: Int) extends UnitOfMeasure[Money] with Product with Serializable

    Represents a Currency, which is the Unit of Measure for Money

  2. case class CurrencyExchangeRate(base: Money, counter: Money) extends Ratio[Money, Money] with Product with Serializable

    Represent the rate of exchange between two currencies

  3. final class Money extends Quantity[Money]

    Represents a quantity of Money.

  4. case class MoneyContext(defaultCurrency: Currency, currencies: Set[Currency], rates: List[CurrencyExchangeRate], allowIndirectConversions: Boolean = true) extends Product with Serializable

    MoneyContext

  5. class NoSuchExchangeRateException extends Exception

  6. case class Price[A <: Quantity[A]](money: Money, quantity: A) extends Ratio[Money, A] with Product with Serializable

    Represents a price

Value Members

  1. lazy val ARS: Currency

  2. lazy val AUD: Currency

  3. lazy val BRL: Currency

  4. lazy val BTC: Currency

  5. lazy val CAD: Currency

  6. lazy val CHF: Currency

  7. lazy val CLP: Currency

  8. lazy val CNY: Currency

  9. lazy val CZK: Currency

  10. lazy val DKK: Currency

  11. lazy val EUR: Currency

  12. lazy val GBP: Currency

  13. lazy val HKD: Currency

  14. lazy val INR: Currency

  15. lazy val JPY: Currency

  16. lazy val KRW: Currency

  17. lazy val MXN: Currency

  18. object Money extends Serializable

    Factory singleton for Money

  19. object MoneyConversions

    Support for Money DSL

  20. lazy val NOK: Currency

  21. lazy val NZD: Currency

  22. lazy val RUB: Currency

  23. lazy val SEK: Currency

  24. lazy val USD: Currency

  25. lazy val XAG: Currency

  26. lazy val XAU: Currency

  27. lazy val defaultCurrencyMap: Map[String, Currency]

  28. lazy val defaultCurrencySet: Set[Currency]

  29. lazy val defaultMoneyContext: MoneyContext

Inherited from AnyRef

Inherited from Any

Ungrouped