Skip to content

Commit

Permalink
debug and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
VladKochetov007 committed Oct 29, 2021
1 parent 4f08a9d commit 0213db4
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 46 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,16 @@ trader.backtest(deposit=1000, commission=0.075, bet=inf) # backtest on one pair
## Output print

```commandline
losses: 18
trades: 25
profits: 7
mean year percentage profit: -8.471933037953615%
winrate: 28.000000000000004%
mean deviation: 1.3587506741755202%
losses: 12
trades: 20
profits: 8
mean year percentage profit: 215.1878652911773%
winrate: 40.0%
mean deviation: 2.917382949881604%
Sharpe ratio: 0.02203412259055281
Sortino ratio: 0.02774402450236864
calmar ratio: 21.321078596349782
max drawdown: 10.092728860725552%
```

## Run strategy
Expand Down Expand Up @@ -240,9 +244,7 @@ trader.realtime_trading(
strategy=trader.strategy,
start_time=start_time,
ticker=ticker,
coin_lotsize_division=True,
limit=100,
ignore_exceptions=False,
wait_sl_tp_checking=5
)

Expand Down
30 changes: 19 additions & 11 deletions docs/docs/quick_trade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ Result:

```commandline
losses: 64
trades: 95
profits: 25
mean year percentage profit: -99.99999896786758%
winrate: 26.31578947368421%
mean deviation: 1.4569306356613254%
trades: 97
profits: 27
mean year percentage profit: -99.99999998327092%
winrate: 27.835051546391753%
mean deviation: 2.624118103674615%
Sharpe ratio: -44.291604314886655
Sortino ratio: -52.11339011671788
calmar ratio: -4.920697866228742
max drawdown: 20.322320675199602%
```

![image](https://raw.githubusercontent.com/VladKochetov007/quick_trade/master/img/simple_backtest_example.png)
Expand Down Expand Up @@ -176,12 +180,16 @@ trader.multi_backtest(test_config={
Result:

```commandline
losses: 92
trades: 36
profits: 36
mean year percentage profit: -99.75637914387364%
winrate: 26.407268062042323%
mean deviation: 5.669772760548183%
losses: 54
trades: 80
profits: 22
mean year percentage profit: -93.08433705679062%
winrate: 27.5%
mean deviation: 1.6403124394477397%
Sharpe ratio: -0.599092330855509
Sortino ratio: -0.9589200009261966
calmar ratio: -9.081044783748151
max drawdown: 10.250399516075348%
```

![image](https://github.com/VladKochetov007/quick_trade/blob/master/img/multi_backtest_example.png?raw=true)
Expand Down
16 changes: 10 additions & 6 deletions docs/docs/quick_trade/trading_sys.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,16 @@ trader.multi_backtest(test_config={'BTC/USDT': [strategy],
output:

```commandline
losses: 146
trades: 214
profits: 68
mean year percentage profit: -92.25033539138768%
winrate: 31.566354534845413%
mean deviation: 4.637481539757627%
losses: 131
trades: 187
profits: 56
mean year percentage profit: -99.98292595327236%
winrate: 30.352119656186698%
mean deviation: 1.3564893692018003%
Sharpe ratio: -11.951556929509964
Sortino ratio: -18.561188937509858
calmar ratio: -8.002808500501935
max drawdown: 12.493479751140047%
```

![image](https://github.com/VladKochetov007/quick_trade/blob/master/img/multi_backtest.png?raw=true)
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/quick_trade/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ get all supertrend data as `pd.DataFrame`:

## get_exponential_growth

Function for calculating [Compound interest](https://investmentu.com/simple-interest-vs-compound-interest/)
Function for calculating [compound interest](https://investmentu.com/simple-interest-vs-compound-interest/)

| param | type | description |
| :---: | :---: | :---: |
Expand Down Expand Up @@ -207,7 +207,7 @@ Decorator. If AssertionError was called, then first the error is written to the

## get_diff

Function for getting the price movement from the current one to TP or SL. Mainly SL
Function for getting the price movement from the current one to TP or SL.

| param | type | description |
| :---: | :---: | :---: |
Expand Down
Binary file modified img/multi_backtest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/multi_backtest_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/simple_backtest_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions quick_trade/trading_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,11 @@ def backtest(self,
signal=sig)
else:
diff = 0.0
if sig == utils.SELL:
diff = -diff

if not no_order:
deposit += bet * credit_lev * diff / open_price
if sig == utils.BUY:
deposit += bet * credit_lev * diff / open_price
elif sig == utils.SELL:
deposit *= 1/((data_column[e] + diff)/data_column[e])
self.deposit_history.append(deposit)

no_order = exit_take_stop
Expand Down
18 changes: 4 additions & 14 deletions quick_trade/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
RETURNS_ALPHA: float = 1.0

DATA_TITLE: str = 'D A T A'
DATA_NAME: str = '{0} {1}' # '{} {}'.format(Trader.ticker, Trader.interval)
DATA_NAME: str = '{0} {1}' # .format(Trader.ticker, Trader.interval)
DATA_UP_COLOR = 'green'
DATA_DOWN_COLOR = 'red'
DATA_ALPHA: float = 1.0
Expand Down Expand Up @@ -172,14 +172,14 @@
calmar ratio: {}
max drawdown: {}%""" # .format(Trader.losses, Trader.trades, ...)

__version__: str = "6.8.1"
__version__: str = "6.9.0"
__author__: str = 'Vlad Kochetov'
__credits__: List[str] = [
"Hemerson Tacon -- Stack overflow",
"hpaulj -- Stack overflow",
"furas -- Stack overflow",
"Devin Jeanpierre (edit: wjandrea) -- Stack overflow",
"Войтенко Миколай Полікарпович (Vojtenko Nikolay Polikarpovich) -- helped me test the system of interaction with the binance crypto exchange",
"Войтенко Миколай Полікарпович (Vojtenko Mykolay Polikarpovich) -- helped me test the system of interaction with the binance crypto exchange",
"https://fxgears.com/index.php?threads/how-to-acquire-free-historical-tick-and-bar-data-for-algo-trading-and-backtesting-in-2020-stocks-forex-and-crypto-currency.1229/#post-19305 -- binance get historical data method",
"https://www.geeksforgeeks.org/python-different-ways-to-kill-a-thread/ and https://teletype.in/@cozy_codespace/Hk70-Ntl4 -- heroku and threading problems",
"https://stackoverflow.com/questions/57838939/handling-exceptions-with-bulk-api-requests -- IEX token",
Expand Down Expand Up @@ -237,20 +237,12 @@ def get_supertrend_lower(self) -> Series:
return self._all['ST_lower']

def get_supertrend_strategy_returns(self) -> Series:
"""
:return: pd.Series with 1 or -1 (buy, sell)
"""
return self._all['ST_strategy']

def get_all_ST(self) -> DataFrame:
return self._all

def _get_all_ST(self) -> DataFrame:
"""
ST Indicator, trading predictions, ST high/low
"""
m = self.close.size
dir_, trend = [1] * m, [0] * m
long, short = [nan] * m, [nan] * m
Expand Down Expand Up @@ -279,7 +271,6 @@ def _get_all_ST(self) -> DataFrame:
else:
trend[i] = short[i] = upperband.iloc[i]

# Prepare DataFrame to return
df = DataFrame(
{
f"ST": trend,
Expand Down Expand Up @@ -417,8 +408,7 @@ def checker(*args, **kwargs):
if not isinstance(e, KeyboardInterrupt):
if WAIT_SUCCESS_PRINT:
print(f'An error occurred: {e}, repeat request')
logger.error(f'An error occurred: {e}, '
f'args: {args}, kwargs: {kwargs}', exc_info=True)
logger.error(f'An error occurred. args: {args}, kwargs: {kwargs}', exc_info=True)
sleep(WAIT_SUCCESS_SLEEP)
continue
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
with open('README.md') as file:
long_desc = file.read()

__version__ = "6.8.1"
__version__ = "6.9.0"

setup(
name='quick_trade',
Expand Down

0 comments on commit 0213db4

Please sign in to comment.