All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.roboquant.ta.PriceBarSeries.kt Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
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