월별 수익률 성과 전략


생성 날짜: 2024-01-08 16:16:58 마지막으로 수정됨: 2024-01-08 16:16:58
복사: 2 클릭수: 388
1
집중하다
1141
수행원

월별 수익률 성과 전략

개요

이 전략의 주요 기능은 매월의 수익성과를 실시간으로 추적하고 표시하는 것입니다. 이 전략은 매월의 구체적인 수익과 손실을 실시간으로 업데이트하는 표입니다.

원칙

이 전략은 다음과 같은 몇 가지 단계를 통해 월간 수익 성과를 추적합니다.

  1. 이 변수는 이달에 거래가 평준화되었는지 기록하는 변수를 정의한다.
  2. 매월 기록된 변수의 구체적인 수익/손실 수치를 정의한다.
  3. 변수를 기록하는 시간을 해당하는 달을 정의한다.
  4. 이달에 평형상태가 있을 때, 이달의 이익과 손실을 이달에 해당하는 배열에 기록한다.
  5. 표의 지정된 위치에 달의 제목을 표시한다.
  6. 매월의 이익과 손실 배열을 가로질러, 표의 해당 달의 열에 이익과 손실 값을 표시한다.
  7. 해당 연도의 정보를 표시합니다.
  8. 연간 영업이익을 종합해보세요.
  9. 색을 사용하여 수익과 손실을 구분하는 양과 음의 차이.

이 전략의 기본 단계와 작동 원리는 다음과 같습니다.

우위 분석

월간 수익/손실 실적을 추적하는 이 전략은 다음과 같은 장점이 있습니다.

  1. 실시간 업데이트, 최신 월간 수익과 손실을 언제든지 확인할 수 있습니다.
  2. 이 표는 한눈에 볼 수 있고, 매월의 수익과 손실을 직관적으로 보여준다.
  3. 매월의 세부사항을 명확하게 볼 수 있습니다.
  4. 직관적인 비교를 위해, 색을 사용하면 매월의 수익과 손실을 더 직관적으로 비교할 수 있습니다.
  5. 대통령회계, 그리고 매년의 이익과 손실의 총합상황을 다.
  6. 사용자 정의 표시, 테이블 위치, 크기 및 기타 표시 방법을 조정할 수 있습니다.

위험 분석

이 전략에는 몇 가지 위험도 있습니다.

  1. 계산 논리는 복잡하고 오류가 발생하여 데이터가 정확하지 않습니다.
  2. 표는 너무 자주 갱신되어서 성능에 영향을 미칠 수 있습니다.
  3. 대렬 데이터 저장 효율이 낮다.
  4. 시간과 달의 변환 계산이 틀릴 수 있습니다.

위험은 다음과 같은 방법으로 줄일 수 있습니다.

  1. 코드가 엄격하게 검토되어 계산 논리가 맞는지 확인합니다.
  2. 탭의 갱신 횟수를 최적화하여 과도한 갱신을 방지하십시오.
  3. 더 효율적인 데이터 구조로 데이터를 저장한다.
  4. 시간을 추가하고 달을 변환하는 특이한 처리가.

전략 최적화

이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.

  1. 더 효율적인 데이터 구조를 사용해서 월별 데이터를 저장하는 사전
  2. 연간 수익률을 증가시키는 계산
  3. 이 지표는 이 증가하고 다른 지표는 증가합니다.
  4. 수익 곡선의 흐름을 시각적으로 보여준다.
  5. 사용자 정의 시작 및 종료 통계 시간대를 지원합니다.
  6. CSV 파일로 데이터를 내보내기 지원한다.

이러한 최적화는 전략의 기능이 더 완벽하고 더 강력해지고, 사용자 경험도 더 좋게 만들 수 있습니다.

요약하다

이 전략은 배열과 표의 방식을 사용하여 매월 수익을 실시간으로 추적하고 표시하는 핵심 기능을 구현한다. 단순하고 효율적이며 사용하기에도 편리하다. 또한 장점이 있지만 예방해야 할 위험이 있습니다. 일부 계산 논리 및 성능의 최적화를 통해이 전략이 더 완벽하고 강력 할 수 있습니다.

전략 소스 코드
/*backtest
start: 2023-01-01 00:00:00
end: 2024-01-07 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MAURYA_ALGO_TRADER

//@version=5
strategy("Monthly Performance", overlay=true)

period = input(20, "Length")

longCondition =   close > high[20]  //ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

shortCondition = close < low[20]  //ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)



// Copy below code to end of the desired strategy script
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                 monthly pnl performance  by Dr. Maurya @MAURYA_ALGO_TRADER                        //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
show_performance = input.bool(true, 'Show Monthly Monthly Performance ?', group='Monthly Performance')

dash_loc_mp = input("Bottom Right","Location"  ,options=["Top Right","Bottom Right","Top Left","Bottom Left", "Middle Right","Bottom Center"]  ,group='Monthly Performance', inline = "performance")

text_size_mp = input('Small',"Size"  ,options=["Tiny","Small","Normal","Large"]  ,group='Monthly Performance', inline = "performance")

var table_position_mp = dash_loc_mp == 'Top Left' ? position.top_left :
  dash_loc_mp == 'Bottom Left' ? position.bottom_left :
  dash_loc_mp == 'Middle Right' ? position.middle_right :
  dash_loc_mp == 'Bottom Center' ? position.bottom_center :
  dash_loc_mp == 'Top Right' ? position.top_right : position.bottom_right
  
var table_text_size_mp = text_size_mp == 'Tiny' ? size.tiny :
  text_size_mp == 'Small' ? size.small :
  text_size_mp == 'Normal' ? size.normal : size.large

/////////////////
text_c = color.white

/////////////////////////////////////////////

// var bool new_month = na
new_month = ta.change(month) //> 0 ? true : false
newest_month = new_month and strategy.closedtrades >= 1
strategy.initial_capital = 50000
// profit
only_profit = strategy.netprofit
initial_balance = strategy.initial_capital

// month number
var int month_number = na
month_number := (ta.valuewhen(newest_month, month(time), 0)) //and month(time) > 1 ? (ta.valuewhen(newest_month, month(time), 0) - 1) :  12 //1 to 12

//month_year
var int month_time = na
month_time := ta.valuewhen(newest_month, time, 0) - 2419200000 


var int m_counter = 0
if newest_month
    m_counter += 1



// current month values
var bool new_year = na
new_year := ta.change(year)
curr_m_pnl = only_profit - nz(ta.valuewhen(newest_month, only_profit, 0), 0)
curr_m_number = newest_month ? ta.valuewhen(newest_month, month(time), 0) : month(time)
curr_y_pnl = (only_profit - nz(ta.valuewhen(new_year, only_profit, 0),0)) 



var float [] net_profit_array = array.new_float()
var int [] month_array = array.new_int()
var int [] month_time_array = array.new_int()


if newest_month
    array.push(net_profit_array, only_profit)
    array.push(month_array, month_number)
    array.push(month_time_array, month_time)



var float [] y_pnl_array = array.new_float()
var int [] y_number_array = array.new_int()
var int [] y_time_array = array.new_int()

newest_year = ta.change(year) and strategy.closedtrades >= 1
get_yearly_pnl = nz(ta.valuewhen(newest_year, strategy.netprofit, 0) - nz(ta.valuewhen(newest_year, strategy.netprofit, 1), 0), 0)
get_m_year = ta.valuewhen(newest_year, year(time), 1)
get_y_time = ta.valuewhen(newest_year, time, 0)

if newest_year
    array.push(y_pnl_array, get_yearly_pnl)
    array.push(y_number_array, get_m_year)
    array.push(y_time_array, get_y_time)
var float monthly_profit = na
var int column_month_number = na
var int row_month_time = na

 


var testTable = table.new(position = table_position_mp, columns = 14, rows = 40, bgcolor = color.rgb(7, 226, 242, 38), border_color = color.white, border_width = 1)
if barstate.islastconfirmedhistory and show_performance
    table.cell(table_id = testTable, column = 0, row = 0, text = "YEAR", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 1, row = 0, text = "JAN", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 2, row = 0, text = "FEB", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 3, row = 0, text = "MAR", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 4, row = 0, text = "APR", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 5, row = 0, text = "MAY", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 6, row = 0, text = "JUN", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 7, row = 0, text = "JUL", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 8, row = 0, text = "AUG", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 9, row = 0, text = "SEP", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 10, row = 0, text = "OCT", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 11, row = 0, text = "NOV", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 12, row = 0, text = "DEC", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 13, row = 0, text = "YEAR P/L", text_color = text_c, text_size=table_text_size_mp)

    for i = 0 to (array.size(y_number_array) == 0 ? na : array.size(y_number_array) - 1)
        row_y = year(array.get(y_time_array, i)) - year(array.get(y_time_array, 0)) + 1
        table.cell(table_id = testTable, column = 13, row = row_y, text = str.tostring(array.get(y_pnl_array , i), "##.##") + '\n' + '(' + str.tostring(array.get(y_pnl_array , i)*100/initial_balance, "##.##") + ' %)', bgcolor = array.get(y_pnl_array , i) > 0 ? color.green : array.get(y_pnl_array , i) < 0 ? color.red : color.gray, text_color = color.rgb(0, 0, 0), text_size=table_text_size_mp)
    curr_row_y = array.size(month_time_array) == 0 ? 1 : (year(array.get(month_time_array, array.size(month_time_array) - 1))) - (year(array.get(month_time_array, 0))) + 1
    table.cell(table_id = testTable, column = 13, row = curr_row_y, text = str.tostring(curr_y_pnl, "##.##") + '\n' + '(' + str.tostring(curr_y_pnl*100/initial_balance, "##.##") + ' %)', bgcolor = curr_y_pnl > 0 ? color.green : curr_y_pnl < 0 ? color.red : color.gray, text_color = color.rgb(0, 0, 0), text_size=table_text_size_mp)
    

    for i = 0 to (array.size(net_profit_array) == 0 ? na : array.size(net_profit_array) - 1)
        monthly_profit := i > 0 ? ( array.get(net_profit_array, i) - array.get(net_profit_array, i - 1) ) : array.get(net_profit_array, i) 
        column_month_number := month(array.get(month_time_array, i)) 
        row_month_time :=((year(array.get(month_time_array, i))) - year(array.get(month_time_array, 0)) ) + 1 
        table.cell(table_id = testTable, column = column_month_number, row = row_month_time, text = str.tostring(monthly_profit, "##.##") + '\n' + '(' + str.tostring(monthly_profit*100/initial_balance, "##.##") + ' %)', bgcolor = monthly_profit > 0 ? color.green : monthly_profit < 0 ? color.red : color.gray, text_color = text_c, text_size=table_text_size_mp)
        table.cell(table_id = testTable, column = 0, row =row_month_time, text = str.tostring(year(array.get(month_time_array, i)), "##.##"), text_color = text_c, text_size=table_text_size_mp)
       
    curr_row_m = array.size(month_time_array) == 0 ? 1 : (year(array.get(month_time_array, array.size(month_time_array) - 1))) - (year(array.get(month_time_array, 0))) + 1
    table.cell(table_id = testTable, column = curr_m_number, row = curr_row_m, text = str.tostring(curr_m_pnl, "##.##") + '\n' + '(' + str.tostring(curr_m_pnl*100/initial_balance, "##.##") + ' %)', bgcolor = curr_m_pnl > 0 ? color.green : curr_m_pnl < 0 ? color.red : color.gray, text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 0, row =curr_row_m, text = str.tostring(year(time), "##.##"), text_color = text_c, text_size=table_text_size_mp)

//============================================================================================================================================================================