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

Source
package.scala
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. abstract class Currency extends UnitOfMeasure[Money]

    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: Seq[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 Serializable with Product

    Represents a price

Value Members

  1. object ARS extends Currency

  2. object AUD extends Currency

  3. object BRL extends Currency

  4. object BTC extends Currency

  5. object CAD extends Currency

  6. object CHF extends Currency

  7. object CLP extends Currency

  8. object CNY extends Currency

  9. object CZK extends Currency

  10. object DKK extends Currency

  11. object EUR extends Currency

  12. object GBP extends Currency

  13. object HKD extends Currency

  14. object INR extends Currency

  15. object JPY extends Currency

  16. object KRW extends Currency

  17. object MXN extends Currency

  18. object MYR extends Currency

  19. object Money extends Dimension[Money] with Serializable

    Factory singleton for Money

  20. object MoneyConversions

    Support for Money DSL

  21. object NOK extends Currency

  22. object NZD extends Currency

  23. object RUB extends Currency

  24. object SEK extends Currency

  25. object USD extends Currency

  26. object XAG extends Currency

  27. object XAU extends Currency

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

  29. lazy val defaultCurrencySet: Set[Currency]

  30. lazy val defaultMoneyContext: MoneyContext

Inherited from AnyRef

Inherited from Any

Ungrouped