Skip to content

Commit

Permalink
Improved some naming
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaron committed Jun 30, 2024
1 parent ab107df commit ffba91e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ internal class AvroSamples {

// Since we only trade in one asset and have leverage, we allow up to 1000% of our equity (10k) allocated to
// one order
val policy = FlexConverter.capitalBased {
val converter = FlexConverter.capitalBased {
shorting = true
orderPercentage = 90.percent
safetyMargin = 10.percent
}
strategy.signalConverter = policy
strategy.signalConverter = converter

val account = run(feed, strategy, broker = broker)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ private object Performance {
)

val broker = SimBroker(accountModel = MarginAccount())
val policy = FlexConverter {
val converter = FlexConverter {
shorting = true
}
strategy.signalConverter = policy
strategy.signalConverter = converter

run(feed, strategy, broker = broker)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ private fun FlowContent.runTable() {
tableHeader("run", "state", "timeframe", "events", "instructions", "last update", "actions")
tbody {
runs.forEach { (run, info) ->
val policy = info.strategy
val strategy = info.strategy
tr {
td { +run }
td { state(info, policy.pause) }
td { state(info, strategy.pause) }
td { +info.timeframe.toPrettyString() }
td {
+"total = ${policy.totalEvents}"
+"total = ${strategy.totalEvents}"
br
+"empty = ${policy.emptyEvents}"
+"empty = ${strategy.emptyEvents}"
br
+"actions = ${policy.totalActions}"
+"actions = ${strategy.totalActions}"
}
td { +policy.totalInstructions.toString() }
td { +policy.lastUpdate.truncatedTo(ChronoUnit.SECONDS).toString() }
td { +strategy.totalInstructions.toString() }
td { +strategy.lastUpdate.truncatedTo(ChronoUnit.SECONDS).toString() }
td {
a(href = "/run/$run") { +"details" }
if (! info.done) {
Expand Down Expand Up @@ -106,11 +106,11 @@ internal fun Route.overview() {
}

val run = params.getOrFail("run")
val policy = runs.getValue(run).strategy
val strategy = runs.getValue(run).strategy

when (action) {
"pause" -> policy.pause = true
"resume" -> policy.pause = false
"pause" -> strategy.pause = true
"resume" -> strategy.pause = false
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import kotlin.math.min
*
* @constructor Create a new instance of Betting Against Beta
*/
open class BettingAgainstBetaTrader(
open class BettingAgainstBeta(
assets: Collection<Asset>,
private val market: Asset,
private val holdingPeriod: TimeSpan = 20.days,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ internal class TaSamples {
@Ignore
internal fun atrPolicy() {
val strategy = EMACrossover.PERIODS_5_15
val policy = AtrSignalConverter(10, 6.0, 3.0, null) {
val converter = AtrSignalConverter(10, 6.0, 3.0, null) {
orderPercentage = 0.02
shorting = true
}
strategy.signalConverter = policy
strategy.signalConverter = converter
val broker = SimBroker(accountModel = MarginAccount(minimumEquity = 50_000.0))

val feed = RandomWalk.lastYears(5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class AtrSignalConverterTest {
return account.toAccount()
}

private fun run(policy: FlexConverter): List<Instruction> {
private fun run(converter: FlexConverter): List<Instruction> {
val asset = Asset("TEST")
val signals = listOf(Signal.buy(asset))
val now = Instant.now()
Expand All @@ -55,7 +55,7 @@ internal class AtrSignalConverterTest {
val p = 5.0
val priceBar = PriceBar(asset, p + it, p + it, p + it, p + it)
val event = Event(now + it.millis, listOf(priceBar))
val o = policy.convert(signals, account, event)
val o = converter.convert(signals, account, event)
instructions.addAll(o)
}
return instructions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ internal class BettingAgainstBetaSignalConverterTest {
val assets = feed.assets.toList()
val marketAsset = assets.first()

val policy = BettingAgainstBetaTrader(assets, marketAsset, maxPositions = 6)
val strategy = BettingAgainstBeta(assets, marketAsset, maxPositions = 6)
val broker = SimBroker(accountModel = MarginAccount())
val account = run(
feed,
policy,
strategy,
broker = broker
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ internal class FlexSignalConverterTest {

@Test
fun order() {
val policy = FlexConverter()
val converter = FlexConverter()
val signals = mutableListOf<Signal>()
val event = Event(Instant.now(), emptyList())
val account = InternalAccount(Currency.USD).toAccount()
val orders = policy.convert(signals, account, event)
val orders = converter.convert(signals, account, event)
assertTrue(orders.isEmpty())
}

Expand Down

0 comments on commit ffba91e

Please sign in to comment.