Skip to content

Commit

Permalink
Make samples runnable as tests part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaron committed Dec 24, 2023
1 parent 3fc39f2 commit 565a861
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

@file:Suppress("KotlinConstantConditions")

package org.roboquant.samples

import org.roboquant.Roboquant
Expand All @@ -33,6 +31,7 @@ import org.roboquant.metrics.ProgressMetric
import org.roboquant.orders.MarketOrder
import org.roboquant.strategies.EMAStrategy
import java.time.Instant
import kotlin.test.Ignore
import kotlin.test.Test

internal class AlpacaSamples {
Expand All @@ -55,12 +54,14 @@ internal class AlpacaSamples {
)

@Test
@Ignore
internal fun alpacaBroker() {
val broker = AlpacaBroker()
println(broker.account.fullSummary())
}

@Test
@Ignore
internal fun alpacaPaperTradeStocks() {
val broker = AlpacaBroker()
val account = broker.account
Expand All @@ -85,6 +86,7 @@ internal class AlpacaSamples {


@Test
@Ignore
internal fun alpacaTradeCrypto() {
val feed = AlpacaLiveFeed()
val symbols = feed.availableCrypto.random(10).symbols
Expand All @@ -102,6 +104,7 @@ internal class AlpacaSamples {


@Test
@Ignore
internal fun alpacaTradeStocks() {
val feed = AlpacaLiveFeed()

Expand All @@ -117,6 +120,7 @@ internal class AlpacaSamples {


@Test
@Ignore
internal fun alpacaLiveFeed() {
val feed = AlpacaLiveFeed()
feed.heartbeatInterval = 10_000
Expand All @@ -130,6 +134,7 @@ internal class AlpacaSamples {


@Test
@Ignore
internal fun alpacaHistoricFeed2() {
val symbols = arrayOf(
"AAPL",
Expand Down Expand Up @@ -162,6 +167,7 @@ internal class AlpacaSamples {
}

@Test
@Ignore
internal fun singleOrder() {
val broker = AlpacaBroker {
extendedHours = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ import java.time.format.DateTimeFormatter
import kotlin.io.path.Path
import kotlin.io.path.div
import kotlin.system.measureTimeMillis
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

internal class AvroSamples {

@Test
@Ignore
internal fun multiCurrency() {
val feed = CSVFeed("data/US") {
priceParser = PriceBarParser(priceAdjust = true)
Expand Down Expand Up @@ -87,6 +89,7 @@ internal class AvroSamples {
}

@Test
@Ignore
internal fun multiRun() {
val feed = AvroFeed.sp500()
val logger = LastEntryLogger()
Expand All @@ -103,6 +106,7 @@ internal class AvroSamples {
}

@Test
@Ignore
internal fun walkForwardParallel() = runBlocking {
val feed = AvroFeed.sp500()
val logger = LastEntryLogger()
Expand All @@ -123,6 +127,7 @@ internal class AvroSamples {


@Test
@Ignore
internal fun testingStrategies() {
val strategy = EMAStrategy()
val roboquant = Roboquant(strategy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

@file:Suppress("KotlinConstantConditions")

package org.roboquant.samples


Expand All @@ -32,12 +30,14 @@ import org.roboquant.metrics.ProgressMetric
import org.roboquant.metrics.ScorecardMetric
import org.roboquant.policies.FlexPolicy
import org.roboquant.strategies.EMAStrategy
import kotlin.test.Ignore
import kotlin.test.Test


internal class BinanceSamples {

@Test
@Ignore
fun binanceLiveFeed() {
val feed = BinanceLiveFeed()
feed.subscribePriceBar("BTCBUSD", "ETHBUSD", interval = Interval.ONE_MINUTE)
Expand All @@ -49,6 +49,7 @@ internal class BinanceSamples {
}

@Test
@Ignore
fun binanceForwardTest() {
val feed = BinanceLiveFeed()

Expand All @@ -66,6 +67,7 @@ internal class BinanceSamples {
}

@Test
@Ignore
fun binanceTestBack() {
val strategy = EMAStrategy()
val initialDeposit = Amount("BUSD", 100_000).toWallet()
Expand All @@ -80,6 +82,7 @@ internal class BinanceSamples {
}

@Test
@Ignore
fun multiplier() {
val feed = BinanceLiveFeed()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

@file:Suppress("KotlinConstantConditions")

package org.roboquant.samples

import org.roboquant.Roboquant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,25 @@ import org.roboquant.common.minutes
import org.roboquant.feeds.PriceAction
import org.roboquant.feeds.filter
import org.roboquant.polygon.PolygonLiveFeed
import kotlin.test.Ignore
import kotlin.test.Test

internal class PolygonSamples {

private fun testLiveFeed() = runBlocking {
val feed = PolygonLiveFeed {
this.delayed = true
@Test
@Ignore
internal fun testLiveFeed() = runBlocking {
System.setProperty(org.slf4j.simple.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE")
val feed = PolygonLiveFeed {
this.delayed = true
}
feed.subscribe("IBM", "AAPL")
val actions = feed.filter<PriceAction>(timeframe = Timeframe.next(5.minutes)) {
println(it)
true
}
assert(actions.isNotEmpty())
feed.disconnect()
}
feed.subscribe("IBM", "AAPL")
val actions = feed.filter<PriceAction>(timeframe = Timeframe.next(5.minutes)) {
println(it)
true
}
assert(actions.isNotEmpty())
feed.disconnect()
}

fun main() {
System.setProperty(org.slf4j.simple.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE")
testLiveFeed()
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.roboquant.metrics.PriceMetric
import org.roboquant.server.WebServer
import org.roboquant.strategies.EMAStrategy
import kotlin.system.exitProcess
import kotlin.test.Ignore
import kotlin.test.Test


Expand All @@ -37,6 +38,7 @@ internal class ServerSamples {
* You can run this sample to start a server with three runs
*/
@Test
@Ignore
internal fun run() {
val server = WebServer()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.roboquant.charts.PriceBarChart
import org.roboquant.charts.transcodeSVG2PNG
import org.roboquant.feeds.random.RandomWalkFeed
import java.io.File
import kotlin.test.Ignore
import kotlin.test.Test

/*
Expand All @@ -30,6 +31,7 @@ class SSRSamples {
* The output is saved in /tmp/
*/
@Test
@Ignore
internal fun run() {
val feed = RandomWalkFeed.lastYears(2, nAssets = 5)
val chart = CorrelationChart(feed, feed.assets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ import org.roboquant.ta.*
import org.ta4j.core.indicators.bollinger.BollingerBandFacade
import org.ta4j.core.indicators.helpers.ClosePriceIndicator
import org.ta4j.core.rules.CrossedUpIndicatorRule
import kotlin.test.Ignore
import kotlin.test.Test

internal class TaSamples {

@Test
@Ignore
internal fun macd() {
val strategy = TaLibSignalStrategy { asset, prices ->
val (_, _, diff) = macd(prices, 12, 26, 9)
Expand All @@ -60,6 +62,7 @@ internal class TaSamples {
}

@Test
@Ignore
internal fun ta4j() {
// How big a look-back period should we use
val period = 20
Expand All @@ -85,6 +88,7 @@ internal class TaSamples {
}

@Test
@Ignore
internal fun customPolicy() {

/**
Expand Down Expand Up @@ -136,6 +140,7 @@ internal class TaSamples {
}

@Test
@Ignore
internal fun atrPolicy() {
val strategy = EMAStrategy.PERIODS_5_15
val policy = AtrPolicy(10, 6.0, 3.0, null) {
Expand All @@ -152,6 +157,7 @@ internal class TaSamples {

@Suppress("CyclomaticComplexMethod")
@Test
@Ignore
internal fun tenkan() {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

@file:Suppress("KotlinConstantConditions")

package org.roboquant.samples

import kotlinx.coroutines.*
Expand All @@ -41,11 +39,13 @@ import org.roboquant.strategies.EMAStrategy
import java.time.Instant
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import kotlin.test.Ignore
import kotlin.test.Test

internal class RoboquantSamples {

@Test
@Ignore
internal fun multiCurrency() {
val feed = CSVFeed("data/US") {
priceParser = PriceBarParser(priceAdjust = true)
Expand Down Expand Up @@ -75,6 +75,7 @@ internal class RoboquantSamples {
}

@Test
@Ignore
internal fun testingStrategies() {
val strategy = EMAStrategy()
val roboquant = Roboquant(strategy)
Expand All @@ -98,6 +99,7 @@ internal class RoboquantSamples {
}

@Test
@Ignore
internal fun cfd() {
val dtf = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss")

Expand All @@ -107,7 +109,7 @@ internal class RoboquantSamples {
return asset.exchange.getInstant(dt)
}

val feed = CSVFeed("/tmp/DE40CASH.csv") {
val feed = CSVFeed("tmp/DE40CASH.csv") {
template = Asset("TEMPLATE", AssetType.CFD, Currency.EUR, Exchange.DEX)
separator = '\t'
timeParser = TimeParser { a, b -> parse(a, b) }
Expand Down Expand Up @@ -140,6 +142,7 @@ internal class RoboquantSamples {
}

@Test
@Ignore
internal fun largeTest() {

class MyLiveFeed : LiveFeed() {
Expand Down

0 comments on commit 565a861

Please sign in to comment.