커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
get_return 값이 변수를 달리 했는데도 바뀌지 않네요 뭐가 잘못됐는지 봐주시겠어요~
undefined주차
북마크
전*호
댓글
1
추천
0
조회수
5
조회수
5
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.








작성한 코드 및 에러 메세지

def get_return(code,n):

  df=fdr.DataReader(code,'2018')

  df=df[['Close']].copy()

  df['ma']=df.rolling(n).mean().shift(1)

  df['action']=np.where(df['Close']>df['ma'],'buy','sell')

  df.iloc[-1,-1]='sell'


  cond1= (df['action'] == 'buy') & (df['action'].shift(1)=='sell')

  cond2= (df['action'] == 'sell') & (df['action'].shift(1)=='buy')


  df_buy = df[cond1].reset_index()

  df_buy.columns = ['날짜', '종가(buy)','이평값','액션']

  df_sell = df[cond2].reset_index()

  df_sell.columns = ['날짜', '종가(sell)','이평값','액션']

  df.result = pd.concat([df_buy,df_sell],axis=1)


  df_result['수익률'] = df_result['종가(sell)']/df_result['종가(buy)']

  return df_result[['수익률']].cumprod().iloc[-1,-1] - 1


get_return('005930',3)

<ipython-input-22-c24c16386715>:15: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  df.result = pd.concat([df_buy,df_sell],axis=1)
0.20833942432949182

get_return('066570',3)

<ipython-input-22-c24c16386715>:15: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  df.result = pd.concat([df_buy,df_sell],axis=1)
0.20833942432949182




취소
 공유
취소
댓글 0
댓글 알림
나의얼굴