Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import os
- def 월간수익률(파일, 투자종목수):
- df = pd.read_excel("per/" + 파일, dtype={'티커':str})
- df = df.set_index('티커')
- cond = (df["PER"] != 0) & (df["PBR"] != 0) & (df["PBR"] < 0.5) & (df["DIV"] > 0)
- 정렬 = df[cond].sort_values(["PER"])
- 투자종목 = 정렬.iloc[:투자종목수]
- if len(투자종목) == 0:
- return 1
- df = pd.read_excel("price/" + 파일, dtype={'티커':str})
- df = df.set_index('티커')
- 수익률 = df.loc[투자종목.index]['등락률']
- return 1 + (수익률.sum() / len(투자종목) / 100)
- 누적수익률 = 1
- 파일리스트 = os.listdir("per")
- for 변수 in 파일리스트:
- 수익률 = 월간수익률(변수, 20)
- 누적수익률 = 누적수익률 * 수익률
- print(변수[:8], 수익률, 누적수익률)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement