goldhand 12.9__tar.gz → 13.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of goldhand might be problematic. Click here for more details.
- {goldhand-12.9 → goldhand-13.3}/PKG-INFO +1 -1
- {goldhand-12.9 → goldhand-13.3}/goldhand/strategy_goldhand_line.py +27 -14
- {goldhand-12.9 → goldhand-13.3}/goldhand/strategy_rsi.py +28 -2
- {goldhand-12.9 → goldhand-13.3}/goldhand.egg-info/PKG-INFO +1 -1
- {goldhand-12.9 → goldhand-13.3}/setup.py +1 -1
- {goldhand-12.9 → goldhand-13.3}/README.md +0 -0
- {goldhand-12.9 → goldhand-13.3}/goldhand/__init__.py +0 -0
- {goldhand-12.9 → goldhand-13.3}/goldhand/backtest.py +0 -0
- {goldhand-12.9 → goldhand-13.3}/goldhand/helpers.py +0 -0
- {goldhand-12.9 → goldhand-13.3}/goldhand/stocks.py +0 -0
- {goldhand-12.9 → goldhand-13.3}/goldhand/tw.py +0 -0
- {goldhand-12.9 → goldhand-13.3}/goldhand.egg-info/SOURCES.txt +0 -0
- {goldhand-12.9 → goldhand-13.3}/goldhand.egg-info/dependency_links.txt +0 -0
- {goldhand-12.9 → goldhand-13.3}/goldhand.egg-info/requires.txt +0 -0
- {goldhand-12.9 → goldhand-13.3}/goldhand.egg-info/top_level.txt +0 -0
- {goldhand-12.9 → goldhand-13.3}/setup.cfg +0 -0
|
@@ -91,8 +91,7 @@ def goldhand_line_strategy(data):
|
|
|
91
91
|
return(res_df)
|
|
92
92
|
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
def show_indicator_goldhand_line_strategy(ticker, plot_title = 'Goldhand line Strategy'):
|
|
94
|
+
def show_indicator_goldhand_line_strategy(ticker, plot_title = '', ndays=0, plot_height=800):
|
|
96
95
|
|
|
97
96
|
data = GoldHand(ticker).df
|
|
98
97
|
|
|
@@ -134,9 +133,17 @@ def show_indicator_goldhand_line_strategy(ticker, plot_title = 'Goldhand line St
|
|
|
134
133
|
##### data prepar end
|
|
135
134
|
|
|
136
135
|
##### backtest
|
|
137
|
-
backtest = Backtest( data, goldhand_line_strategy, plot_title =
|
|
136
|
+
backtest = Backtest( data, goldhand_line_strategy, plot_title =plot_title)
|
|
138
137
|
trades =backtest.trades
|
|
139
138
|
|
|
139
|
+
if ndays!=0:
|
|
140
|
+
data = data.tail(ndays)
|
|
141
|
+
trades = trades.loc[trades['buy_date']>data.date.min()]
|
|
142
|
+
|
|
143
|
+
if data['high'].max() >= max(data['high'][0:50]):
|
|
144
|
+
tex_loc = [0.1, 0.2]
|
|
145
|
+
else:
|
|
146
|
+
tex_loc = [0.1, 0.85]
|
|
140
147
|
|
|
141
148
|
# base plot
|
|
142
149
|
fig = go.Figure(data=go.Ohlc(x=data['date'], open=data['open'], high=data['high'], low=data['low'],close=data['close']))
|
|
@@ -227,22 +234,28 @@ def show_indicator_goldhand_line_strategy(ticker, plot_title = 'Goldhand line St
|
|
|
227
234
|
font=dict(size=13, color=triangle_color, family="Times New Roman")))
|
|
228
235
|
|
|
229
236
|
# Update layout
|
|
230
|
-
fig.update_layout(showlegend=False, plot_bgcolor='white', height=
|
|
237
|
+
fig.update_layout(showlegend=False, plot_bgcolor='white', height=plot_height, title=plot_title)
|
|
231
238
|
fig.update(layout_xaxis_rangeslider_visible=False)
|
|
232
239
|
|
|
233
|
-
# Update x-axes and y-axes for the main chart
|
|
234
|
-
fig.update_xaxes(mirror=True, ticks='outside', showline=True, linecolor='black', gridcolor='lightgrey')
|
|
235
|
-
fig.update_yaxes(mirror=True, ticks='outside', showline=True, linecolor='black', gridcolor='lightgrey')
|
|
236
|
-
|
|
237
|
-
# Update x-axes and y-axes for the RSI subplot
|
|
238
|
-
fig.update_xaxes(mirror=True, ticks='outside', showline=True, linecolor='black', gridcolor='lightgrey')
|
|
239
|
-
fig.update_yaxes(mirror=True, ticks='outside', showline=True, linecolor='black', gridcolor='lightgrey')
|
|
240
|
-
|
|
241
240
|
|
|
241
|
+
t= backtest.trades_summary
|
|
242
|
+
trade_text = f"Trades: {t['number_of_trades']}<br>"\
|
|
243
|
+
f"Win ratio: {t['win_ratio(%)']}%<br>"\
|
|
244
|
+
f"Average result: {t['average_res(%)']}%<br>"\
|
|
245
|
+
f"Median result: {t['median_res(%)']}%<br>"\
|
|
246
|
+
f"Average trade lenght: {round(t['average_trade_len(days)'], 0)} days<br>"\
|
|
247
|
+
f"Cumulative result: {round(t['cumulative_result'], 2)}x<br>"\
|
|
248
|
+
f"Profitable trades mean: {t['profitable_trades_mean']}%<br>"\
|
|
249
|
+
f"Profitable trades median: {t['profitable_trades_median']}%<br>"\
|
|
250
|
+
f"Looser trades mean: {t['looser_trades_mean']}%<br>"\
|
|
251
|
+
f"Looser trades median: {t['looser_trades_median']}%<br>"
|
|
242
252
|
|
|
253
|
+
# Add a larger textbox using annotations
|
|
254
|
+
fig.add_annotation( go.layout.Annotation( x=tex_loc[0], y=tex_loc[1], xref='paper', yref='paper', text=trade_text, showarrow=True, arrowhead=4, ax=0, ay=0, bordercolor='black', borderwidth=2, bgcolor='white', align='left', font=dict(size=14, color='black')))
|
|
243
255
|
|
|
244
256
|
# Show the plot
|
|
245
|
-
fig
|
|
257
|
+
return (fig)
|
|
246
258
|
|
|
247
259
|
|
|
248
|
-
#
|
|
260
|
+
#ticker= 'AAPL'
|
|
261
|
+
#show_indicator_goldhand_line_strategy(ticker, plot_title=tw.get_plotly_title(ticker), ndays=700, plot_height=1000)
|
|
@@ -67,11 +67,22 @@ def rsi_strategy(data, buy_threshold = 30, sell_threshold = 70):
|
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
def show_indicator_rsi_strategy(ticker, buy_threshold = 30, sell_threshold = 70, plot_title = '
|
|
70
|
+
def show_indicator_rsi_strategy(ticker, buy_threshold = 30, sell_threshold = 70, plot_title = '', ndays=0, plot_height=800):
|
|
71
71
|
|
|
72
72
|
tdf = GoldHand(ticker).df
|
|
73
73
|
backtest = Backtest( tdf, rsi_strategy, buy_threshold=buy_threshold, sell_threshold=sell_threshold)
|
|
74
74
|
trades =backtest.trades
|
|
75
|
+
|
|
76
|
+
if ndays!=0:
|
|
77
|
+
tdf = data.tail(tdf)
|
|
78
|
+
trades = trades.loc[trades['buy_date']>tdf.date.min()]
|
|
79
|
+
|
|
80
|
+
if data['high'].max() >= max(data['high'][0:50]):
|
|
81
|
+
tex_loc = [0.1, 0.2]
|
|
82
|
+
else:
|
|
83
|
+
tex_loc = [0.1, 0.85]
|
|
84
|
+
|
|
85
|
+
|
|
75
86
|
|
|
76
87
|
# Create subplots with shared x-axis and custom heights
|
|
77
88
|
fig = make_subplots(rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.1, subplot_titles=[plot_title, "RSI"], row_heights=[0.7, 0.3])
|
|
@@ -151,6 +162,21 @@ def show_indicator_rsi_strategy(ticker, buy_threshold = 30, sell_threshold = 70,
|
|
|
151
162
|
fig.update_yaxes(mirror=True, ticks='outside', showline=True, linecolor='black', gridcolor='lightgrey', row=2, col=1)
|
|
152
163
|
|
|
153
164
|
|
|
165
|
+
t= backtest.trades_summary
|
|
166
|
+
trade_text = f"Trades: {t['number_of_trades']}<br>"\
|
|
167
|
+
f"Win ratio: {t['win_ratio(%)']}%<br>"\
|
|
168
|
+
f"Average result: {t['average_res(%)']}%<br>"\
|
|
169
|
+
f"Median result: {t['median_res(%)']}%<br>"\
|
|
170
|
+
f"Average trade length: {round(t['average_trade_len(days)'], 0)} days<br>"\
|
|
171
|
+
f"Cumulative result: {round(t['cumulative_result'], 2)}x<br>"\
|
|
172
|
+
f"Profitable trades mean: {t['profitable_trades_mean']}%<br>"\
|
|
173
|
+
f"Profitable trades median: {t['profitable_trades_median']}%<br>"\
|
|
174
|
+
f"Looser trades mean: {t['looser_trades_mean']}%<br>"\
|
|
175
|
+
f"Looser trades median: {t['looser_trades_median']}%<br>"
|
|
176
|
+
|
|
177
|
+
# Add a larger textbox using annotations
|
|
178
|
+
fig.add_annotation( go.layout.Annotation( x=tex_loc[0], y=tex_loc[1], xref='paper', yref='paper', text=trade_text, showarrow=True, arrowhead=4, ax=0, ay=0, bordercolor='black', borderwidth=2, bgcolor='white', align='left', font=dict(size=14, color='black')))
|
|
179
|
+
|
|
154
180
|
|
|
155
181
|
|
|
156
182
|
# Add RSI line
|
|
@@ -160,7 +186,7 @@ def show_indicator_rsi_strategy(ticker, buy_threshold = 30, sell_threshold = 70,
|
|
|
160
186
|
|
|
161
187
|
|
|
162
188
|
# Show the plot
|
|
163
|
-
fig
|
|
189
|
+
return (fig)
|
|
164
190
|
|
|
165
191
|
|
|
166
192
|
# Test
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|