Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
VladKochetov007 committed Oct 27, 2021
1 parent 0ed06cf commit cfd7053
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion quick_trade/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def plot_deposit(self):
_col=self.deposit_col)

def plot_returns(self):
self.plot_line(line=self.trader.recurrent_returns,
self.plot_line(line=self.trader.net_returns,
width=utils.RETURNS_WIDTH,
opacity=utils.RETURNS_ALPHA,
color=utils.RETURNS_COLOR,
Expand Down
24 changes: 11 additions & 13 deletions quick_trade/trading_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Trader(object):
client: TradingClient
__last_stop_loss: float
__last_take_profit: float
recurrent_returns: pd.Series
net_returns: pd.Series
_sec_interval: int
supports: Dict[int, float]
resistances: Dict[int, float]
Expand All @@ -79,20 +79,18 @@ def mean_deviation(self) -> float:

@property
def cumulative_returns(self) -> pd.Series:
dh = pd.Series(self.deposit_history)
returns = (dh / dh.shift(1) - 1.0)[1:]
return pd.Series(np.cumprod(returns + 1))
return pd.Series(self.deposit_history) / self.deposit_history[0]

@property
def sharpe_ratio(self) -> float:
returns = self.recurrent_returns
returns = utils.get_multipliers(pd.Series(self.deposit_history)) - 1
mean_ = returns.mean() * self._profit_calculate_coef
sigma = returns.std() * np.sqrt(self._profit_calculate_coef)
return mean_ / sigma

@property
def sortino_ratio(self) -> float:
returns = self.recurrent_returns
returns = utils.get_multipliers(pd.Series(self.deposit_history)) - 1
mean_ = returns.mean() * self._profit_calculate_coef
sigma = returns[returns < 0].std() * np.sqrt(self._profit_calculate_coef)
return mean_ / sigma
Expand Down Expand Up @@ -484,8 +482,8 @@ def backtest(self,
prev_sig = sig
ignore_breakout = False

self.recurrent_returns = pd.Series(self.deposit_history).diff()
self.recurrent_returns[0] = 0
self.net_returns = pd.Series(self.deposit_history).diff()
self.net_returns[0] = 0
if not pass_math:
self.year_profit = utils.profit_factor(self.average_growth) ** (self._profit_calculate_coef - 1)
# Compound interest. View https://www.investopedia.com/terms/c/compoundinterest.asp
Expand All @@ -501,7 +499,7 @@ def backtest(self,
print(self._info)
self.backtest_out = pd.DataFrame(
(self.deposit_history, self._stop_losses, self._take_profits, self.returns,
self._open_lot_prices, data_column, self.average_growth, self.recurrent_returns, self.cumulative_returns),
self._open_lot_prices, data_column, self.average_growth, self.net_returns, self.cumulative_returns),
index=[
'deposit', 'stop loss', 'take profit',
'predictions', 'open trade', 'Close',
Expand Down Expand Up @@ -599,10 +597,10 @@ def multi_backtest(self,
multipliers: pd.Series = sum(depos) / len(depos)
multipliers[0] = deposit
self.deposit_history = list(np.cumprod(multipliers.values))
self.recurrent_returns = pd.Series(self.deposit_history).diff()
self.recurrent_returns[0] = 0
self.net_returns = pd.Series(self.deposit_history).diff()
self.net_returns[0] = 0
self.backtest_out = pd.DataFrame(
(self.deposit_history, self.average_growth, self.recurrent_returns, self.cumulative_returns),
(self.deposit_history, self.average_growth, self.net_returns, self.cumulative_returns),
index=[
'deposit',
"average growth deposit data",
Expand Down Expand Up @@ -843,7 +841,7 @@ def realtime_trading(self,
while True:
if datetime.now() >= start_time:
break
open_time = time()
open_time = start_time
while True:
self.df = self.client.get_data_historical(ticker=self.ticker, limit=limit, interval=self.interval)
utils.logger.debug("(%s) new dataframe loaded", self)
Expand Down
2 changes: 1 addition & 1 deletion quick_trade/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
calmar ratio: {}
max drawdown: {}%""" # .format(Trader.losses, Trader.trades, ...)

__version__: str = "6.7.9"
__version__: str = "6.8.0"
__author__: str = 'Vlad Kochetov'
__credits__: List[str] = [
"Hemerson Tacon -- Stack overflow",
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.7.9"
__version__ = "6.8.0"

setup(
name='quick_trade',
Expand Down

0 comments on commit cfd7053

Please sign in to comment.