contango.stream.indicators.calculations.bollinger_bands
contango.stream.indicators.calculations.bollinger_bands
BollingerBandSnapshot
Bases: NamedTuple
A single snapshot of Bollinger Bands.
Attributes:
| Name | Type | Description |
|---|---|---|
upper |
float
|
The upper band for the current price. |
middle |
float
|
The middle band (pure SMA) for the current price. |
lower |
float
|
The lower band for the current price. |
stdev |
float
|
The population standard deviation over the lookback window. |
BollingerBands
BollingerBands(pd: days = 20, k: float = 2.0)
Bases: Indicator[BollingerBandSnapshot | None]
Rolling Bollinger Bands with variance updates.
Wraps an SMA and tracks a running sum-of-squares so that standard deviation is recomputed in constant time on every tick. Returns None until the lookback window is full.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pd
|
days
|
Lookback window in bars (default 20). |
20
|
k
|
float
|
Band-width multiplier in standard deviations (default 2.0). |
2.0
|
Source code in src\contango\stream\indicators\calculations\bollinger_bands.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
value
property
value: BollingerBandSnapshot | None
Returns the latest value for the bollinger bands.
update
update(event: MarketDataEvent) -> BollingerBandSnapshot | None
Takes in a new price and return the current bands, or None while the window is still filling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
MarketDataEvent
|
The underlying event to update the bollinger bands indicator with. |
required |
Returns:
| Type | Description |
|---|---|
BollingerBandSnapshot | None
|
A BollingerBandSnapshot(upper, middle, lower), or None until |
BollingerBandSnapshot | None
|
|
Source code in src\contango\stream\indicators\calculations\bollinger_bands.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |