
이 전략은 선형 회귀 기술을 사용하여 선형 회귀 차단점을 계산하고 그것을 구매/판매 신호로 사용하여 양적 거래 전략을 구축한다. 이 전략은 주식 가격의 시간 순서를 분석하여 선형 회귀 트렌드 라인을 조립하고, 선형 회귀 차단점을 사용하여 가격이 과대 평가되거나 과소 평가되었는지 판단하여 신호 거래를 생성한다.
선형 회귀 차단점은 시간 시리즈 X값이 0일 때 Y값 (일반적으로 가격) 의 예측값을 나타냅니다. 이 전략은 종결값을 소스 서열로 사용하여 Langth 파라미터를 미리 설정하여 가장 최근의 Length 날의 선형 회귀 차단점을 계산합니다. 종결값이 xLRI보다 높을 때 더하고, 종결값이 xLRI보다 낮을 때 공백합니다.
구체적인 계산 공식은 다음과 같습니다:
xX = Length *(Length - 1)* 0.5
xDivisor = xX *xX - Length* Length *(Length - 1) *(2 * Length - 1) / 6
xXY = Σ(i *收盘价[i]),i从0到Length-1
xSlope = (Length *xXY - xX* Σ(收盘价, Length))/ xDivisor
xLRI = (Σ(收盘价, Length) - xSlope * xX) / Length
이러한 계산을 통해, 가장 최근의 트일 (Length day) 의 선형 회귀 차단점 xLRI를 얻을 수 있다. 전략은 가격의 상승과 하락을 판단하여 거래 신호를 생성한다.
이 전략은 다음과 같은 장점을 가지고 있습니다.
이 전략에는 몇 가지 위험도 있습니다.
대책:
이 정책은 다음과 같은 부분에서 최적화 될 수 있습니다.
이 전략은 선형 회귀 차단점을 기반으로 간단한 양적 거래 전략을 구축한다. 전반적으로 이 전략은 경제적 가치가 있지만 주의해야 할 위험도 있다. 지속적인 최적화를 통해 전략의 안정성과 수익성을 더욱 높일 수 있다.
/*backtest
start: 2023-11-28 00:00:00
end: 2023-12-28 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 21/03/2018
// Linear Regression Intercept is one of the indicators calculated by using the
// Linear Regression technique. Linear regression indicates the value of the Y
// (generally the price) when the value of X (the time series) is 0. Linear
// Regression Intercept is used along with the Linear Regression Slope to create
// the Linear Regression Line. The Linear Regression Intercept along with the Slope
// creates the Regression line.
//
// You can change long to short in the Input Settings
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
strategy(title="Line Regression Intercept Backtest", overlay = true)
Length = input(14, minval=1)
xSeria = input(title="Source", defval=close)
reverse = input(false, title="Trade reverse")
xX = Length * (Length - 1) * 0.5
xDivisor = xX * xX - Length * Length * (Length - 1) * (2 * Length - 1) / 6
xXY = 0
for i = 0 to Length-1
xXY := xXY + (i * xSeria[i])
xSlope = (Length * xXY - xX * sum(xSeria, Length)) / xDivisor
xLRI = (sum(xSeria, Length) - xSlope * xX) / Length
pos = iff(close > xLRI, 1,
iff(close < xLRI, -1, nz(pos[1], 0)))
possig = iff(reverse and pos == 1, -1,
iff(reverse and pos == -1, 1, pos))
if (possig == 1)
strategy.entry("Long", strategy.long)
if (possig == -1)
strategy.entry("Short", strategy.short)
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
plot(xLRI, color=blue, title="LRI")