-
Notifications
You must be signed in to change notification settings - Fork 15
Stretching the Funds
In early iterations QUANTITY per trade was a setting. Viably trading over COVERAGE was assured by calculating a BDI where buy down orders could still be placed for QUANTITY down to the market price where COVERAGE would be exhausted. Now that BDI is set and quantity is variable, the current implementation solves the resulting equation below for QB. The reason for the switch is explained at the end of this page.
I'm guessing I way overcomplicated this and there's a simpler solution, but here's what I came up with originally to stretch the funds where BDI was being calculated.
MP = Current market price ($)
Bal = Current account balance to trade with ($)
f = Fee per transaction (%)
Cov = The drop in market price to cover (%)
QB = Quantity bought per transaction (#)
This static interval (I ) can be expressed by two variables:
- MP∆ – the nominal drop in market price to cover.
- Xact – the # of buy transactions made over the course of the covered drop.
If COVERAGE is 20%, equating to a drop in market price of $100, and 25 buys are made over the course of the drop, then the BDI would have been at $4 increments.
MP∆ can be expressed with COVERAGE(Cov) and MP:
MP and Cov are two knowns so the dividend is solved.
The divisor Xact it more involved. If the price dropped to where COVERAGE was exhausted, then the total cost (CTOT ) will have been equal to the average cost of all buy transaction (CAVE ) multiplied by the # of transactions (Xact ):
So solving for Xact:
If COVERAGE does gets exhausted then the cash balance will be zero. In that case the CTOT will have equalled the cash balance (Bal ) at the beginning of the price drop:
Assuming a quantity of 1, the cost of any buy transaction will be the market price (MP ) plus the fee (f ), which holds true for the average, and since in this case f is a percentage of MP:
or …
Quantity bought (QB ) won't always be 1 so we can add that in. QB is (was) a configurable setting within the bot, so this gives (gave) another known to work with:
Given that the bot's COVERAGE accounts for market movements that trend downward without an intermittent up-tick large enough to trigger a sell, and given that the BDI will be constant during this down trend, then it is known that MPAVE is going to equal the midpoint of MP∆. It is also known from earlier that:
so MPAVE can be represented as …
and reduce …
Substituting knowns into the original equation of:
where …
and …
Bal is known, and it is known that …
and that …
so we can put it all together with knowns:
Which reduces to:
BDI used to be calculated with QUANTITY per trade as a setting. For example if desired coverage was 25%, and the price of the crypto was $100, and QUANTITY was set at 2.0, the bot calculated a static nominal price difference between buy down orders for 2.0 crypto that ensured their affordability down to $75.
When recalculating the BDI over a general downturn this meant it would get larger and larger. Buying the dip means the bot has less funds to work with when recalculating COVERAGE, which occurs whenever there is an intermittent uptick that triggers a sell.
It was observed that when such declines were followed by long-lived price troughs instead of rebounds, a lot of market activity could and often did still occur. With a large BDI outside the range of those price oscillations, opportunities to trade were missed.
In the current implementation BDI is set by the operator and stays constant when protection recalculates. QUANTITY per trade is variably figured instead, and becomes smaller and smaller over general downturns as intermittent sell orders execute. This was a way to trade with more frequency without having to give up COVERAGE. The thinking was it's better to have ten flips for $0.03 than one for $0.10 over the same time period.
An unforeseen downside of this is when quote currency balance gets low, and the calculated QUANTITY is below the exchange's min trade amount allowed, COVERAGE becomes inaccurate. BlueCollar currently favors trading over accurate COVERAGE in this case, and will place the order at the exchange min trade amount allowed.