Skip to content

Commit

Permalink
Merge pull request #102 from VladKochetov007/dev
Browse files Browse the repository at this point in the history
3.6.8: tuner rules and little backtest's info debug
  • Loading branch information
VladKochetov007 authored Aug 4, 2021
2 parents 64a1620 + 2aba179 commit 3a17148
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# quick_trade
[![Downloads](https://pepy.tech/badge/quick-trade)](https://pepy.tech/project/quick-trade)
[![Downloads](https://static.pepy.tech/personalized-badge/quick-trade?period=total&units=none&left_color=grey&right_color=brightgreen&left_text=PyPi%20downloads)](https://pepy.tech/project/quick-trade)
[![Downloads](https://static.pepy.tech/personalized-badge/quick-trade?period=month&units=none&left_color=grey&right_color=brightgreen&left_text=PyPi%20downloads%20(month))](https://pepy.tech/project/quick-trade)

View documentation: 🚧 https://vladkochetov007.github.io/quick_trade/#/ 🚧 in process

Expand Down Expand Up @@ -119,6 +120,23 @@ tuner = QuickTradeTuner(
tuner.tune(Test)
print(tuner.sort_tunes())
tuner.save_tunes('quick-trade-tunes.json') # save tunes as JSON

```
You can also set rules for arranging arguments for each strategy by using `_RULES_` and `kwargs` to access the values of the arguments:

```python
params = {
'strategy_3_sma':
[
dict(
plot=False,
slow=Choise([2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597]),
fast=Choise([2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597]),
mid=Choise([2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597]),
_RULES_='kwargs["slow"] > kwargs["mid"] > kwargs["fast"]'
)
],
}
```

## Installing:
Expand All @@ -128,6 +146,7 @@ $ git clone https://github.com/VladKochetov007/quick_trade.git
$ pip3 install -r quick_trade/requirements.txt
$ cd quick_trade
$ python3 setup.py install
$ cd ..
```

or
Expand Down
5 changes: 3 additions & 2 deletions quick_trade/quick_trade_tuner/tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self,
:param tickers: ticker
:param intervals: list of intervals -> ['1m', '4h'...]
:param limits: limits for client.get_data_historical ([1000, 700...])
:param strategies_kwargs: kwargs for strategies: {'strategy_supertrend': [{'multiplier': 10}]}, you can use Choice, Linspace, Arange as argument's value and recourse it
:param strategies_kwargs: kwargs for strategies: {'strategy_supertrend': [{'multiplier': 10}]}, you can use Choice, Linspace, Arange as argument's value and recourse it. You can also set rules for arranging arguments for each strategy by using _RULES_ and kwargs to access the values of the arguments.
"""
strategies_kwargs = transform_all_tunable_values(strategies_kwargs)
Expand All @@ -45,7 +45,8 @@ def __init__(self,
self.client = client
for strategy in strategies:
for kwargs in strategies_kwargs[strategy]:
self._strategies.append([strategy, kwargs])
if eval(kwargs.get('_RULES_', 'True')):
self._strategies.append([strategy, kwargs])

def tune(
self,
Expand Down
23 changes: 13 additions & 10 deletions quick_trade/trading_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# decimal
# 3.9
# decorator for strategies without exit condition (not converted data)
# quick-trade-tuner arguments blacklist
# multi-backtest normal calculating(real multi-test, not sum of single tests)
# add meta-data in tuner's returns

from copy import copy
from datetime import datetime
Expand Down Expand Up @@ -336,18 +336,29 @@ def backtest(self,
data_low[1:])):

if converted_element is not nan:
# count the number of profitable and unprofitable trades.
if prev_sig != utils.EXIT:
self.trades += 1
if deposit > moneys_open_bet:
self.profits += 1
elif deposit < moneys_open_bet:
self.losses += 1

# calculating commission
if prev_sig != utils.EXIT:
commission_reuse = 2
else:
commission_reuse = 1
bet = start_bet
if bet > deposit:
bet = deposit
open_price = data_column[e]
for i in range(commission_reuse):
deposit -= bet * (commission / 100) * credit_lev
if bet > deposit:
bet = deposit

# reset service variables
open_price = data_column[e]
moneys_open_bet = deposit
no_order = False
exit_take_stop = False
Expand Down Expand Up @@ -405,14 +416,6 @@ def backtest(self,
deposit += bet * credit_lev * diff / open_price
self.deposit_history.append(deposit)

if converted_element is not nan:
if prev_sig != utils.EXIT:
self.trades += 1
if deposit > moneys_open_bet:
self.profits += 1
elif deposit < moneys_open_bet:
self.losses += 1

no_order = exit_take_stop
prev_sig = sig
ignore_breakout = False
Expand Down
4 changes: 2 additions & 2 deletions quick_trade/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
mean year percentage profit: {}%
winrate: {}%""" # .format(Trader.losses, Trader.trades, Trader.profits, Trader.year_profit, Trader.winrate)

__version__: str = "6.3.7"
__version__: str = "6.3.8"
__author__: str = 'Vlad Kochetov'
__credits__: List[str] = [
"Hemerson Tacon -- Stack overflow",
Expand Down Expand Up @@ -415,7 +415,7 @@ def checker(*args, **kwargs):
return checker


def root(x: float, pwr: float = 2) -> float:
def root(x: float, pwr: float = 2.0) -> float:
return x ** (1 / pwr)


Expand Down
3 changes: 2 additions & 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.3.7"
__version__ = "6.3.8"

setup(
name='quick_trade',
Expand All @@ -26,6 +26,7 @@
'numpy==1.21.1',
'pandas==1.3.1',
'ta==0.7.0',
'tqdm==4.6.2'
'ccxt==1.54.44'
],
download_url=f'https://github.com/VladKochetov007/quick_trade/archive/{__version__}.tar.gz',
Expand Down

0 comments on commit 3a17148

Please sign in to comment.