Skip to content

Commit

Permalink
Added doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaron committed Jul 26, 2023
1 parent debbb87 commit ed9da05
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 35 deletions.
28 changes: 16 additions & 12 deletions roboquant-perf/src/main/kotlin/org/roboquant/perf/Performance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import kotlin.system.exitProcess
import kotlin.system.measureTimeMillis

/**
* Simple fast strategy
* Simple fast strategy.
*
* Not realistic, but with minimal overhead to ensure we can measure the performance of the engine and not the strategy.
*/
private class FastStrategy(private val skip: Int) : Strategy {

Expand All @@ -57,27 +59,29 @@ private class FastStrategy(private val skip: Int) : Strategy {
}

/**
* Fast feed
* Fast feed.
*
* Not realistic, but with minimal overhead to ensure we can measure the performance of the engine and are not
* impacted by the feed.
*/
private class FastFeed(val nAssets: Int, val events: Int) : Feed {
private class FastFeed(nAssets: Int, val events: Int) : Feed {

private val assets = mutableListOf<Asset>()
private val start = Instant.parse("2000-01-01T00:00:00Z")
val actions = ArrayList<PriceBar>(nAssets)
val size = nAssets * events

init {
repeat(nAssets) { assets.add(Asset("TEST-$it")) }
val data = doubleArrayOf(100.0, 101.0, 99.0, 100.0, 10000.0)
for (asset in assets) {
val action = PriceBar(asset, data)
actions.add(action)
}
}

override suspend fun play(channel: EventChannel) {
repeat(events) {
val actions = ArrayList<PriceBar>(nAssets)
val open = 100.0 + 10 * (it / events)
val data = doubleArrayOf(open, open + 1.0, open - 1.0, open, 500.0)
for (asset in assets) {
val action = PriceBar(asset, data)
actions.add(action)
}
channel.send(Event(actions, start + it.millis))
}
}
Expand All @@ -90,8 +94,7 @@ private class FastFeed(val nAssets: Int, val events: Int) : Feed {
* outside events like virus scanners.
*
* The main purpose is to validate the performance, throughput and stability of the back test engine, not any particular
* feed, strategy or metric. So the used feed and strategy are optimized for this test and not something you would
* normally use.
* feed, strategy or metric. So the used feed and strategy are optimized for this test and not realistic at all.
*/
private object Performance {

Expand Down Expand Up @@ -177,6 +180,7 @@ private object Performance {
val jobs = ParallelJobs()
repeat(backTests) {
jobs.add {
// use lower channel capacity to limit memory bandwidth
val roboquant = Roboquant(getStrategy(skip), logger = SilentLogger(), channelCapacity = 3)
roboquant.runAsync(feed)
}
Expand Down
52 changes: 30 additions & 22 deletions roboquant/src/main/kotlin/org/roboquant/http/WebServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,37 @@ private class WebMetric : Metric {

override fun toString(): String {
val acc = account ?: return "Not yet run"
val summary = listOf(
listOf("name", "value"),
listOf("last update", acc.lastUpdate),
listOf("events", events),
listOf("actions", actions),
listOf("buying power", acc.buyingPower),
listOf("equity", acc.equity),
listOf("open positions", acc.positions.size),
listOf("open orders", acc.openOrders.size),
listOf("closed orders", acc.closedOrders.size),
listOf("trades", acc.trades.size),
)

return """
<div>
<h3>summary</h3>
<p>events: $events</p>
<p>actions: $actions</p>
<p>buying power: ${acc.buyingPower}</p>
<p>equity: ${acc.equity}</p>
<h2>summary</h2>
${summary.toTable()}
<h2>cash</h2>
${acc.cash}
<h2>positions</h2>
${acc.positions.lines().toTable()}
<h2>open orders</h2>
${acc.openOrders.lines().toTable()}
<h2>closed orders</h2>
${acc.closedOrders.lines().toTable()}
<h3>cash</h3>
${acc.cash}
<h3>positions</h3>
${acc.positions.lines().toTable()}
<h3>open orders</h3>
${acc.openOrders.lines().toTable()}
<h3>closed orders</h3>
${acc.closedOrders.lines().toTable()}
<h3>trades</h3>
${acc.trades.lines().toTable()}
</div>
<h2>trades</h2>
${acc.trades.lines().toTable()}
""".trimIndent()
}

Expand Down Expand Up @@ -163,7 +171,7 @@ class WebServer(port: Int = 8000, username: String, password: String) {
private fun detailsRun(run: String): String {
val result = StringBuilder()
val info = runs.getValue(run)
result.append("<h2>${run}</h2>")
result.append("<h1>${run}</h1>")
result.append(info.metric.toString())
result.append("<br/><a href='/'>Back</a>".trimIndent())
return String.format(template, result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.roboquant.feeds.Event
/**
* Strategy that doesn't generate any signals. This is especially useful if you develop your Strategy as
* a Policy (for example, when you require access to the Account). In that case, the NoSignalStrategy just serves as
* a pass through and all logic can be handled by the policy.
* a pass-through and all logic can be handled by the policy.
*
* ## Example
* ```
Expand Down

0 comments on commit ed9da05

Please sign in to comment.