전략과 구매 및 보유 수익 사이의 시각적 비교

저자:차오장, 날짜: 2024-01-05 15:27:26
태그:

img

전반적인 설명

이 전략은 주어진 전략과 거래된 증권의 구매 및 보유 수익을 상세하고 시각적으로 비교합니다.

전략 논리

이 전략의 핵심 논리는 주어진 전략과 구매 및 보유 전략의 비교를 위해 네 가지 핵심 요소를 계획하는 것입니다.

  1. 전략 P/L: 전략 순이익 + 전략 오픈이익
  2. 구매 및 보유 수익/손실: 실현되지 않은 수익
  3. 차이점: 전략 P/L - 구매 & 보유 P/L
  4. 전략 대 구매 보유 통계
    • 바 전략 P / L의 비율은 구매 및 보유 이상입니다
    • 바 전략 P / L의 비율은 구매 & 보유 하에 있습니다
    • 모든 시간 평균 차이

위의 네 가지 요소를 비교함으로써 우리의 전략이 간단한 구매 및 보유 전략을 능가하거나 저하하는지 직관적으로 이해할 수 있습니다.

이점 분석

구매 및 보유 수익률의 간단한 비교와 비교하면 이 전략은 다음과 같은 장점을 가지고 있습니다.

  1. 더 포괄적이고 상세한 비교 메트릭, 바별 비교 및 전체 통계 비교를 포함하여, 우리의 전략이 언제 어디서 타거나 잃는지 명확하게 알 수 있습니다.

  2. 직관적인 시각 차트 전략 P / L, 구매 & 보유 P / L 및 그 사이의 차이를 그래프. 그것은 우리가 시각적으로 우리의 전략의 성능을 더 빨리 말할 수 있습니다.

  3. 맞춤형 비교 날짜 범위에서 우리는 특정 기간에 우리의 전략 vs 구매 & 보유 비교에 집중할 수 있습니다.

  4. 간단하고 사용하기 쉽습니다. 비교 논리는 내장되어 있습니다. 그래서 우리는 전략 스크립트 섹션을 우리의 것으로 교체 할 필요가 있습니다. 비교 논리를 직접 코딩 할 필요가 없습니다.

위험 분석

이 전략은 주로 비교를 위해 거래 플랫폼의 내장된 구매 및 보유 수익 메트릭에 의존합니다. 해당 벤치마크에 대한 모든 편차는 최종 결과에 영향을 줄 것입니다. 또한이 전략의 통계 계산에 오류가있을 수 있으며 비교를 정확하게 반영하지 못합니다.

추가 검증을 위해 더 많은 벤치마크와 통계적 방법을 도입 할 수 있습니다. 거래 플랫폼이 구매 및 보유 메트릭에 중대한 변화를 도입하면 비교 논리 또한 조정해야합니다.

최적화 방향

이 전략은 다음 측면에서 더 이상 최적화 될 수 있습니다.

  1. 3방향 또는 다방향 비교를 위한 더 많은 벤치마크를 도입합니다. 예를 들어 지수 또는 업계 동료에 대한 비교입니다.

  2. 더 많은 차원에서 전략을 평가하기 위해 연간 승률, 최대 마감 기간 차이 등과 같은 더 많은 통계 메트릭을 포함하십시오.

  3. 벤치마크, 메트릭 등과 같은 더 많은 구성 요소를 사용자에 의해 사용자 정의 할 수 있도록 설정하십시오.

  4. 간단한 직선 차트에서 특정 바에 대한 상세한 비교를 발견하는 것이 어렵기 때문에 차트 시각화를 개선하십시오. 컬럼 그래프 또는 추가 표시가 도움이 될 수 있습니다.

결론

상세한 비교 메트릭과 직관적인 시각 차트를 통해 이 전략은 우리의 사용자 지정 전략이 간단한 바이 앤 홀드 접근 방식과 어디에서 어떻게 다른지 매우 명확하게 볼 수 있습니다. 사용자 지정 가능한 날짜 범위는 또한 다른 기간에 우리의 전략의 장단점을 분석하는 유연성을 제공합니다.

벤치마크, 메트릭 및 시각화를 더욱 풍부하게 함으로써 이것은 전략 분석을 위한 매우 강력한 툴킷으로 변할 수 있습니다. 전략 분석과 개선을 훨씬 효율적으로 만들기 위한 템플릿과 프레임워크를 제공합니다.


/*backtest
start: 2023-12-28 00:00:00
end: 2024-01-04 00:00:00
period: 3m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("VS Buy Hold", precision=2)

bnh_info_panel = input(true, title='Enable Info Panel')
bnh_indicator_panel = input(true, title='Enable Indicator Panel')

//COMPARISON DATE RANGE//
bnh_FromYear = input(1970, title="From Year", minval=1970)
bnh_FromMonth = input(1, title="From Month", minval=1, maxval=12)
bnh_FromDay = input(1, title="From Day", minval=1, maxval=31)

bnh_ToYear = input(2050, title="To Year", minval=2010)
bnh_ToMonth = input(12, title="To Month", minval=1, maxval=12)
bnh_ToDay = input(31, title="To Day", minval=1, maxval=31)

bnh_start = timestamp(bnh_FromYear, bnh_FromMonth, bnh_FromDay, 00, 00)
bnh_finish = timestamp(bnh_ToYear, bnh_ToMonth, bnh_ToDay, 23, 59)
bnh_timeCond = time >= bnh_start and time <= bnh_finish ? true: false
    
//Note: If you are going to use the COMPARISON DATE RANGE above, apply bnh_timeCond
//      to your strategy parameters.


/////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////STRATEGY SCRIPT START//////////////////////////////////

//=========================PLACEHOLDER MA CROSS STRATEGY=========================//
fastLength = 50
slowLength = 200
price = close

mafast = sma(price, fastLength)
maslow = sma(price, slowLength)
strategy.initial_capital = 50000
positionSize = strategy.initial_capital / close

if (crossover(mafast, maslow) and bnh_timeCond) // <= bnh_timeCond added as a condition
    strategy.entry("MA2CrossLE", strategy.long, positionSize, comment="MA2CrossLE")

if (crossunder(mafast, maslow) and bnh_timeCond) // <= bnh_timeCond added as a condition
    strategy.entry("MA2CrossSE", strategy.short, positionSize, comment="MA2CrossSE")

//////////////////////////////STRATEGY SCRIPT END////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////



//STRATEGY EQUITY
strategy_pnl = strategy.netprofit + strategy.openprofit
bnh_strategy_pnl_pcnt = (strategy_pnl / strategy.initial_capital) * 100


//BUY AND HOLD EQUITY
float bnh_start_bar = na
bnh_start_bar := na(bnh_start_bar[1]) and bnh_timeCond? close : bnh_start_bar[1]
bnl_buy_hold_equity = ((close - bnh_start_bar)/bnh_start_bar) * 100


//STRATEGY VS BUY AND HOLD STATS
bnh_vs_diff = bnh_strategy_pnl_pcnt - bnl_buy_hold_equity

bnh_bar_counter = 0
bnh_bar_counter := bnh_vs_diff > 0 ? nz(bnh_bar_counter[1]) + 1 : bnh_bar_counter[1]

bnh_bar_counter2 = 0
bnh_bar_counter2 := bnh_vs_diff <= 0 ? nz(bnh_bar_counter2[1]) + 1 : bnh_bar_counter2[1]

bnh_pcnt_above = (bnh_bar_counter/(bnh_bar_counter + bnh_bar_counter2))*100
bnh_pcnt_below = (bnh_bar_counter2/(bnh_bar_counter + bnh_bar_counter2))*100

bnh_average_diff = cum(bnh_vs_diff) / (bnh_bar_counter + bnh_bar_counter2)


//PLOTS AND LABELS
bnh_diff_color = bnh_vs_diff > 0 ? color.green : color.red
plot(bnh_vs_diff, style=plot.style_columns, color=bnh_diff_color, transp=60, title='SvB')
plot(bnh_strategy_pnl_pcnt, color=color.yellow, linewidth=2, title="SR")
plot(bnl_buy_hold_equity, color=color.blue, title="BHR")

// draw_IndicatorLabel(_text, _x, _y, label_color, font_color)=>
//     string_text = _text
//     var label la_indicator = na
//     label.delete(la_indicator)
//     la_indicator := label.new(
//          x=_x, y=_y, 
//          text=string_text, xloc=xloc.bar_index, yloc=yloc.price, 
//          color=label_color, style=label.style_labeldown, textcolor=font_color, size=size.small)

// draw_InfoPanel(_text, _x, _y, font_size)=>
//     var label la_panel = na
//     label.delete(la_panel)
//     la_panel := label.new(
//          x=_x, y=_y, 
//          text=_text, xloc=xloc.bar_time, yloc=yloc.price, 
//          color=color.new(#383838, 5), style=label.style_labelup, textcolor=color.white, size=font_size)

// if bnh_indicator_panel         
//     draw_IndicatorLabel("Difference", bar_index, bnh_vs_diff, color.new(color.gray, 40), color.white)
//     draw_IndicatorLabel("Strategy P/L", bar_index, bnh_strategy_pnl_pcnt, color.new(color.yellow, 50), color.white)
//     draw_IndicatorLabel("Buy & Hold P/L", bar_index, bnl_buy_hold_equity, color.new(color.blue, 50), color.white)

// info_panel_x = time_close + round(change(time) * 200)
// info_panel_y = max(max(bnl_buy_hold_equity, bnh_strategy_pnl_pcnt), bnh_vs_diff) + abs(bnh_vs_diff * 0.25)


// title = "STRATEGY vs BUY & HOLD STATS"
// row0 = "-----------------------------------------------------"
// row1 = 'Bars Above Buy & Hold: ' + tostring(bnh_pcnt_above, '#.##') + '%'
// row2 = 'Bars Below Buy & Hold: ' + tostring(bnh_pcnt_below, '#.##') + '%'
// row3 = 'All Time Ave. Difference: ' + tostring(bnh_average_diff, '#.##') + '%'

// panel_text = '\n' + title + '\n' + row0 + '\n' + row1 + '\n\n' + row2 + '\n\n' + row3 + '\n'

// if bnh_info_panel
//     draw_InfoPanel(panel_text, info_panel_x, info_panel_y, size.normal)



더 많은