goldhand 12.9__py3-none-any.whl → 13.3__py3-none-any.whl

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.

@@ -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 = 'Goldhand line Strategy' )
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=800, title=plot_title)
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.show()
257
+ return (fig)
246
258
 
247
259
 
248
- #show_indicator_goldhand_line_strategy('TSLA', plot_title='sdgfsdg')
260
+ #ticker= 'AAPL'
261
+ #show_indicator_goldhand_line_strategy(ticker, plot_title=tw.get_plotly_title(ticker), ndays=700, plot_height=1000)
goldhand/strategy_rsi.py CHANGED
@@ -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 = 'RSI Strategy'):
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.show()
189
+ return (fig)
164
190
 
165
191
 
166
192
  # Test
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: goldhand
3
- Version: 12.9
3
+ Version: 13.3
4
4
  Summary: A package working with financial data
5
5
  Home-page: https://github.com/misrori/goldhand
6
6
  Author: Mihaly
@@ -2,10 +2,10 @@ goldhand/__init__.py,sha256=2D68nqSZuv6sqyLJbOXnWIeeFpNgpYc90rHa2Fo70lk,152
2
2
  goldhand/backtest.py,sha256=KrZXXaQw3ZPxE3tY0MOCa2qPJX374pVMLwM_VIOKy5Y,6105
3
3
  goldhand/helpers.py,sha256=l9yn0kVTiwfUR8sI5nH1QFx6dYikaUQgRA227Ox7hs0,6130
4
4
  goldhand/stocks.py,sha256=0MnjAex2A2c06JHinToKHBAvUJvYtDFXxtGudqBux6o,10521
5
- goldhand/strategy_goldhand_line.py,sha256=R_ZKmkGXft6zsGIG5tA28MRJv9ssFTtyC5uzzVXT_h8,9797
6
- goldhand/strategy_rsi.py,sha256=Mo_yo5H25ncuMKclW4Y-sSFWgELAqZjWEIMkt2QMqF8,7588
5
+ goldhand/strategy_goldhand_line.py,sha256=ersczdUtKBpyWpmgbLOEnoGi5MedV1aSjBNptMM-zP0,10501
6
+ goldhand/strategy_rsi.py,sha256=9uzKo3HnmpkJV7rxzvovlGZv3-O2rwTJxxdl8V2--s4,8804
7
7
  goldhand/tw.py,sha256=K8MwMDkW5JtBFBG0qcPzj8OVx2OhDjrOH2UGo6nwtSs,8375
8
- goldhand-12.9.dist-info/METADATA,sha256=yzP3KJIBW7PuJDeJ9pLIEKLD9Ck5ff9iZdlEYpPzKTs,1952
9
- goldhand-12.9.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
10
- goldhand-12.9.dist-info/top_level.txt,sha256=siEJ2_a_Fx_7hqRI4Ms6SzCelbXrK_1H_eOF8KAaMdA,9
11
- goldhand-12.9.dist-info/RECORD,,
8
+ goldhand-13.3.dist-info/METADATA,sha256=rDlhsIGYs5naNPOD5fmCy6_SpNDm9kg0gdkVHCvYlJo,1952
9
+ goldhand-13.3.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
10
+ goldhand-13.3.dist-info/top_level.txt,sha256=siEJ2_a_Fx_7hqRI4Ms6SzCelbXrK_1H_eOF8KAaMdA,9
11
+ goldhand-13.3.dist-info/RECORD,,