볼린저 밴드 (BBANDS)
검증된 StratForge C++23 API, 계산 및 준비 기간.
Route: /indicators/bbands/
단순 이동평균과 모집단 표준편차를 사용합니다(n으로 나누며 n - 1이 아님). 세 밴드의 단위는 입력 가격과 같습니다. 이 생성자에는 movav 옵션이 없습니다.
mid = SMA(period)
top = mid + devfactor * sqrt(sum((price - mid)^2) / period)
bottom = mid - devfactor * sqrt(sum((price - mid)^2) / period)
매개변수
period = 20devfactor = 2.0
계산 예시
period = 4, 가격 [2, 4, 6, 8]의 평균은 5, 편차 제곱은 [9, 1, 1, 9], 분산은 5, 표준편차는 sqrt(5)입니다. devfactor = 2일 때 mid = 5, top = 9.472136, bottom = 0.527864(소수점 6자리). 처음 3개 봉은 NaN이며 4번째부터 유효합니다. 기본 기간은 20개 봉이 필요합니다.
유한한 가격과 양수 기간 및 lookback을 사용하세요. 이 버전은 0을 1로 정규화합니다. 사용자 안전값을 검증하지 않으며 비유한 가격의 의미 있는 결과를 보장하지 않습니다. 계산 예시는 매매 신호나 수익 증거가 아닙니다.
C++23 API — StratForge
#include <stratforge/indicators/bollinger.hpp>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
int main() {
stratforge::Line<double> close;
stratforge::BollingerBands bands(close, 4, 2.0);
assert(bands.minimum_period() == 4);
for (double price : {2.0, 4.0, 6.0, 8.0}) {
close.forward(price);
bands.next();
if (close.size() < 4) {
assert(std::isnan(bands.mid()[0]));
assert(std::isnan(bands.top()[0]));
assert(std::isnan(bands.bottom()[0]));
}
}
assert(std::abs(bands.mid()[0] - 5.0) < 1e-9);
assert(std::abs(bands.top()[0] - 9.472135955) < 1e-9);
assert(std::abs(bands.bottom()[0] - 0.527864045) < 1e-9);
std::cout << std::fixed << std::setprecision(6)
<< bands.mid()[0] << " " << bands.top()[0] << " "
<< bands.bottom()[0] << "\n";
}
재현
StratForge d25404dcf2c3842ba304ddc60ac19cfec1f8aa37 (2026-08-28); GCC 14, C++23; scalar build, no xsimd dependency.
git clone https://github.com/StratCraftsAI/StratForge.git StratForge
git -C StratForge checkout --detach d25404dcf2c3842ba304ddc60ac19cfec1f8aa37
g++-14 -std=c++23 -O2 -Wall -Wextra -pedantic -IStratForge/include example.cpp -o example
./example
example.cpp: C++23 API. stdout:
5.000000 9.472136 0.527864
