fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Pennant

Install and import#

bash
npm install fintech-algorithms
ts
import { detectPennant } from "fintech-algorithms/geometric-chart-patterns/continuation-structures/pennant";

Signature#

detectPennant()

Worked example#

executed This entry is a thin wrapper its test never calls directly, so it was invoked with the arguments its shared implementation received. Real output, not asserted against a published figure.

Input#

argument 1
[92, 94.416667, 96.833333, 99.25, 101.666667, 104.083333]

Showing 6 of 96 elements.

Call#

detectPennant()

Returns#

object with 7 fields: pattern, state, reason, event, events, pivots, parameters

{
  "pattern": "pennant",
  "state": "confirmed",
  "reason": "breakout-confirmed",
  "event": {
    "pattern": "pennant",
    "state": "confirmed",
    "reason": "breakout-confirmed",
    "pivot_indices": [16, 22, 28, 34, 40, 46],
    "pivot_prices": [125, 115, 123, 116.5, 121, 118],
    "pivot_types": ["high", "low", "high", "low", "high", "low"],
    "candidate_available_index": 48,
    "confirmation_index": 49,
    "breakout_direction": "bullish",
    "expected_direction": "bullish",
    "subtype": null,
    "upper_boundary": 119.5,
    "lower_boundary": 118.375,
    "metrics": {
      "upper_slope": -0.16666666666666666,
      "lower_slope": 0.125,
      "upper_relative_slope": -0.0013917884481558802,
      "lower_relative_slope": 0.0010438413361169101,
      "upper_intercept": 127.66666666666667,
      "lower_intercept": 112.25,
      "width_start": 10.75,
      "width_end": 2,
      "convergence": 0.813953488372093,
      "parallel_gap": 0.0024356297842727903,
      "impulse": 0.22950819269013703,
      "impulse_direction": "bullish",
      "formation_bars": 30
    }
  },
  "events": [
    {
      "pattern": "pennant",
      "state": "confirmed",
      "reason": "breakout-confirmed",
      "pivot_indices": [16, 22, 28, 34, 40, 46],
      "pivot_prices": [125, 115, 123, 116.5, 121, 118],
      "pivot_types": ["high", "low", "high", "low", "high", "low"],
      "candidate_available_index": 48,
      "confirmation_index": 49,
      "breakout_direction": "bullish",
      "expected_direction": "bullish",
      "subtype": null,
      "upper_boundary": 119.5,
      "lower_boundary": 118.375,
      "metrics": {
        "upper_slope": -0.16666666666666666,
        "lower_slope": 0.125,
        "upper_relative_slope": -0.0013917884481558802,
        "lower_relative_slope": 0.0010438413361169101,
        "upper_intercept": 127.66666666666667,
        "lower_intercept": 112.25,
        "width_start": 10.75,
        "width_end": 2,
        "convergence": 0.813953488372093,
        "parallel_gap": 0.0024356297842727903,
        "impulse": 0.22950819269013703,
        "impulse_direction": "bullish",
        "formation_bars": 30
      }
    }
  ],
  "pivots": [
    {
      "kind": "high",
      "index": 16,
      "confirmation_index": 18,
      "price": 125
    },
    {
      "kind": "low",
      "index": 22,
      "confirmation_index": 24,
      "price": 115
    },
    {
      "kind": "high",
      "index": 28,
      "confirmation_index": 30,
      "price": 123
    }
  ],
  "parameters": {
    "pivot_left": 2,
    "pivot_right": 2,
    "pivots_per_side": 3,
    "max_pattern_bars": 44,
    "max_confirmation_bars": 4,
    "impulse_lookback": 12,
    "flat_tolerance": 0.00045,
    "min_slope": 0.00022,
    "parallel_tolerance": 0.00035,
    "min_convergence": 0.18,
    "min_impulse": 0.055,
    "break_buffer": 0.001
  }
}

Other exports#

This module also exports tracePennant. Every module additionally exports run as an alias of its primary function, and a meta object carrying its catalog id, domain, family, shape and article URL.

Diagrams#

Pennant — algorithm anatomy
Pennant — article hero
Pennant — calculation ledger
Pennant — causal timeline
Pennant — failure boundary
Pennant — method comparison

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

The rest of the Continuation Structures family#