From 3d18229ab6064dfabea0eac87fedc72dffc00b5d Mon Sep 17 00:00:00 2001 From: fcaptuayo Date: Fri, 11 Dec 2020 17:39:57 -0500 Subject: [PATCH] added Colombian Peso and Polish Zloty in Money supported --- README.md | 6 +++--- shared/src/main/scala/squants/market/Money.scala | 5 ++++- shared/src/test/scala/squants/market/MoneySpec.scala | 4 ++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c433b8e2..04df84a3 100644 --- a/README.md +++ b/README.md @@ -634,7 +634,7 @@ scala> val exchangeRates = List(USD / CAD(1.05), USD / MXN(12.50), USD / JPY(100 exchangeRates: List[squants.market.CurrencyExchangeRate] = List(USD/CAD 1.05, USD/MXN 12.5, USD/JPY 100.0) scala> implicit val moneyContext = defaultMoneyContext withExchangeRates exchangeRates -moneyContext: squants.market.MoneyContext = MoneyContext(DefaultCurrency(USD),Currencies(ARS,AUD,BRL,BTC,CAD,CHF,CLP,CNY,CZK,DKK,ETH,EUR,GBP,HKD,INR,JPY,KRW,LTC,MXN,MYR,NAD,NOK,NZD,RUB,SEK,USD,XAG,XAU,ZAR),ExchangeRates(USD/CAD 1.05,USD/JPY 100.0,USD/MXN 12.5),AllowIndirectConversions(true)) +moneyContext: squants.market.MoneyContext = MoneyContext(DefaultCurrency(USD),Currencies(ARS,AUD,BRL,BTC,CAD,CHF,CLP,CNY,CZK,DKK,ETH,EUR,GBP,HKD,INR,JPY,KRW,LTC,MXN,MYR,NAD,NOK,NZD,RUB,SEK,USD,XAG,XAU,ZAR,COP,PLN),ExchangeRates(USD/CAD 1.05,USD/JPY 100.0,USD/MXN 12.5),AllowIndirectConversions(true)) scala> val energyPrice = USD(102.20) / MegawattHours(1) energyPrice: squants.market.Price[squants.energy.Energy] = 102.2 USD/1.0 MWh @@ -925,7 +925,7 @@ implicit val moneyContext = defaultMoneyContext ```scala scala> implicit val moneyNum = new MoneyNumeric() -moneyNum: squants.market.MoneyConversions.MoneyNumeric = MoneyNumeric(MoneyContext(DefaultCurrency(USD),Currencies(ARS,AUD,BRL,BTC,CAD,CHF,CLP,CNY,CZK,DKK,ETH,EUR,GBP,HKD,INR,JPY,KRW,LTC,MXN,MYR,NAD,NOK,NZD,RUB,SEK,USD,XAG,XAU,ZAR),ExchangeRates(),AllowIndirectConversions(true))) +moneyNum: squants.market.MoneyConversions.MoneyNumeric = MoneyNumeric(MoneyContext(DefaultCurrency(USD),Currencies(ARS,AUD,BRL,BTC,CAD,CHF,CLP,CNY,CZK,DKK,ETH,EUR,GBP,HKD,INR,JPY,KRW,LTC,MXN,MYR,NAD,NOK,NZD,RUB,SEK,USD,XAG,XAU,ZAR,COP,PLN),ExchangeRates(),AllowIndirectConversions(true))) scala> val sum = List(USD(100), USD(10)).sum sum: squants.market.Money = 1.1E+2 USD @@ -1322,7 +1322,7 @@ import squants.time.TimeConversions._ ```scala scala> implicit val moneyContext = defaultMoneyContext -moneyContext: squants.market.MoneyContext = MoneyContext(DefaultCurrency(USD),Currencies(ARS,AUD,BRL,BTC,CAD,CHF,CLP,CNY,CZK,DKK,ETH,EUR,GBP,HKD,INR,JPY,KRW,LTC,MXN,MYR,NAD,NOK,NZD,RUB,SEK,USD,XAG,XAU,ZAR),ExchangeRates(),AllowIndirectConversions(true)) +moneyContext: squants.market.MoneyContext = MoneyContext(DefaultCurrency(USD),Currencies(ARS,AUD,BRL,BTC,CAD,CHF,CLP,CNY,CZK,DKK,ETH,EUR,GBP,HKD,INR,JPY,KRW,LTC,MXN,MYR,NAD,NOK,NZD,RUB,SEK,USD,XAG,XAU,ZAR,COP,PLN),ExchangeRates(),AllowIndirectConversions(true)) scala> val energyPrice: Price[Energy] = 45.25.money / megawattHour energyPrice: squants.market.Price[squants.energy.Energy] = 45.25 USD/1.0 MWh diff --git a/shared/src/main/scala/squants/market/Money.scala b/shared/src/main/scala/squants/market/Money.scala index ae3f043d..8e815348 100644 --- a/shared/src/main/scala/squants/market/Money.scala +++ b/shared/src/main/scala/squants/market/Money.scala @@ -471,7 +471,8 @@ object ETH extends Currency("ETH", "Ether", "\u039E", 15) object LTC extends Currency("LTC", "Litecoin", "\u0141", 15) object ZAR extends Currency("ZAR", "South African Rand", "R", 2) object NAD extends Currency("NAD", "Namibian Dollar", "N$", 2) - +object COP extends Currency("COP", "Colombian Peso", "$", 2) +object PLN extends Currency("PLN", "Polish Zloty", "zł", 2) /** * Support for Money DSL */ @@ -512,6 +513,8 @@ object MoneyConversions { def litecoin = LTC def ZAR = Money(n, squants.market.ZAR) def NAD = Money(n, squants.market.NAD) + def COP = Money(n, squants.market.COP) + def PLN = Money(n, squants.market.PLN) } class MoneyNumeric()(implicit mc: MoneyContext) extends Numeric[Money] { diff --git a/shared/src/test/scala/squants/market/MoneySpec.scala b/shared/src/test/scala/squants/market/MoneySpec.scala index 8884a440..cb6fe96f 100644 --- a/shared/src/test/scala/squants/market/MoneySpec.scala +++ b/shared/src/test/scala/squants/market/MoneySpec.scala @@ -30,6 +30,8 @@ class MoneySpec extends AnyFlatSpec with Matchers { implicit val moneyContext = MoneyContext(USD, defaultCurrencySet, Nil) Currency("USD") should be(Success(USD)) Currency("NAD") should be(Success(NAD)) + Currency("COP") should be(Success(COP)) + Currency("PLN") should be(Success(PLN)) Currency("DUM") should be(Failure(NoSuchCurrencyException("DUM", moneyContext))) } @@ -484,6 +486,8 @@ class MoneySpec extends AnyFlatSpec with Matchers { d.litecoin should be(LTC(d)) d.ZAR should be(ZAR(d)) d.NAD should be(NAD(d)) + d.COP should be(COP(d)) + d.PLN should be(PLN(d)) } it should "provide Numeric support within a MoneyContext with no Exchange Rates" in {