할로윈 투자 전략

jh_k·2023년 2월 7일
0

투자전략

목록 보기
5/7

할로윈 투자 전략

  1. 11월 1일에 구매 -> 6개월동안 유지 4월 말일에 판매
  2. 11월 첫날 시가로 구매
  3. 4월 마지막날 종가로 판매
  4. 수익율 = (3번과정 - 2번과정) / 2번과정
  5. 투자 기간이 21년 누적 수익율 계산
  6. CAGR(연복리수익율) 계산
  7. MDD(Max DrawDown)
  8. 백테스팅
import pandas as pd
kospi = pd.read_excel("./kospi.xlsx",engine='openpyxl',index_col=0)
acc_rtn = 1

for year in range(2000,2021):
    buy_mon = str(year)+"-11"
    sell_mon = str(year+1) + "-04"

    #매수가 지정
    buy = kospi.loc[buy_mon].iloc[0]['Open']
    #매도가 지정
    sell = kospi.loc[sell_mon].iloc[-1]['Close']
    
    # 수익율 (매도가/매수가)
    rtn = sell / buy
    # 누적 수익율 계산 
    acc_rtn *=rtn 
    
acc_rtn
## CAGR 계산
##  (수익율 **(1/투자기간))-1  
CAGR = (acc_rtn ** (1/21))-1
CAGR*100
## buy and hold 의 수익율
# 매수가
buy = kospi.iloc[0]["Open"]
# 매도가
sell = kospi.iloc[-1]["Close"]

# 수익율
rtn = sell/buy
rtn
## 바이앤 홀드 CAGR
BAH_CAGR = (rtn **(1/21))-1
BAH_CAGR*100

백테스팅

import datetime
from dateutil.relativedelta import relativedelta
start = datetime.datetime(year=2000,month=11,day=1)
end = start + relativedelta(months=5)
def six_month(df,start_year=2000,end_year=2020,month=11):
    # 누적 수익율 초기값
    acc_rtn = 1
    
    # 반복문을 이용하여 누적수익율 계산
    for year in range(start_year,end_year):
        start = datetime.datetime(year=year,month=month,day=1)
        end = start + relativedelta(months=5)

        buy_mon = start.strftime("%Y-%m")
        sell_mon = end.strftime("%Y-%m")

        # 구매가
        buy = df.loc[buy_mon].iloc[0]["Open"]
        #  판매가
        sell = df.loc[sell_mon].iloc[-1]["Close"]

        # 수익율
        rtn = sell / buy
        #누적 수익율
        acc_rtn *= rtn
    
    return acc_rtn
six_month(kospi,2000,2021,11)
### 6.18585306815823

월별 수익률의 차이 확인

for month in range(1,13):
    result = six_month(kospi,2000,2021,month)
    print(f"{month} -> {result:0.2f}")

11월 매수의 수익률이 가장 높은것으로 확인됨
1 -> 1.64
2 -> 1.72
3 -> 1.64
4 -> 1.45
5 -> 0.64
6 -> 1.16
7 -> 1.65
8 -> 1.81
9 -> 2.03
10 -> 2.50
11 -> 6.19
12 -> 3.68

profile
Just Enjoy Yourself

0개의 댓글