IbkrApi.Backtester.Bar (ibkr_api v1.0.0)

View Source

Historical market data bar structure for backtesting.

This module provides a standardized bar structure and conversion utilities for backtesting with IBKR historical data.

Summary

Functions

Returns true if the bar is bearish (close < open).

Returns true if the bar is bullish (close > open).

Converts IbkrApi.ClientPortal.MarketData.HistoricalBar to IbkrApi.Backtester.Bar.

Converts IBKR API response data to IbkrApi.Backtester.Bar struct.

Returns the price range (high - low) for the bar.

Returns the typical price (HLC/3) for the bar.

Types

t()

@type t() :: %IbkrApi.Backtester.Bar{
  close: float(),
  high: float(),
  low: float(),
  open: float(),
  timestamp: DateTime.t(),
  volume: float()
}

Functions

bearish?(bar)

@spec bearish?(t()) :: boolean()

Returns true if the bar is bearish (close < open).

bullish?(bar)

@spec bullish?(t()) :: boolean()

Returns true if the bar is bullish (close > open).

from_historical_bar(bar)

@spec from_historical_bar(IbkrApi.ClientPortal.MarketData.HistoricalBar.t()) :: t()

Converts IbkrApi.ClientPortal.MarketData.HistoricalBar to IbkrApi.Backtester.Bar.

This provides compatibility between the IBKR API module and backtesting framework.

from_ibkr(map)

@spec from_ibkr(map()) :: t()

Converts IBKR API response data to IbkrApi.Backtester.Bar struct.

Parameters

  • data: Map containing IBKR bar data with keys "t", "o", "h", "l", "c", "v"

Examples

iex> IbkrApi.Backtester.Bar.from_ibkr(%{"t" => 1707139200000, "o" => 189.9, "h" => 190.3, "l" => 188.7, "c" => 189.5, "v" => 24018321})
%IbkrApi.Backtester.Bar{
  timestamp: ~U[2024-02-05 13:20:00.000Z],
  open: 189.9,
  high: 190.3,
  low: 188.7,
  close: 189.5,
  volume: 24018321
}

range(bar)

@spec range(t()) :: float()

Returns the price range (high - low) for the bar.

typical_price(bar)

@spec typical_price(t()) :: float()

Returns the typical price (HLC/3) for the bar.