Replies: 3 comments 9 replies
-
I'll try to provide some answers and pointers per topic, but please feel free to correct me if I misunderstood it. So this reply covers the scanning part as I understood it: Scanning It is possible to have different strategies for different assets. Right now the out of the box provided asset filters are "static", but they could be made dynamic. Small (dummy) example with two different strategies for different stocks: import org.roboquant.common.AssetFilter
import org.roboquant.strategies.CombinedStrategy
import org.roboquant.strategies.EMAStrategy
import org.roboquant.strategies.filter
val strategy = CombinedStrategy(
EMAStrategy.PERIODS_12_26.filter(
AssetFilter.includeSymbols("TSLA", "AAPL")
),
EMAStrategy.PERIODS_5_15.filter(
AssetFilter.includeSymbols("IBM", "MSFT", "GOOG")
)
) I use EMAStrategy variations as an example, but of course these strategies could be anything. And if I understood your use-case correctly, something like the following could work: // This class represents the scanner you referred to
class Scanner(val symbols: Array<String>, val signal: String)
val scanners = listOf<Scanner>()
val strategies = mutableListOf<Strategy>()
for (x in scanners) {
when(x.signal) {
"a" -> strategies.add(EMAStrategy.PERIODS_12_26.filter(AssetFilter.includeSymbols(*x.symbols)))
"b" -> strategies.add(EMAStrategy.PERIODS_5_15.filter(AssetFilter.includeSymbols(*x.symbols)))
}
}
val strategy = CombinedStrategy(strategies) |
Beta Was this translation helpful? Give feedback.
-
(No) Indicators Roboquant is event driven. That means that your strategy will just get the prices (or any other piece of information) at each moment in time they become available. This is true for both back-testing as well as live trading. class MyStrategy : Strategy {
override fun generate(event: Event): List<Signal> {
print(event.time)
for ((asset, action) in event.prices) {
val price = action.getPrice()
print("$asset $price")
}
TODO()
}
} However this is not convenient for many strategies since they need historic series of prices to work (f.e the last 10 prices for a stock). So there are some helper classes you can extend that make your life easier: class MyStrategy2 : HistoricPriceStrategy(10, priceType = "CLOSE") {
override fun generateRating(data: DoubleArray): Rating? {
return if (data.last() == data.max())
Rating.BUY
else if (data.last() == data.min())
Rating.SELL
else
null
}
} And to make it even more convenient, roboquant also comes with bindings for two popular technical analysis/indicator frameworks, Ta4J and TaLib. TaLib is the much faster one of the two, while Ta4J is a more flexible. val shortTerm = 30
val longTerm = 50
val myStrategy3 = TaLibStrategy(longTerm)
myStrategy3.buy {
sma(it.close, shortTerm) > sma(it.close, longTerm)
}
myStrategy3.buy {
sma(it.close, shortTerm) < sma(it.close, longTerm)
} So you can see there are different ways to access prices in a strategy, depending on your needs. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the time you took to explain these concepts. |
Beta Was this translation helpful? Give feedback.
-
Adding to the discussion on discord I would like to describe my ideas for a bot that basically trades like an intraday trader focussing on
Scanning
At the heart of any of these strategies lies a dynamic selection of stocks based on some sort of scanning logic. I think the scanning part it self does not have to be a feature of the framework, but it would be great to be able to hook into the selection of stocks traded dynamically. It would probably best if this selection included some sort of signal, as depending on what scanner the stock came up on, a user might want to run a different strategy or parameter-set.
As I side note: Im working on a stock scanner in python right now. It scans the entire market periodically and saves data from polygon. In the future this should serve me with the ability to "replay" the market for each trading day and provide the necesarry data to backtest. Id be willing to port this to AVRO and share it with community
(No) Indicators
From what Ive understood so far entry and exit signals in roboquant rely on some sort of indicator logic. I have to dive deeper into ta4j as I think it might be possible to reference "pure price action" with it.
Reading into the ta4j strategy code it uses a "series" argument which i think might be suitable.
MultiTimeframe Analysis / Execution
This is something I have really struggeled with while testing different frameworks. When trading live manually I would compare different timeframes to gain a better understanding of the price action. In detail you might want to study these charts:
or perform any other sort of analysis, basically accepting more or less noise the higher/lower you go.
The execution however should always be triggered by tick level price data - otherwise one can never catch a breakout.
Enabling a strategy to reference certain intervals of priceaction indepently of the timeframe would unlock great potential as you could:
I think archieving this relies heavily on the user as it would be necesarry to have all of the candle data ready. Of course some aggregation feature would help alot in this scenario. Getting back to the fact that the stock selection is limited by the scanner I am currently defaulting to downloading 3 months of data in daily resolution, the last week in hourly resolution and the trading day itself in tick resolution. I think you could also add a minute resolution for some sort of period to easily be able to aggregate these bars into any timeframe.
Some more detail on entry logic based on price action
If not using an indicator to generate signals one pretty much always relies on the price break through some sort of predefined level i.e. support/resistance, channels, pivot points etc. Identifying those algorithmically means defining some sort of lookback period and granularity. So to identify a pivot high you would look at the last x candles and pick the high point where y candles to left, aswell as z candles to the right are lower.
Conclusion
I hope this can give anybody reading some trading ideas and maybe we can figure out solutions for this together.
If somebody with a better understanding of roboquant could point me in some general directions I would be happy to share my solutions/findings with the community, possibly to be referenced in the documentation.
Beta Was this translation helpful? Give feedback.
All reactions