Advertisement
mmyjh86

[YouTube] 벡테스팅 - 주간매매

Oct 3rd, 2020
1,913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. from pykrx import stock
  2.  
  3. # 2018 - 2020 코스피 기간 수익률
  4. df = stock.get_index_ohlcv_by_date("20180101", "20200831", "1001")
  5. temp = df['종가']
  6. for i in range(0, 5):
  7.     result = temp.shift( i ).resample('W').agg( [ 'first', 'last' ] )
  8.     수익률 = result['last'] / result['first'] - 0.002
  9.     print(i, 수익률.cumprod().iloc[-1])
  10. print("-" * 30)
  11.  
  12. # 2019 - 2020 코스피 기간 수익률
  13. df = stock.get_index_ohlcv_by_date("20180101", "20200831", "1001")
  14. temp = df['종가']
  15. for i in range(0, 5):
  16.     result = temp.shift( i ).resample('W').agg( [ 'first', 'last' ] )
  17.     수익률 = result['last'] / result['first'] - 0.002
  18.     print(i, 수익률.cumprod().iloc[-1])
  19. print("-" * 30)
  20.  
  21. # 2019 - 2020 코스닥 기간 수익률
  22. df = stock.get_index_ohlcv_by_date("20190101", "20200831", "2001")
  23. temp = df['종가']
  24. for i in range(0, 5):
  25.     result = temp.shift( i ).resample('W').agg( [ 'first', 'last' ] )
  26.     수익률 = result['last'] / result['first'] - 0.002
  27.     print(i, 수익률.cumprod().iloc[-1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement