org.roboquant.ta.PriceBarSeries.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of roboquant-ta Show documentation
Show all versions of roboquant-ta Show documentation
Technical analysis support for the roboquant algorithmic trading platform
package org.roboquant.ta
import org.roboquant.common.Asset
import org.roboquant.feeds.Event
import org.roboquant.feeds.PriceBar
/**
* Contains the [PriceBarSerie] data for a collection of Assets
*
* @property capacity
*/
class PriceBarSeries private constructor(
private val capacity: Int,
private val series: MutableMap
) : MutableMap by series {
/**
* Create a new PriceBarSeries with the provided [capacity] per asset.
*/
constructor(capacity: Int) : this(capacity, mutableMapOf())
/**
* Add a single [priceBar]
*/
fun add(priceBar: PriceBar): Boolean {
val priceBuffer = series.getOrPut(priceBar.asset) { PriceBarSerie(capacity) }
priceBuffer.add(priceBar)
return priceBuffer.isFull()
}
/**
* Add all the [PriceBar] actions found in the [event] to this PriceBarSeries
*/
fun addAll(event: Event) {
for (action in event.actions.filterIsInstance()) {
val priceBuffer = series.getOrPut(action.asset) { PriceBarSerie(capacity) }
priceBuffer.add(action)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy