diff --git a/roboquant-jupyter/pom.xml b/roboquant-jupyter/pom.xml
index 751630e8e..ba95384de 100644
--- a/roboquant-jupyter/pom.xml
+++ b/roboquant-jupyter/pom.xml
@@ -70,12 +70,6 @@
echarts-java
1.0.7
-
\ No newline at end of file
diff --git a/roboquant/src/main/kotlin/org/roboquant/Roboquant.kt b/roboquant/src/main/kotlin/org/roboquant/Roboquant.kt
index d1c58c677..81930f6b3 100644
--- a/roboquant/src/main/kotlin/org/roboquant/Roboquant.kt
+++ b/roboquant/src/main/kotlin/org/roboquant/Roboquant.kt
@@ -87,7 +87,7 @@ class Roboquant(
start(runInfo.phase)
try {
- var orders = listOf()
+ var orders = emptyList()
while (true) {
val event = channel.receive()
orders = step(orders, event, runInfo)
diff --git a/roboquant/src/main/kotlin/org/roboquant/common/Asset.kt b/roboquant/src/main/kotlin/org/roboquant/common/Asset.kt
index 0d72ffb03..5c7d0f3c1 100644
--- a/roboquant/src/main/kotlin/org/roboquant/common/Asset.kt
+++ b/roboquant/src/main/kotlin/org/roboquant/common/Asset.kt
@@ -20,6 +20,7 @@ package org.roboquant.common
import java.math.BigDecimal
import java.math.RoundingMode
import java.time.LocalDate
+import java.time.Month
import java.time.format.DateTimeFormatter
/**
@@ -102,21 +103,22 @@ data class Asset(
}
/**
- * Returns a future contract based on the provided parameters
+ * Returns a future contract based on the provided parameters. It will generate a [symbol] name using the
+ * Future Contract Trading Code standard.
*/
fun futureContract(
symbol: String,
- month: Char,
+ month: Month,
year: Int,
currencyCode: String = "USD",
exchangeCode: String = "",
multiplier: Double = 1.0,
id: String = ""
): Asset {
- val months = listOf('F', 'G', 'H', 'J', 'K', 'M', 'N', 'Q', 'U', 'V', 'X', 'Z')
- require(month in months) { "$month not one of $months" }
+ val months = arrayOf('F', 'G', 'H', 'J', 'K', 'M', 'N', 'Q', 'U', 'V', 'X', 'Z')
+ val monthEncoding = months[month.value - 1]
val yearCode = year.toString()
- val futureSymbol = "$symbol$month${yearCode.takeLast(2)}"
+ val futureSymbol = "$symbol$monthEncoding${yearCode.takeLast(2)}"
return Asset(futureSymbol, AssetType.FUTURES, currencyCode, exchangeCode, multiplier, id)
}
@@ -159,7 +161,7 @@ data class Asset(
}
/**
- * Faster hashcode than default
+ * Faster hashcode that is well distributed than the default data class generated one
*/
override fun hashCode(): Int {
return symbol.hashCode()
@@ -183,6 +185,7 @@ data class Asset(
* It supports fractional sizes by providing a number of [fractions] bigger than 0.
*/
fun contractSize(amount: Double, price: Double, fractions: Int = 0): Size {
+ require (fractions >= 0) { "factions has to be >= 0, found $fractions" }
val singleContractValue = value(Size.ONE, price).value
val size = BigDecimal(amount / singleContractValue).setScale(fractions, RoundingMode.DOWN)
return Size(size)
diff --git a/roboquant/src/test/kotlin/org/roboquant/common/AssetTest.kt b/roboquant/src/test/kotlin/org/roboquant/common/AssetTest.kt
index 6aaa9c10e..9a1d07c7e 100644
--- a/roboquant/src/test/kotlin/org/roboquant/common/AssetTest.kt
+++ b/roboquant/src/test/kotlin/org/roboquant/common/AssetTest.kt
@@ -20,6 +20,7 @@ package org.roboquant.common
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import java.time.LocalDate
+import java.time.Month
import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
@@ -45,15 +46,11 @@ internal class AssetTest {
val a = Asset.optionContract("SPX", LocalDate.parse("2014-11-22"), 'P', "19.50")
assertEquals("SPX 141122P00019500", a.symbol)
- val b = Asset.futureContract("GC", 'Z', 18)
- val b2 = Asset.futureContract("GC", 'Z', 2018)
+ val b = Asset.futureContract("GC", Month.DECEMBER, 18)
+ val b2 = Asset.futureContract("GC", Month.DECEMBER, 2018)
assertEquals("GCZ18", b.symbol)
assertEquals(b, b2)
- assertThrows {
- Asset.futureContract("GC", 'P', 18)
- }
-
val c = Asset.forexPair("EUR_USD")
assertEquals("EUR/USD", c.symbol)
@@ -101,8 +98,7 @@ internal class AssetTest {
val s2 = a.contractSize(1000.0, 1.0, 4)
assertEquals(Size(10), s2)
- val s3 = a.contractSize(250.0, 1.0, 4)
- assertEquals(Size("2.5"), s3)
+ assertThrows { a.contractSize(250.0, 1.0, -1) }
}
}
\ No newline at end of file