This commit is contained in:
dsyoon
2023-10-16 10:52:44 +09:00
parent 8bb8e8b09a
commit 90b3327716
4 changed files with 62 additions and 37 deletions

View File

@@ -37,7 +37,8 @@ class Simulation (HTS):
data = data.loc[pd.DatetimeIndex(data.index).day == int(given_day[6:])]
buy_line = bsLine['buy'][len(bsLine['buy'])-len(data):]
buy_weight_line = bsLine['buy_weight'][len(bsLine['buy'])-len(data):]
sell_line = bsLine['sell'][len(bsLine['buy'])-len(data):]
sell_line = bsLine['sell'][len(bsLine['sell'])-len(data):]
sell_weight_line = bsLine['sell_weight'][len(bsLine['sell']) - len(data):]
# 그래프 설정을 위한 변수를 생성한다.
data = data.astype({'open': 'int',
@@ -73,13 +74,25 @@ class Simulation (HTS):
buy_colors.append("#0C752E")
buy_size.append(10 + (5 * buy_weight_line[i]))
sell_size = []
sell_colors = []
for i in range(len(sell_line)):
if sell_line[i] < 0:
sell_colors.append("#ffffff")
sell_line[i] = nan
sell_size.append(0)
else:
sell_colors.append("#00ced1")
sell_size.append(10 + (5 * sell_weight_line[i]))
volume_colors = []
for i in range(len(buy_line)):
if data['open'][i] > data['close'][i]:
volume_colors.append("#0000FF")
elif data['open'][i] < data['close'][i]:
volume_colors.append("#FF0000")
else:
volume_colors.append("#000000")
# 그래프를 설정한다.
buy_check = go.Scatter(x=data['date'], y=buy_line, mode='markers', name="buy", marker=dict(size=buy_size, color=buy_colors, line_width=0))
@@ -98,7 +111,7 @@ class Simulation (HTS):
candle_stick = go.Candlestick(x=data['date'], open=data['open'], high=data['high'], low=data['low'], close=data['close'], increasing_line_color='red', decreasing_line_color='blue', showlegend=False)
#volume_line = go.Scatter(x=data['date'], y=data["volume"], mode='lines', name='volume')
volume_line = go.Bar(x=data['date'], y=data["volume"], marker_color='red', name='volume')
volume_line = go.Bar(x=data['date'], y=data["volume"], marker_color=volume_colors, name='volume')
disparity_avg5 = go.Scatter(x=data['date'], y=data["disparity_avg5"], name="disparity_avg5", line_color='#F81191')
disparity_avg20 = go.Scatter(x=data['date'], y=data["disparity_avg20"], name="disparity_avg20", line_color='#097F19')
@@ -118,9 +131,9 @@ class Simulation (HTS):
rsi_line = go.Scatter(x=data['date'], y=data["rsi"], line=dict(color='red', width=2), name='rsi')
rsis_line = go.Scatter(x=data['date'], y=data["rsis"], line=dict(dash='dashdot', color='black', width=2), name='rsis')
candle_data = [candle_stick, upper, lower, avg5, avg20, avg30, avg60, avg120, avg200, buy_check, sell_check, laggingSpan, changeLine, baseLine]
#candle_data = [candle_stick, upper, lower, avg5, avg20, avg30, avg60, avg120, avg200, buy_check, sell_check, laggingSpan, changeLine, baseLine]
candle_data = [candle_stick, avg5, avg20, avg30, avg60, avg200, buy_check, sell_check]
candle_data = [candle_stick, avg200, buy_check, sell_check]
#candle_data = [candle_stick, avg200, buy_check, sell_check]
volume_data = [volume_line]
disparity_data = [disparity_avg5, disparity_avg20, disparity_avg30, disparity_avg60, disparity_avg120, disparity_avg200]
macd_data = [macd_line, macd_s_line, macd_o_line]
@@ -136,20 +149,20 @@ class Simulation (HTS):
fig = subplots.make_subplots(
rows=6, cols=1,
subplot_titles=("거래량", "이격도", "스토캐스틱", "RSI", "MACD", '캔들'),
subplot_titles=("이격도", "스토캐스틱", "RSI", "MACD", "거래량", '캔들'),
#specs=[[{}], [{}], [{}], [{}], [{}], [{}]],
shared_xaxes=True, horizontal_spacing=0.03, vertical_spacing=0.01,
row_heights=[200, 200, 200, 200, 200, 700]
)
for trace in volume_data:
fig.append_trace(trace, 1, 1)
for trace in disparity_data:
fig.append_trace(trace, 2, 1)
fig.append_trace(trace, 1, 1)
for trace in stochastic_data:
fig.append_trace(trace, 3, 1)
fig.append_trace(trace, 2, 1)
for trace in rsi_data:
fig.append_trace(trace, 4, 1)
fig.append_trace(trace, 3, 1)
for trace in macd_data:
fig.append_trace(trace, 4, 1)
for trace in volume_data:
fig.append_trace(trace, 5, 1)
for trace in candle_data:
fig.append_trace(trace, 6, 1)
@@ -234,12 +247,12 @@ if __name__ == "__main__":
# to check bying
stock_codes = {
"252670": ['20231012'],
"122630": ['20231012'],
#"252670": ['20210901','20210902','20210903','20210906'],
#"252670": ['20210901', '20210902', '20210903', '20210906', '20210907', '20210908', '20210909', '20210910', '20210913', '20210914', '20210915', '20210916', '20210917', '20210923', '20210924', '20210927', '20210928', '20210929', '20210930', '20211001', '20211005'],
#"122630": ['20220901', '20220902', '20220905', '20220906']
#"122630": ['20210901', '20210902', '20210903', '20210906', '20210907', '20210908', '20210909', '20210910', '20210913', '20210914', '20210915', '20210916', '20210917', '20210923', '20210924', '20210927', '20210928', '20210929', '20210930', '20211001', '20211005'],
#"252670": ['20210930'],
#"122630": ['20230930'],
#"252670": ['20210903','20210910','20210913'],
"252670": ['20210901', '20210902', '20210903', '20210906', '20210907', '20210908', '20210909', '20210910', '20210913', '20210914', '20210915', '20210916', '20210917', '20210923', '20210924', '20210927', '20210928', '20210929', '20210930', '20211001', '20211005','20231012','20231013'],
#"122630": ['20210901','20210902','20210903','20210906','20231012','20231013']
#"122630": ['20210901', '20210902', '20210903', '20210906', '20210907', '20210908', '20210909', '20210910', '20210913', '20210914', '20210915', '20210916', '20210917', '20210923', '20210924', '20210927', '20210928', '20210929', '20210930', '20211001', '20211005','20231012','20231013'],
}
#simulation.simulate(stock_codes)
simulation.simulate(stock_codes)