커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
df_sell
undefined주차
북마크
맹*영
댓글
9
추천
0
조회수
27
조회수
27
답변 완료

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

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


4주차 4-6 강의 자료와 똑같이 코드를 했는데 df_sell 부분에서 어떤 이유인지

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

이 조건이 마지막줄게 적용이 안됩니


스파르타 즉문즉답스파르타 즉문즉답스파르타 즉문즉답




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


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

#rolling(n): use n values for something

#shift(n): shift n times

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

#where: if statement

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


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

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


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

print(df)

df_buy=df[cond1].reset_index()

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


df_sell=df[cond2].reset_index()

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

print(df_sell)

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


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


df_result.tail()



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