goldhand 15.1__py3-none-any.whl → 15.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.
- goldhand/stocks.py +7 -1
- goldhand/strategy_goldhand_line.py +24 -13
- goldhand/strategy_rsi.py +18 -9
- {goldhand-15.1.dist-info → goldhand-15.3.dist-info}/METADATA +1 -1
- goldhand-15.3.dist-info/RECORD +11 -0
- goldhand-15.1.dist-info/RECORD +0 -11
- {goldhand-15.1.dist-info → goldhand-15.3.dist-info}/WHEEL +0 -0
- {goldhand-15.1.dist-info → goldhand-15.3.dist-info}/top_level.txt +0 -0
goldhand/stocks.py
CHANGED
|
@@ -21,6 +21,9 @@ class GoldHand:
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
def get_olhc(self):
|
|
24
|
+
"""
|
|
25
|
+
Download historical stock data for the last year
|
|
26
|
+
"""
|
|
24
27
|
#scraper = cloudscraper.create_scraper()
|
|
25
28
|
response = self.scraper.get(f"https://query1.finance.yahoo.com/v8/finance/chart/{self.ticker}?interval={self.interval}&range={self.range}")
|
|
26
29
|
t= response.json()
|
|
@@ -32,6 +35,9 @@ class GoldHand:
|
|
|
32
35
|
return(df)
|
|
33
36
|
|
|
34
37
|
def smma(self, data, window, colname):
|
|
38
|
+
"""
|
|
39
|
+
Calculate Smoothed Moving Average (SMMA)
|
|
40
|
+
"""
|
|
35
41
|
hl2 = data['hl2'].values
|
|
36
42
|
smma_values = [hl2[0]]
|
|
37
43
|
|
|
@@ -141,7 +147,7 @@ class GoldHand:
|
|
|
141
147
|
else:
|
|
142
148
|
temj = '😭💔'
|
|
143
149
|
self.df.loc[states[i], 'local_text'] = f'{temj}{fall}%<br>${round(current_low, 2)}'
|
|
144
|
-
|
|
150
|
+
self.df.reset_index(inplace=True, drop=True)
|
|
145
151
|
|
|
146
152
|
def plotly_last_year(self, plot_title, plot_height=900, ndays=500, ad_local_min_max=True):
|
|
147
153
|
tdf = self.df.tail(ndays)
|
|
@@ -8,11 +8,13 @@ from goldhand import *
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
def goldhand_line_strategy(data):
|
|
11
|
+
def goldhand_line_strategy(data, buy_at='gold', sell_at='grey'):
|
|
12
12
|
"""
|
|
13
13
|
This function implements the goldhand line strategy.
|
|
14
14
|
Parameters:
|
|
15
15
|
data (pandas.DataFrame): The dataframe containing the data.
|
|
16
|
+
buy_at (str): The color of the line to buy at. Default is 'gold'.
|
|
17
|
+
sell_at (str): The color of the line to sell at. Default is 'grey'.
|
|
16
18
|
Returns:
|
|
17
19
|
res_df (pandas.DataFrame): The dataframe containing the results.
|
|
18
20
|
"""
|
|
@@ -52,23 +54,33 @@ def goldhand_line_strategy(data):
|
|
|
52
54
|
# Check if not already in a trade
|
|
53
55
|
if not in_trade:
|
|
54
56
|
# Generate buy signal
|
|
55
|
-
if (data['color'][i] ==
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
if (data['color'][i] ==buy_at) :
|
|
58
|
+
|
|
59
|
+
if i == (len(data) -1):
|
|
60
|
+
temp_trade['buy_price'] = data['close'][i]
|
|
61
|
+
temp_trade.update(dict(data.iloc[i].add_prefix('buy_')))
|
|
62
|
+
else:
|
|
63
|
+
temp_trade['buy_price'] = data['open'][i+1]
|
|
64
|
+
temp_trade.update(dict(data.iloc[i+1].add_prefix('buy_')))
|
|
65
|
+
|
|
66
|
+
|
|
58
67
|
temp_trade['trade_id'] = trade_id
|
|
59
68
|
temp_trade['status'] = 'open'
|
|
60
|
-
temp_trade.update(dict(data.iloc[i].add_prefix('buy_')))
|
|
61
69
|
in_trade = True # Set flag to indicate in a trade
|
|
62
70
|
else:
|
|
63
71
|
# Generate sell signal
|
|
64
|
-
if (data['color'][i] ==
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
if (data['color'][i] ==sell_at) :
|
|
73
|
+
|
|
74
|
+
if i == (len(data) -1):
|
|
75
|
+
temp_trade['sell_price'] = data['close'][i]
|
|
76
|
+
temp_trade.update(dict(data.iloc[i].add_prefix('sell_')))
|
|
77
|
+
else:
|
|
78
|
+
temp_trade['sell_price'] = data['open'][i+1]
|
|
79
|
+
temp_trade.update(dict(data.iloc[i+1].add_prefix('sell_')))
|
|
80
|
+
|
|
67
81
|
temp_trade['trade_id'] = trade_id
|
|
68
82
|
temp_trade['status'] = 'closed'
|
|
69
83
|
|
|
70
|
-
temp_trade.update(dict(data.iloc[i].add_prefix('sell_')))
|
|
71
|
-
|
|
72
84
|
# calculate results
|
|
73
85
|
temp_trade['result'] = temp_trade['sell_price'] / temp_trade['buy_price']
|
|
74
86
|
temp_trade['days_in_trade'] = (temp_trade['sell_date'] - temp_trade['buy_date']).days
|
|
@@ -98,7 +110,7 @@ def goldhand_line_strategy(data):
|
|
|
98
110
|
return(res_df)
|
|
99
111
|
|
|
100
112
|
|
|
101
|
-
def show_indicator_goldhand_line_strategy(ticker, plot_title = '', ndays=0, plot_height=1000, add_strategy_summary = True):
|
|
113
|
+
def show_indicator_goldhand_line_strategy(ticker, plot_title = '', buy_at='gold', sell_at='grey', ndays=0, plot_height=1000, add_strategy_summary = True):
|
|
102
114
|
"""
|
|
103
115
|
This function shows the goldhand line strategy on a plotly candlestick chart.
|
|
104
116
|
Parameters:
|
|
@@ -147,11 +159,10 @@ def show_indicator_goldhand_line_strategy(ticker, plot_title = '', ndays=0, plot
|
|
|
147
159
|
# Create a 'group' column and increase the value only when there's a color change
|
|
148
160
|
data['group'] = (data['color_change']).cumsum()
|
|
149
161
|
|
|
150
|
-
|
|
151
162
|
##### data prepar end
|
|
152
163
|
|
|
153
164
|
##### backtest
|
|
154
|
-
backtest = Backtest( data, goldhand_line_strategy, plot_title =plot_title)
|
|
165
|
+
backtest = Backtest( data, goldhand_line_strategy, plot_title =plot_title, buy_at='gold', sell_at='grey')
|
|
155
166
|
trades =backtest.trades
|
|
156
167
|
|
|
157
168
|
if ndays!=0:
|
goldhand/strategy_rsi.py
CHANGED
|
@@ -20,33 +20,43 @@ def rsi_strategy(data, buy_threshold = 30, sell_threshold = 70):
|
|
|
20
20
|
# Check if not already in a trade
|
|
21
21
|
if not in_trade:
|
|
22
22
|
# Generate buy signal
|
|
23
|
+
#You have to change olne the buy and sell signal
|
|
23
24
|
if data['rsi'][i] < buy_threshold:
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
if i == (len(data) -1):
|
|
27
|
+
temp_trade['buy_price'] = data['close'][i]
|
|
28
|
+
temp_trade.update(dict(data.iloc[i].add_prefix('buy_')))
|
|
29
|
+
else:
|
|
30
|
+
temp_trade['buy_price'] = data['open'][i+1]
|
|
31
|
+
temp_trade.update(dict(data.iloc[i+1].add_prefix('buy_')))
|
|
32
|
+
|
|
26
33
|
temp_trade['trade_id'] = trade_id
|
|
27
34
|
temp_trade['status'] = 'open'
|
|
28
|
-
temp_trade.update(dict(data.iloc[i].add_prefix('buy_')))
|
|
29
35
|
in_trade = True # Set flag to indicate in a trade
|
|
30
36
|
else:
|
|
31
37
|
# Generate sell signal
|
|
38
|
+
#You have to change olne the buy and sell signal
|
|
32
39
|
if data['rsi'][i] > sell_threshold:
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
if i == (len(data) -1):
|
|
41
|
+
temp_trade['sell_price'] = data['close'][i]
|
|
42
|
+
temp_trade.update(dict(data.iloc[i].add_prefix('sell_')))
|
|
43
|
+
else:
|
|
44
|
+
temp_trade['sell_price'] = data['open'][i+1]
|
|
45
|
+
temp_trade.update(dict(data.iloc[i+1].add_prefix('sell_')))
|
|
46
|
+
|
|
35
47
|
temp_trade['trade_id'] = trade_id
|
|
36
48
|
temp_trade['status'] = 'closed'
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
|
|
40
51
|
# calculate results
|
|
41
52
|
temp_trade['result'] = temp_trade['sell_price'] / temp_trade['buy_price']
|
|
42
53
|
temp_trade['days_in_trade'] = (temp_trade['sell_date'] - temp_trade['buy_date']).days
|
|
43
54
|
|
|
44
|
-
|
|
45
|
-
|
|
46
55
|
in_trade = False # Reset flag to indicate not in a trade
|
|
47
56
|
trade_id +=1
|
|
48
57
|
all_trades.append(temp_trade)
|
|
49
58
|
temp_trade = {}
|
|
59
|
+
|
|
50
60
|
if temp_trade:
|
|
51
61
|
temp_trade['sell_price'] = data['close'][i]
|
|
52
62
|
temp_trade['trade_id'] = trade_id
|
|
@@ -59,7 +69,6 @@ def rsi_strategy(data, buy_threshold = 30, sell_threshold = 70):
|
|
|
59
69
|
res_df = pd.DataFrame(all_trades)
|
|
60
70
|
|
|
61
71
|
# change orders
|
|
62
|
-
|
|
63
72
|
all_col = res_df.columns.tolist()
|
|
64
73
|
first = ['result', 'buy_price', 'sell_price', 'buy_date', 'sell_date', 'days_in_trade']
|
|
65
74
|
first.extend([x for x in all_col if x not in first])
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
goldhand/__init__.py,sha256=2D68nqSZuv6sqyLJbOXnWIeeFpNgpYc90rHa2Fo70lk,152
|
|
2
|
+
goldhand/backtest.py,sha256=haK0c7wbUv02DUU5LcrvDSC1i0h1nDX7HHYzD9abhb8,6456
|
|
3
|
+
goldhand/helpers.py,sha256=l9yn0kVTiwfUR8sI5nH1QFx6dYikaUQgRA227Ox7hs0,6130
|
|
4
|
+
goldhand/stocks.py,sha256=rQmcBo6cwu8mXmVSqT9PJhHCHJ9X1laPwhqX5sDHS6E,11886
|
|
5
|
+
goldhand/strategy_goldhand_line.py,sha256=TEb16PvaoX07bjtTRVMYlz2ilJ_YlQ2Q6_o-sAC60QQ,12056
|
|
6
|
+
goldhand/strategy_rsi.py,sha256=JhmefDm-PXmIT2tQNeLFjaDb0SpR1yln33wuDPt1Zp4,9540
|
|
7
|
+
goldhand/tw.py,sha256=zyB-Pb0KVns7bMrr6NFwDQlu6-PpFn-xWt9BRmmMMTs,8456
|
|
8
|
+
goldhand-15.3.dist-info/METADATA,sha256=m2qwyZHeVU61GG74tpHrlBTLpoHVbfDFnfEzmHXQ0NA,1952
|
|
9
|
+
goldhand-15.3.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
10
|
+
goldhand-15.3.dist-info/top_level.txt,sha256=siEJ2_a_Fx_7hqRI4Ms6SzCelbXrK_1H_eOF8KAaMdA,9
|
|
11
|
+
goldhand-15.3.dist-info/RECORD,,
|
goldhand-15.1.dist-info/RECORD
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
goldhand/__init__.py,sha256=2D68nqSZuv6sqyLJbOXnWIeeFpNgpYc90rHa2Fo70lk,152
|
|
2
|
-
goldhand/backtest.py,sha256=haK0c7wbUv02DUU5LcrvDSC1i0h1nDX7HHYzD9abhb8,6456
|
|
3
|
-
goldhand/helpers.py,sha256=l9yn0kVTiwfUR8sI5nH1QFx6dYikaUQgRA227Ox7hs0,6130
|
|
4
|
-
goldhand/stocks.py,sha256=wizTmZ8ybH76CSHuWbNu0hkbwH95Mw4LWSblb5jl9ro,11680
|
|
5
|
-
goldhand/strategy_goldhand_line.py,sha256=dsOzCsVtvhNJ42-r2rsPVV4YFuNto31ylqQ3Il4XYOw,11341
|
|
6
|
-
goldhand/strategy_rsi.py,sha256=eswHKmswX408Cf9xjny7DqxSkJ_FemtxHHQ2V69vbP0,8918
|
|
7
|
-
goldhand/tw.py,sha256=zyB-Pb0KVns7bMrr6NFwDQlu6-PpFn-xWt9BRmmMMTs,8456
|
|
8
|
-
goldhand-15.1.dist-info/METADATA,sha256=oaImadJh7nYeTavHKtXrwty7OQUXLuMJnnk-Nbapwyg,1952
|
|
9
|
-
goldhand-15.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
10
|
-
goldhand-15.1.dist-info/top_level.txt,sha256=siEJ2_a_Fx_7hqRI4Ms6SzCelbXrK_1H_eOF8KAaMdA,9
|
|
11
|
-
goldhand-15.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|