Advertisement
mmyjh86

[러닝-스크래핑5기] 백테스팅 - 콤보전략

May 11th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. import pandas as pd
  2. import os
  3.  
  4. def 월간수익률(파일, 투자종목수):
  5.     df = pd.read_excel("per/" + 파일, dtype={'티커':str})
  6.     df = df.set_index('티커')
  7.            
  8.     cond = (df["PER"] != 0) & (df["PBR"] != 0) & (df["PBR"] < 0.5) & (df["DIV"] > 0)
  9.     정렬 = df[cond].sort_values(["PER"])    
  10.     투자종목 = 정렬.iloc[:투자종목수]
  11.    
  12.     if len(투자종목) == 0:
  13.         return 1
  14.    
  15.     df = pd.read_excel("price/" + 파일, dtype={'티커':str})
  16.     df = df.set_index('티커')
  17.    
  18.     수익률 = df.loc[투자종목.index]['등락률']    
  19.     return 1 + (수익률.sum() / len(투자종목) / 100)
  20.  
  21. 누적수익률 = 1
  22. 파일리스트 = os.listdir("per")
  23. for 변수 in 파일리스트:
  24.     수익률 = 월간수익률(변수, 20)    
  25.     누적수익률 = 누적수익률 * 수익률
  26.     print(변수[:8], 수익률, 누적수익률)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement