세이프 RSI (RSI_SAFE)
검증된 StratForge C++23 API, 계산 및 준비 기간.
Route: /indicators/rsi_safe/
안전 나눗셈은 평균 손실이 0인 경우를 처리합니다. 가격과 RSI의 다이버전스를 탐지하지 않습니다. 기본 안전값에서 출력은 0–100 RSI 값이며 수익률이 아닙니다.
change = close[t] - close[t - lookback]
gain = max(change, 0); loss = max(-change, 0)
average[t] = (average[t - 1] * (period - 1) + value[t]) / period
RS = average_gain / average_loss; RSI = 100 - 100 / (1 + RS)
매개변수
period = 14movav = stratforge::RsiMovAv::Smoothed(Simple,Exponential)safehigh = 100.0safelow = 50.0lookback = 1
RSI_Safe: safediv = true; RSI: safediv = false.
upperband / lowerband: 70 / 30 — 차트 기준값이며 생성자 인수가 아닙니다.
계산 예시
period = 3, lookback = 1, 종가 [10, 11, 10, 11, 13]의 변화는 [1, -1, 1, 2]입니다. 초기 평균 상승 2/3, 평균 하락 1/3이므로 4번째 봉 RSI = 66.666667입니다. 5번째 봉은 평활 평균 상승 10/9, 하락 2/9로 RSI = 83.333333입니다. 처음 3개 봉은 NaN입니다. 준비 기간은 period + lookback이며 기본값은 15개 봉입니다.
기본 안전값에서 손실 없는 상승은 100, 상승 없는 하락은 0, 평탄한 시계열(0/0)은 50입니다. 준비 기간 이후에만 적용됩니다. safehigh/safelow는 분모가 0일 때의 RSI 결과값이며 분모 보정값이 아닙니다.
유한한 가격과 양수 기간 및 lookback을 사용하세요. 이 버전은 0을 1로 정규화합니다. 사용자 안전값을 검증하지 않으며 비유한 가격의 의미 있는 결과를 보장하지 않습니다. 계산 예시는 매매 신호나 수익 증거가 아닙니다.
C++23 API — StratForge
#include <stratforge/indicators/rsi.hpp>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
int main() {
stratforge::Line<double> close, rising, falling, flat;
stratforge::RSI_Safe rsi(close, 3);
stratforge::RSI_Safe up(rising, 3), down(falling, 3), neutral(flat, 3);
assert(rsi.minimum_period() == 4);
std::cout << std::fixed << std::setprecision(6);
for (double price : {10.0, 11.0, 10.0, 11.0, 13.0}) {
close.forward(price);
rsi.next();
if (close.size() < 4) assert(std::isnan(rsi[0]));
else std::cout << rsi[0] << " ";
}
assert(std::abs(rsi.line()[-1] - 66.666666667) < 1e-9);
assert(std::abs(rsi[0] - 83.333333333) < 1e-9);
for (int i = 0; i < 4; ++i) {
rising.forward(10.0 + i);
falling.forward(10.0 - i);
flat.forward(10.0);
up.next();
down.next();
neutral.next();
}
assert(up[0] == 100.0 && down[0] == 0.0 && neutral[0] == 50.0);
std::cout << up[0] << " " << down[0] << " " << neutral[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:
66.666667 83.333333 100.000000 0.000000 50.000000
