
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
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()
