라이브러리
[PHP] trader_stochrsi - 확률적 상대 강도 지수
트레이딩 기술: Stochastic RSI (StochRSI)
Stochastic RSI (StochRSI)는 기술적 분석에서 사용되는 지표로, 가격 변동의 강도와 가격의 추세를 측정하는 데 사용됩니다. StochRSI는 Stochastic Oscillator와 Relative Strength Index (RSI) 두 가지 지표를 결합한 것입니다.
Stochastic Oscillator
Stochastic Oscillator는 가격의 변동을 0에서 100 사이의 범위로 변환하여 가격의 추세를 측정하는 지표입니다. Stochastic Oscillator는 14일 이동 평균을 사용하여 계산됩니다.
Relative Strength Index (RSI)
RSI는 가격의 변동을 측정하는 지표로, 0에서 100 사이의 범위로 변환됩니다. RSI는 14일 이동 평균을 사용하여 계산됩니다.
Stochastic RSI
StochRSI는 Stochastic Oscillator와 RSI를 결합한 지표로, 가격의 추세와 변동을 측정하는 데 사용됩니다. StochRSI는 14일 이동 평균을 사용하여 계산됩니다.
StochRSI의 계산
StochRSI의 계산은 다음과 같습니다.
1. RSI를 계산합니다.
2. Stochastic Oscillator를 계산합니다.
3. Stochastic Oscillator와 RSI를 결합하여 StochRSI를 계산합니다.
StochRSI의 의미
StochRSI의 의미는 다음과 같습니다.
* Overbought: StochRSI가 80 이상이면, 가격이 과매수 상태입니다.
* Oversold: StochRSI가 20 이하이면, 가격이 과매도 상태입니다.
* Buy Signal: StochRSI가 20 이하에서 상승하는 경우, 매수 신호가 발생합니다.
* Sell Signal: StochRSI가 80 이상에서 하락하는 경우, 매도 신호가 발생합니다.
PHP 예제
PHP에서 StochRSI를 계산하는 예제는 다음과 같습니다.
#hostingforum.kr
php
<?php
// 데이터를 입력합니다.
$data = array(
array('날짜', '가격'),
array('2022-01-01', 100),
array('2022-01-02', 120),
array('2022-01-03', 110),
array('2022-01-04', 130),
array('2022-01-05', 140),
array('2022-01-06', 150),
array('2022-01-07', 160),
array('2022-01-08', 170),
array('2022-01-09', 180),
array('2022-01-10', 190),
array('2022-01-11', 200),
array('2022-01-12', 210),
array('2022-01-13', 220),
array('2022-01-14', 230),
);
// RSI를 계산합니다.
function rsi($data, $n) {
$rsi = array();
for ($i = 0; $i < count($data); $i++) {
if ($i < $n) {
$rsi[] = null;
} else {
$gain = array();
$loss = array();
for ($j = $i - $n + 1; $j <= $i; $j++) {
if ($data[$j][1] > $data[$j - 1][1]) {
$gain[] = $data[$j][1] - $data[$j - 1][1];
} elseif ($data[$j][1] < $data[$j - 1][1]) {
$loss[] = $data[$j - 1][1] - $data[$j][1];
}
}
$avg_gain = array_sum($gain) / count($gain);
$avg_loss = array_sum($loss) / count($loss);
$rs = $avg_gain / $avg_loss;
$rsi[] = 100 - (100 / (1 + $rs));
}
}
return $rsi;
}
// Stochastic Oscillator를 계산합니다.
function stochastic_oscillator($data, $n) {
$stochastic_oscillator = array();
for ($i = 0; $i < count($data); $i++) {
if ($i < $n) {
$stochastic_oscillator[] = null;
} else {
$low = min(array_slice($data, $i - $n + 1, $n));
$high = max(array_slice($data, $i - $n + 1, $n));
$k = (($data[$i][1] - $low) / ($high - $low)) * 100;
$stochastic_oscillator[] = $k;
}
}
return $stochastic_oscillator;
}
// StochRSI를 계산합니다.
function stochrsi($data, $n) {
$rsi = rsi($data, $n);
$stochastic_oscillator = stochastic_oscillator($data, $n);
$stochrsi = array();
for ($i = 0; $i < count($data); $i++) {
if ($i < $n) {
$stochrsi[] = null;
} else {
$stochrsi[] = $stochastic_oscillator[$i] * $rsi[$i];
}
}
return $stochrsi;
}
// 데이터를 입력합니다.
$data = array(
array('날짜', '가격'),
array('2022-01-01', 100),
array('2022-01-02', 120),
array('2022-01-03', 110),
array('2022-01-04', 130),
array('2022-01-05', 140),
array('2022-01-06', 150),
array('2022-01-07', 160),
array('2022-01-08', 170),
array('2022-01-09', 180),
array('2022-01-10', 190),
array('2022-01-11', 200),
array('2022-01-12', 210),
array('2022-01-13', 220),
array('2022-01-14', 230),
);
// StochRSI를 계산합니다.
$stochrsi = stochrsi($data, 14);
// 결과를 출력합니다.
for ($i = 0; $i < count($data); $i++) {
echo $data[$i][0] . ' ' . $data[$i][1] . ' ' . $stochrsi[$i] . "
";
}
이 예제에서는 StochRSI를 계산하는 함수를 정의하고, 데이터를 입력하여 StochRSI를 계산한 후 결과를 출력합니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.