bestnaf / ARS

ARS addon for Gunbot MM
https://gunbot.ru
10 stars 2 forks source link

Dynamic Allocation #23

Open tr0lldermort opened 3 years ago

tr0lldermort commented 3 years ago

Description

Dynamic Allocation is a function designed to stretch the DCA budget (Pos Lim) & stop losses (Stop Loss / uPNLK) for positions that require more room to survive a strong market movement, without the user having to set very large stop losses across the board (or alter their stops on-the-fly). DA will also inhibit new positions from opening if the total wallet allocation fund % has been consumed by open positions. This function is especially useful when trading 8 pairs or more.

The global variable (DA_WALLET_PERC) sets how much wallet balance is to be allocated to stops at any given time. A pair variable (DA_FACTOR_LIM) sets the maximum multiplication factor that DA is allowed to use for each pair.

If a position's -uPNL approaches a stop loss, and the sum of all the active stop losses is < DA_WALLET_PERC, DA will incrementally increase the existing parameters SL_LIMIT, SL_MAX, uPNLK_LIM and POS_LIMIT_PERC, by multiplying them all with an internal variable called DA_X. However, the multiplication effect on POS_LIMIT_PERC can be switched on or off.

DA_X starts at 1 for all pairs (no modification to settings), and increases by 0.1 each time position -uPNL gets within 0.5% boundary of current stop loss (DA_BOUNDARY). Current stop loss is calulated by multiplying the "active" config stop loss by DA_X (determining "active" config stop loss is covered below). This continues until either DA_FACTOR_LIM or DA_WALLET_PERC is reached.

If DA_WALLET_PERC is reached, DA also inhibits GB from opening any new positions until one or more current positions close, at which point the sum of all the stops becomes < DA_WALLET_PERC and GB can open again. Additionally, a buffer value is specified to inhibit GB from opening positions before DA_WALLET_PERC is reached. This value is called DA_BUFFER. The global inhibit function becomes:

_if (total SL + DA_BUFFER) < DA_WALLET_PERC then allow to open, otherwise inhibit._

For each pair, DA_X can only increase whilst a position is open - meaning that if uPNL goes very negative but then recovers and goes positive, the maximum DA_X remains applied for the duration of the position until it closes (similar to liquidation spread).

DA will detect which stop loss parameter is "active" via STOP_LOSS and uPNLK switches. This will determine whether SL_MAX or uPNLK_LIM is used. If both functions are set to true, then DA will use the highest value of either when calculating the current stop loss load across all pairs.

ARS may need to store values for DA_X and others in this function, so that they are presistent between restarts.

Example Flow Diagram

Due to the somewhat complex nature of this function, a flow diagram is used to help illustrate the concept:

DA_2

Config Parameters

Global Settings (at top of file, not per pair) self.DA_WALLET_PERC = 30 # maximum wallet % allowed to allocate to stops at any given time

Pair Settings pair.settings.DA = True pair.settings.DA_FACTOR_LIM = 3.5 # maximum multiplication factor that DA is allowed to go up to pair.settings.DA_BOUNDARY = 0.5 _# sets the boundary from current SL which -uPNL must breach before DAX is increased pair.settings.DA_BUFFER = 10 # this value is added onto the total SL when ARS is caluclating whether GB should be allowed to open positions or not. This will inhibit GB from opening positions before DA WALLET PERC is reached, if the user wishes pair.settings.DA_POS_LIM = False # enable or disable the DA X coefficient on POS LIMIT PERC

tr0lldermort commented 3 years ago

Updated request to include DA_POS_LIM, DA_BUFFER and ammended diagram to show where DA_BOUNDARY is used