trading_sys:

The main file of quick_trade.

PatternFinder

  • A class in which you can test and create trading strategies following these rules:
    • exit from the deal - 2.
    • buy - 1.
    • sell - 0.
    • the output of the strategy function has a list format:
      • [... 1, 1, 1, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0 ...]
df = yf.download(TICKER, period='5y', interval='1d')
trader = PatternFinder(TICKER, df=df, interval='1d')  #  please, use your df

set_client

This must be run for get_trading_predict and realtime_trading. This method must be passed a class inherited from TradingClient.

kalman_filter

A method that returns the closure data to which the kalman filter has been applied N times. Ret type: pd.DataFrame

trader.set_pyplot()
filtered = trader.scipy_filter()
trader.strategy_diff(filtered)

scipy_filter

A method that returns the closure data to which the scipy.signal.savgol_filter filter has been applied. Ret type: pd.DataFrame

trader.set_pyplot()
filtered = trader.kalman_filter()
trader.strategy_diff(filtered)

bull_power

Bull power indicator. Ret type: np.array

filtered = trader.bull_power(900)
trader.strategy_diff(filtered)

tema

Triple exponential moмing averageю. Ret type: pd.DataFrame

filtered = trader.tema(70)
trader.strategy_diff(filtered)

linear_

A function to get linear data from an argument. Ret type: np.array

get_stop_take

Converts take profit and stop loss from points to specific numbers. It uses self.stop_loss, self.open_price, self.take_profit and signal. Ret type: dict

{'stop': stop_loss,
'take': take_profit}

strategy_diff

Strategy based on changing the input data (pd.DataFrame). Ret type: list of predicts.

trader.strategy_diff(trader.df['Close'])

strategy_N_ema / strategy_N_sma

Moving average strategy.

image

strategy_macd

MACD strategy. MACD, MACD signal

image

strategy_exp_diff

Strategy_diff from tema of close.

strategy_rsi

RSI strategy.

and:

strategy_macd_rsi

if macd > 0 and rsi > N : buy.

if macd < 0 and rsi < N : sell.

strategy_parabolic_SAR

PSAR strategy

strategy_macd_histogram_diff

Based on MACD histogram.

image

get_network_regression

A method that creates a neural network for regression. Based on https://medium.com/@randerson112358/stock-price-prediction-using-python-machine-learning-e82a039ac2bb

strategy_regression_model

A method that creates a series of neural network predictions from closure data. After that, the method produces strategy_diff and returns a tuple of predictions for trading and neural network predictions.

TICKER = 'EUR=X'
df = yf.download(TICKER)
trader = PatternFinder(TICKER, df=df, interval='1d')
trader.set_pyplot()
trader.load_model('../model-regression')
trader.strategy_regression_model()

or

TICKER = 'EUR=X'
df = yf.download(TICKER)
trader = PatternFinder(TICKER, df=df, interval='1d')
trader.set_pyplot()
trader.get_network_regression([df])
trader.strategy_regression_model()

get_trained_network

A method that creates a trained neural network for predictions consisting of buy, sell, exit. The neural network receives data from ta.add_all_ta_features (my_df, fill_na = True).

trading predictions are based on the Kalman or scipy filter that smoothes the data (and scaled ta.add_all_ta_features()).

TICKER = 'EUR=X'
df = yf.download(TICKER)
trader = PatternFinder(TICKER, df=df, interval='1d')
trader.set_pyplot()
trader.get_trained_network([df])
trader.strategy_with_network()

strategy_with_network

Strategy using a neural network made by the get_trained_network method.

inverse_strategy

Inverts signals in self.returns.

- buy - sell
- sell - buy
- exit - exit

basic_backtest

Makes a backtest of the strategy, taking into account your parameters. Returns pd.DataFrame with all metadata. The console displays data containing information about the deposit.

set_pyplot

To set plotly subplots 2x1

strategy_collider

Colliding 2 strategies. standard mode:

[1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2]
[2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 0, 0, 0]
                                                                  to this
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]

maximalist mode:

[1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2]
[2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 0, 0, 0]
                                                                  to this
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

super mode:

[1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2]
[2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 0, 0, 0]
                                                                  to this
[2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 2, 2, 2, 2, 0, 0, 1, 2, 1, 0, 0, 0, 2, 0, 0, 0, 1, 1, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2]

example of the code:

TICKER = 'EUR=X'
df = yf.download(TICKER)
trader = PatternFinder(TICKER, df=df, interval='1d')
trader.set_pyplot()
trader.returns = [1,1,1,1,1,1,0,0,0,0,2,2,2,2,2,2,2,1,1,1,1,1,1,0,0,0,1,1,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,2]
ret2 = [2,2,2,2,2,2,2,2,1,1,1,1,1,1,0,0,1,0,1,0,0,0,2,2,2,2,2,2,0,0,0,0,0,0,1,1,1,1,2,2,2,2,2,2,0,0,0]
trader.strategy_collider(args_first_func=(trader.returns,), args_second_func=(ret2,), mode='super')

get_trading_predict

Getting the trading predict based on current returnsю

realtime_trading

To trading on real-time.

log_deposit / log_data

Log X-axis on data/depositю

backtest

Similar to a basic_backtest, but a candlestick deposit.

load_model

Loading model from path.

prepare_scaler

If you are using a loaded neural network, you need to prepare a scaler suitable for the perception of the neural network.

find_N

Strategy using trading patterns.

strategy_random_pred

This strategy produces random results.

is_doji

Returns a list from T / F. If the opening price of the candlestick is equal to the closing price, then this is Doji (True)

convert_signal

A method that replaces signal №1 with signal №2

strategy_bollinger

Bollinger bands strategy. to_mid: the trade is closed when the average MA is reached.

TradingClient

This class is needed for receiving data and trading, if you want to trade on your system and receive data not from binance, inherit this class and change the code in your class for your system.

class TradingClient(Client):
    ordered = False

    def get_ticker_price(self, ticker):
        return float(self.get_symbol_ticker(symbol=ticker)['price'])

    def get_data(self, ticker=None, interval=None, **get_kw):
        return get_binance_data(ticker, interval, **get_kw)

    def new_order_buy(self, ticker=None, quantity=None, credit_leverage=None):
        self.__side__ = 'Buy'
        self.quantity = quantity
        self.ticker = ticker
        self.order = self.order_market_buy(symbol=ticker, quantity=quantity)
        self.order_id = self.order['orderId']
        self.ordered = True

    def new_order_sell(self, ticker=None, quantity=None, credit_leverage=None):
        self.__side__ = 'Sell'
        self.quantity = quantity
        self.ticker = ticker
        self.order = self.order_market_sell(symbol=ticker, quantity=quantity)
        self.order_id = self.order['orderId']
        self.ordered = True

    def exit_last_order(self):
        if self.ordered:
            if self.__side__ == 'Sell':
                self.new_order_buy(self.ticker, self.quantity)
            elif self.__side__ == 'Buy':
                self.new_order_sell(self.ticker, self.quantity)
            self.__side__ = 'Exit'
            self.ordered = False

    def get_balance_ticker(self, ticker):
        for asset in self.get_account()['balances']:
            if asset['asset'] == ticker:
                return float(asset['free'])

Each of these methods needs to be rewritten for your system.