Created
April 18, 2019 13:27
-
-
Save yasuabe/ec1c6266c185866e07a6ec339e5672ff to your computer and use it in GitHub Desktop.
squants exercise: Money and Price
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import squants.market.{JPY, MoneyContext, USD} | |
import squants.market.MoneyConversions._ | |
val rate = USD / 112.14.yen | |
// r: CurrencyExchangeRate = USD/JPY 112.14 | |
rate convert 10.dollars | |
// 1121.4 JPY | |
import squants.market.defaultMoneyContext | |
implicit val moneyContext: MoneyContext = | |
defaultMoneyContext withExchangeRates List(USD / 112.14.yen) | |
10.dollars in JPY | |
// 1121.4 JPY | |
import squants.space.VolumeConversions._ | |
// 原油価格 1バレル(42ガロン) につき 64.39 USドル | |
val oilPrice = 64.39.dollars / 42.gallons | |
// oilPrice: Price[Volume] = 64.39 USD/42.0 gal | |
// これを1000リットル買うと日本円で、、、 | |
(oilPrice * 1000.liters in JPY).toFormattedString | |
// res2: String = ¥45417 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment