Class BarSeries

java.lang.Object
com.quantfinlib.core.BarSeries

public final class BarSeries extends Object
Immutable, cache-friendly OHLCV time series backed by primitive arrays (structure-of-arrays layout, no boxing) so indicators read primitive columns directly.

The column arrays never leave the object. Indexed accessors such as close(int) read one element without allocating; whole columns are available as copies (closesCopy(), ...) or copied into a reusable caller buffer with copyClosesInto(double[], int, int).

A bar can be flagged synthetic: a placeholder created by alignment (for example data.SeriesAligner.unionForwardFill carrying the last close across a halt or a listing gap) rather than a bar that traded. Estimators of volatility, average volume and impact should skip synthetic bars, since a flat zero-volume bar shrinks both. Series built without the flag report every bar as real.

  • Method Details

    • builder

      public static BarSeries.Builder builder(String symbol)
    • of

      public static BarSeries of(String symbol, double[] closes)
      Builds a series from close prices only (open = high = low = close).
    • fromBars

      public static BarSeries fromBars(String symbol, List<Bar> bars)
    • symbol

      public String symbol()
    • size

      public int size()
    • timestamp

      public long timestamp(int i)
    • open

      public double open(int i)
    • high

      public double high(int i)
    • low

      public double low(int i)
    • close

      public double close(int i)
    • volume

      public double volume(int i)
    • lastClose

      public double lastClose()
    • bar

      public Bar bar(int i)
    • isSynthetic

      public boolean isSynthetic(int i)
      Whether bar i is an alignment placeholder rather than a traded bar.
    • hasSyntheticBars

      public boolean hasSyntheticBars()
      false guarantees that no bar is synthetic; true means some may be.
    • timestampsCopy

      public long[] timestampsCopy()
      A fresh copy of the timestamp column.
    • opensCopy

      public double[] opensCopy()
      A fresh copy of the open column.
    • highsCopy

      public double[] highsCopy()
      A fresh copy of the high column.
    • lowsCopy

      public double[] lowsCopy()
      A fresh copy of the low column.
    • closesCopy

      public double[] closesCopy()
      A fresh copy of the close column.
    • volumesCopy

      public double[] volumesCopy()
      A fresh copy of the volume column.
    • copyClosesInto

      public void copyClosesInto(double[] dst, int from, int len)
      Copies closes [from, from + len) into dst[0, len) without allocating.
      Parameters:
      dst - caller-owned destination, length at least len
      from - first bar index
      len - number of bars
    • slice

      public BarSeries slice(int from, int toExclusive)
      Copy of the bar range [from, toExclusive) as a new series (for train/test splits).
    • returns

      public double[] returns()
      Simple (arithmetic) returns; length = size - 1.
    • logReturns

      public double[] logReturns()
      Log returns; length = size - 1.