mmyjh86

[YouTube] 벡테스팅 - 지수수익률 - 2

Sep 19th, 2020
1,451
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. import os
  3. from pandas import Series
  4.  
  5. def 지수수익률(df):
  6.     기간수익률 = df['종가'][-1]/df['종가'][0]
  7.     N = (df.index[-1] - df.index[0]).days / 365
  8.     return (기간수익률 ** (1/N)) - 1
  9.  
  10. 수익률 = [ ]
  11. for filename in os.listdir():
  12.     if filename.endswith('xlsx'):
  13.         df = pd.read_excel(filename, index_col=0)
  14.         CAGR = 지수수익률(df)
  15.         수익률.append(CAGR)
  16.        
  17. tickers = [ x[6:10] for x in os.listdir() if x.endswith('xlsx')]
  18.  
  19.  
  20. s = Series(수익률, index=tickers)
  21. result = s.sort_values(ascending=False)
  22.  
  23. for t in result.index[:5]:
  24.     print(s.loc[t], stock.get_index_ticker_name(t))
RAW Paste Data