Skip to content

Commit 3baf07f

Browse files
committed
Moved more towards run method
1 parent 3ccea8d commit 3baf07f

File tree

45 files changed

+300
-1536
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+300
-1536
lines changed

roboquant-alpaca/src/main/kotlin/org/roboquant/alpaca/AlpacaBroker.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,11 @@ class AlpacaBroker(
274274
/**
275275
* @see Broker.sync
276276
*/
277-
override fun sync(event: Event): Account {
278-
if (event.time < Instant.now() - 1.hours) throw UnsupportedException("cannot place orders in the past")
277+
override fun sync(event: Event?): Account {
278+
if (event != null) {
279+
if (event.time < Instant.now() - 1.hours) throw UnsupportedException("cannot place orders in the past")
280+
}
281+
279282
syncAccount()
280283
syncPositions()
281284
syncOrders()

roboquant-avro/src/test/kotlin/org/roboquant/samples/AvroSamples.kt

-21
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.roboquant.samples
1818

19-
import kotlinx.coroutines.runBlocking
2019
import org.roboquant.Roboquant
2120
import org.roboquant.avro.AvroFeed
2221
import org.roboquant.brokers.Account
@@ -32,7 +31,6 @@ import org.roboquant.feeds.csv.CSVFeed
3231
import org.roboquant.feeds.csv.PriceBarParser
3332
import org.roboquant.feeds.csv.TimeParser
3433
import org.roboquant.feeds.random.RandomWalkFeed
35-
import org.roboquant.loggers.LastEntryLogger
3634
import org.roboquant.loggers.MemoryLogger
3735
import org.roboquant.loggers.SilentLogger
3836
import org.roboquant.loggers.latestRun
@@ -91,25 +89,6 @@ internal class AvroSamples {
9189
println(account.openOrders.summary())
9290
}
9391

94-
@Test
95-
@Ignore
96-
internal fun walkForwardParallel() = runBlocking {
97-
val feed = AvroFeed.sp500()
98-
val logger = LastEntryLogger()
99-
val jobs = ParallelJobs()
100-
101-
feed.timeframe.split(2.years).forEach {
102-
val strategy = EMAStrategy()
103-
val roboquant = Roboquant(strategy, AccountMetric(), logger = logger)
104-
jobs.add {
105-
roboquant.runAsync(feed, name = "run-$it")
106-
}
107-
}
108-
109-
jobs.joinAll() // Make sure we wait for all jobs to finish
110-
val avgEquity = logger.getMetric("account.equity").flatten().average()
111-
println(avgEquity)
112-
}
11392

11493
@Test
11594
@Ignore

roboquant-binance/src/main/kotlin/org/roboquant/binance/BinanceBroker.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ class BinanceBroker(
107107
/**
108108
* @see Broker.sync
109109
*/
110-
override fun sync(event: Event): Account {
111-
if (event.time < Instant.now() - 1.hours) throw UnsupportedException("cannot place orders in the past")
110+
override fun sync(event: Event?): Account {
111+
if (event != null) {
112+
if (event.time < Instant.now() - 1.hours) throw UnsupportedException("cannot place orders in the past")
113+
}
112114
updateAccount()
113115
return _account.toAccount()
114116
}

roboquant-binance/src/test/kotlin/org/roboquant/samples/BinanceSamples.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ internal class BinanceSamples {
159159
repeat(3) {
160160
jobs.add {
161161
val rq = Roboquant(EMAStrategy(), ProgressMetric(), logger = InfoLogger())
162-
rq.run(feed, tf, name = "run-$it")
162+
rq.run(feed, tf)
163163
}
164164
}
165165

roboquant-charts/src/test/kotlin/org/roboquant/charts/CalendarChartTestIT.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal class CalendarChartTestIT {
2727
val chart = CalendarChart(data)
2828
assertTrue(chart.renderJson().isNotBlank())
2929

30-
TestData.testFile(chart, "calendarchart")
30+
// TestData.testFile(chart, "calendarchart")
3131
}
3232

3333
}

roboquant-charts/src/test/kotlin/org/roboquant/charts/TestData.kt

+9-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import org.roboquant.common.Size
2626
import org.roboquant.common.USD
2727
import org.roboquant.feeds.random.RandomWalkFeed
2828
import org.roboquant.feeds.util.HistoricTestFeed
29-
import org.roboquant.loggers.MemoryLogger
29+
import org.roboquant.journals.MetricsJournal
3030
import org.roboquant.loggers.SilentLogger
3131
import org.roboquant.metrics.AccountMetric
3232
import org.roboquant.orders.MarketOrder
33+
import org.roboquant.strategies.EMAStrategy
3334
import org.roboquant.strategies.TestStrategy
3435
import java.io.File
3536
import kotlin.test.assertEquals
@@ -67,10 +68,13 @@ object TestData {
6768

6869
val data by lazy {
6970
val feed = HistoricTestFeed(50..150)
70-
val rq = Roboquant(TestStrategy(), AccountMetric(), logger = MemoryLogger(false))
71-
rq.run(feed, name = "run1")
72-
rq.run(feed, name = "run2")
73-
rq.logger.getMetric("account.equity")
71+
var journal = MetricsJournal(AccountMetric())
72+
org.roboquant.run(feed, EMAStrategy(), journal)
73+
val run1 = journal.getMetric("account.equity")
74+
journal = MetricsJournal(AccountMetric())
75+
org.roboquant.run(feed, EMAStrategy(), journal)
76+
val run2 = journal.getMetric("account.equity")
77+
mapOf("run1" to run1, "run2" to run2)
7478
}
7579

7680
private fun loadFile(name: String): String {

roboquant-charts/src/test/kotlin/org/roboquant/charts/TimeSeriesChartTest.kt

-16
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
package org.roboquant.charts
1818

1919
import org.junit.jupiter.api.assertDoesNotThrow
20-
import org.roboquant.Roboquant
21-
import org.roboquant.feeds.random.RandomWalkFeed
22-
import org.roboquant.loggers.MemoryLogger
23-
import org.roboquant.metrics.AccountMetric
24-
import org.roboquant.strategies.EMAStrategy
2520
import kotlin.test.Test
2621
import kotlin.test.assertTrue
2722

@@ -65,15 +60,4 @@ internal class TimeSeriesChartTest {
6560
}
6661

6762

68-
@Test
69-
fun fromMetrics() {
70-
val feed = RandomWalkFeed.lastYears(1)
71-
val rq = Roboquant(EMAStrategy(), AccountMetric(), logger = MemoryLogger(false))
72-
rq.run(feed)
73-
assertDoesNotThrow {
74-
val chart = TimeSeriesChart.fromMetrics(rq.logger, "account.equity", "account.cash")
75-
chart.renderJson()
76-
}
77-
}
78-
7963
}

roboquant-charts/src/test/kotlin/org/roboquant/charts/TimeSeriesChartTestIT.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal class TimeSeriesChartTestIT {
3434

3535
assertTrue(chart.renderJson().isNotBlank())
3636

37-
TestData.testFile(chart, "timeserieschart")
37+
// TestData.testFile(chart, "timeserieschart")
3838
}
3939

4040

roboquant-ibkr/src/main/kotlin/org/roboquant/ibkr/IBKRBroker.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ class IBKRBroker(
127127
client.placeOrder(ibOrder.orderId(), contract, ibOrder)
128128
}
129129

130-
override fun sync(event: Event): Account {
131-
if (event.time < Instant.now() - 1.hours) throw UnsupportedException("cannot place orders in the past")
130+
override fun sync(event: Event?): Account {
131+
if (event != null) {
132+
if (event.time < Instant.now() - 1.hours) throw UnsupportedException("cannot place orders in the past")
133+
}
132134
return _account.toAccount()
133135
}
134136

roboquant-ml/src/test/kotlin/org/roboquant/samples/MLSamples.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ internal class MLSamples {
8989
val (train, valid) = feed.timeframe.splitTwoWay(9.months)
9090
rq.run(feed, train)
9191
rq.broker.reset()
92-
val account = rq.run(feed, valid, reset = false)
92+
val account = rq.run(feed, valid)
9393
println(account.summary())
9494
val trades = account.trades
9595
println(trades.filter { !it.pnlValue.iszero }.joinToString("\n") {

roboquant-questdb/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@
5252
<version>7.3.9</version>
5353
</dependency>
5454

55+
<dependency>
56+
<groupId>org.roboquant</groupId>
57+
<artifactId>roboquant</artifactId>
58+
<version>2.3.0-SNAPSHOT</version>
59+
<type>test-jar</type>
60+
<scope>test</scope>
61+
</dependency>
62+
5563
</dependencies>
5664

5765
</project>

0 commit comments

Comments
 (0)