trading.indicators.calculations.bollinger_bands
trading.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(period: 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 |
|---|---|---|---|
period
|
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\trading\indicators\calculations\bollinger_bands.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
update
update(price: USD) -> 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 |
|---|---|---|---|
price
|
USD
|
The price for the current bar. |
required |
Returns:
| Type | Description |
|---|---|
BollingerBandSnapshot | None
|
A BollingerBandSnapshot(upper, middle, lower), or None until |
BollingerBandSnapshot | None
|
|
Source code in src\contango\trading\indicators\calculations\bollinger_bands.py
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |