Skip to content

Commit

Permalink
sets
Browse files Browse the repository at this point in the history
  • Loading branch information
VladKochetov007 committed Jun 2, 2021
1 parent 6efea00 commit 8fff9a8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 46 deletions.
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,32 @@ or
$ pip3 install quick-trade
```

## user's code example
```
import quick_trade.trading_sys as qtr
import ccxt
client = brokers.TradingClient(ccxt.binance())
df = client.get_data_historical('BTC/USDT', '15m', 1000)
trader = qtr.Trader('BTC/USDT', df=df, interval='15m')
trader.set_client(client)
trader.set_pyplot(height=731, width=1440, row_heights=[10, 5, 2])
trader.strategy_2_sma(55, 21)
trader.backtest(deposit=1000, commission=0.075, bet=qtr.utils.np.inf)
```

## output plotly chart:

![image](https://i.ibb.co/NyxbsV2/Unknown-2.png)
![image](https://raw.githubusercontent.com/VladKochetov007/quick_trade/master/plot.png)

## output print

```
losses: 226
trades: 460
profits: 232
mean year percentage profit: 9075.656014641549%
winrate: 50.43478260869565%
losses: 7
trades: 16
profits: 9
mean year percentage profit: 541.9299012354617%
winrate: 56.25%
```

![image](https://i.ibb.co/mFLDJsX/IMG-5613.png)
Expand Down
Binary file added plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 16 additions & 40 deletions quick_trade/trading_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# numpy
# scalper and dca bot

import random
import time
import typing
from typing import Dict, List, Tuple, Any, Iterable
Expand Down Expand Up @@ -152,7 +151,6 @@ def __init__(self,
self._sec_interval = 86400 * 180
else:
raise ValueError(f'incorrect interval; {interval}')
self._regression_inputs = utils.REGRESSION_INPUTS
self.__exit_order__ = False

def __repr__(self):
Expand Down Expand Up @@ -205,19 +203,6 @@ def scipy_filter(self,
line=dict(width=utils.SUB_LINES_WIDTH)), 1, 1)
return pd.Series(filtered)

def bull_power(self, periods: int) -> np.ndarray:
EMA = ta.trend.ema_indicator(self.df['Close'], periods)
return np.array(self.df['High']) - EMA

def tema(self, periods: int, *args, **kwargs) -> pd.Series:
"""
:rtype: pd.Series
"""
ema = ta.trend.ema_indicator(self.df['Close'], periods)
ema2 = ta.trend.ema_indicator(ema, periods)
ema3 = ta.trend.ema_indicator(ema2, periods)
return pd.Series(3 * ema.values - 3 * ema2.values + ema3.values)

def __get_stop_take(self, sig: utils.PREDICT_TYPE) -> Dict[str, float]:
"""
calculating stop loss and take profit.
Expand Down Expand Up @@ -296,6 +281,7 @@ def strategy_diff(self, frame_to_diff: pd.Series, *args, **kwargs) -> utils.PRED

def strategy_buy_hold(self, *args, **kwargs) -> utils.PREDICT_TYPE_LIST:
self.returns = [utils.BUY for _ in range(len(self.df))]
self.set_credit_leverages()
self.set_open_stop_and_take()
return self.returns

Expand Down Expand Up @@ -328,6 +314,7 @@ def strategy_2_sma(self,
else:
self.returns.append(utils.EXIT)
self.set_open_stop_and_take()
self.set_credit_leverages()
return self.returns

def strategy_3_sma(self,
Expand Down Expand Up @@ -360,6 +347,7 @@ def strategy_3_sma(self,
else:
self.returns.append(utils.EXIT)

self.set_credit_leverages()
self.set_open_stop_and_take()
return self.returns

Expand Down Expand Up @@ -391,6 +379,7 @@ def strategy_3_ema(self,
self.returns.append(utils.SELL)
else:
self.returns.append(utils.EXIT)
self.set_credit_leverages()
self.set_open_stop_and_take()
return self.returns

Expand All @@ -409,23 +398,7 @@ def strategy_macd(self,
self.returns.append(utils.SELL)
else:
self.returns.append(utils.EXIT)
self.set_open_stop_and_take()
return self.returns

def strategy_exp_diff(self,
period: int = 70,
plot: bool = True,
*args,
**kwargs) -> utils.PREDICT_TYPE_LIST:
exp: pd.Series = self.tema(period)
self.strategy_diff(exp)
if plot:
self.fig.add_trace(
Line(
name=f'EMA{period}',
y=exp.values.T[0],
line=dict(width=utils.SUB_LINES_WIDTH)), 1, 1)

self.set_credit_leverages()
self.set_open_stop_and_take()
return self.returns

Expand All @@ -451,6 +424,7 @@ def strategy_rsi(self,
flag = utils.EXIT
self.returns.append(flag)

self.set_credit_leverages()
self.set_open_stop_and_take()
return self.returns

Expand Down Expand Up @@ -478,7 +452,8 @@ def strategy_parabolic_SAR(self, plot: bool = True, *args, **sar_kwargs) -> util
self.returns.append(utils.SELL)
else:
self.returns.append(utils.EXIT)
self.set_open_stop_and_take(set_stop=False)
self.set_credit_leverages()
self.set_open_stop_and_take()
return self.returns

def strategy_macd_histogram_diff(self,
Expand All @@ -497,11 +472,7 @@ def strategy_macd_histogram_diff(self,
self.returns.append(utils.BUY)
else:
self.returns.append(utils.SELL)
self.set_open_stop_and_take()
return self.returns

def strategy_random_pred(self, *args, **kwargs) -> utils.PREDICT_TYPE_LIST:
self.returns = [random.choice([utils.EXIT, utils.SELL, utils.BUY]) for i in range(len(self.df))]
self.set_credit_leverages()
self.set_open_stop_and_take()
return self.returns

Expand All @@ -522,6 +493,7 @@ def strategy_supertrend(self, plot: bool = True, *st_args, **st_kwargs) -> utils
self.returns = list(st.get_supertrend_strategy_returns())
self._stop_losses[0] = np.inf if self.returns[0] == utils.SELL else -np.inf
self.set_open_stop_and_take(set_stop=False)
self.set_credit_leverages()
return self.returns

def strategy_bollinger(self,
Expand Down Expand Up @@ -686,7 +658,7 @@ def strategy_ichimoku(self,
self._stop_losses.append(max_cloud + stop_loss_adder)
self.set_open_stop_and_take(set_take=True,
set_stop=False)
self.set_open_stop_and_take()
self.set_credit_leverages()
return self.returns

def crossover(self, fast: Iterable, slow: Iterable):
Expand Down Expand Up @@ -1465,6 +1437,7 @@ def find_pip_bar(self,
self.returns.append(flag)
else:
self.returns.append(flag)
self.set_credit_leverages()
self.set_open_stop_and_take()
return self.returns

Expand Down Expand Up @@ -1494,7 +1467,7 @@ def find_DBLHC_DBHLC(self, *args, **kwargs) -> utils.PREDICT_TYPE_LIST:

self.returns.append(flag)
self._stop_losses.append(flag_stop_loss)
self.set_open_stop_and_take(set_take=False, set_stop=False)
self.set_credit_leverages()
return self.returns

def find_TBH_TBL(self, *args, **kwargs) -> utils.PREDICT_TYPE_LIST:
Expand All @@ -1515,6 +1488,7 @@ def find_TBH_TBL(self, *args, **kwargs) -> utils.PREDICT_TYPE_LIST:
elif low[0] == low[1]:
flag = utils.SELL
self.returns.append(flag)
self.set_credit_leverages()
self.set_open_stop_and_take()
return self.returns

Expand All @@ -1535,6 +1509,7 @@ def find_PPR(self, *args, **kwargs) -> utils.PREDICT_TYPE_LIST:
) == high[1] and close[2] < close[1] and low[2] > low[0]:
flag = utils.SELL
self.returns.append(flag)
self.set_credit_leverages()
self.set_open_stop_and_take()
return self.returns

Expand All @@ -1549,6 +1524,7 @@ def is_doji(self, *args, **kwargs) -> List[bool]:
ret.append(True)
else:
ret.append(False)
self.set_credit_leverages()
self.set_open_stop_and_take()
return ret

Expand Down

0 comments on commit 8fff9a8

Please sign in to comment.