
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
죄송해요 print 했는데도 이해가 안되어요 ㅠㅠㅠ
import FinanceDataReader as fdr
import pandas as pd
df = fdr.DataReader('005930')
df=df[['Close','High','Low']]
df['Buy_amount'] = [0] * len(df)
now = '2007-03-16' #기준을 정한날
df['Buy_amount'] = [0] * len(df)
df['Once_buy_money'] = [0] * len(df)
df['Boyu_amount'] = [0] * len(df)
df['Sell_amount'] = [0] * len(df)
df['Sell_prices'] = [0] * len(df)
df['Total_sell_prices'] = [0] * len(df)
df['Total_tuip'] = [0] * len(df)
df['Peongdanga'] = [0] * len(df)
df['Peonggageumek'] = [0] * len(df)
df['suikgeum'] = [0] * len(df)
df['suikyul'] = [0] * len(df)
df['namengemek'] = [0] * len(df)
df['chongzasan'] = [0] * len(df)
now = '2007-03-16'
target_ratios = [.8, .7] # 20퍼센트일 때 사고 30일때
cashes = [200, 400]
# target ration 만큼 떨어졌을 때 사는 부분
for r, c in zip(target_ratios, cashes):
target_close = df['Close'][now] * r #07-03-16일의 종가 * 0.8 0.7 의 가격이 TARGET CLOSE 다
target = df[now:][df['Close'][now:] < target_close].iloc[0]
print(target_close)
print(target)
#TARGET은 오늘 날짜부터 시작한 CLOSE 의 가격이 TARGER CLOSE의 가격보다 작을때 어떻게 한다는 말인지 말모르겠네요 ㅠㅠ
target_idx = len(df.loc[:target.name])
print(target_idx)
print(target.name)
#target_idx는 무엇의 개수일까요?
target_buy_amount = (c / df['Close'][target_idx]).astype(int)
#target_buy_amount는 뭐를 정수로 바꾼다는 의미일까요?
print(target_buy_amount)
df['Buy_amount'].loc[target.name] = target_buy_amount
#무슨의미일까요? ㅠㅠ
df['Once_buy_money'].loc[target.name] = df['Buy_amount'].loc[target.name] * df['Close'].loc[target.name]
df['Boyu_amount'].iloc[target_idx-1:] += target_buy_amount
df['Total_tuip'].iloc[target_idx-1:] += df['Once_buy_money'].loc[target.name]
# 특정 날짜에서 얼마를 사고 싶을 때 df 업데이트
input_dates = ['2008-10-13','2008-10-14']
input_cashes = [500,500]
for input_date, input_cash in zip(input_dates, input_cashes):
input_buy_amount = (input_cash / df['Close'].loc[input_date]).astype(int)
input = df.loc[input_date]
input_idx = len(df.loc[:input.name])
df['Buy_amount'].loc[input_date] += input_buy_amount
df['Once_buy_money'].loc[input_date] += df['Buy_amount'].loc[input_date] * df['Close'].loc[input_date]
df['Boyu_amount'].loc[input_date:] += input_buy_amount
df['Total_tuip'].iloc[input_idx-1:] += df['Once_buy_money'].loc[input.name]
# 특정 날짜에서 얼마는 팔고 싶을 때 df 업데이트
sell_dates = ['2008-10-20', '2008-10-29']
sell_ratios = [.5, .3]
for sell_date, sell_ratio in zip(sell_dates, sell_ratios):
df['Sell_amount'].loc[sell_date] = (df['Boyu_amount'].loc[sell_date] * sell_ratio).astype(int)
sell = df.loc[sell_date]
sell_idx = len(df.loc[:sell.name])
df['Boyu_amount'].iloc[sell_idx:] -= df['Sell_amount'].loc[sell_date]
df['Sell_prices'].loc[sell_date] = df['Close'].loc[sell_date]
df['Total_sell_prices'].loc[sell_date] = df['Sell_amount'].loc[sell_date] * df['Sell_prices'].loc[sell_date]
df['Total_tuip'].iloc[sell_idx-1:] *= (df['Boyu_amount'].loc[sell_date] - df['Sell_amount'].loc[sell_date])/df['Boyu_amount'].loc[sell_date]
# 그 외 columns
df['Peongdanga'] = df['Total_tuip'] / df['Boyu_amount']
df['Peonggageumek'] = df['Close'] * df['Boyu_amount']
df['suikgeum']=df['Peonggageumek']-df['Total_tuip']
df['suikyul']=df['suikgeum']/df['Total_tuip']*100
df['2008-10-07':'2008-10-30']
