ctubio / tribeca

Self-hosted crypto trading bot (automated high frequency market making) in node.js, angular, typescript and c++
https://127.0.0.1:3000
Other
95 stars 26 forks source link

IMPROVEMENT: apMode EWMAhalf #7

Closed Camille92 closed 7 years ago

Camille92 commented 7 years ago

Dear Carles and everybody,

Here is another improvement idea for the bot. I think it must be very easy to implement, but I don't know how to code so I post it here if anyone is interested to work on it.

The EWMAbasic tool of Tribeca is very useful as it reduces the exposition of the trader during price moves.

EwmaBasic - Tribeca will use a 200 minute and 100 minute exponential weighted moving average calculation to buy up BTC when the 100 minute line crosses over the 200 minute line, and sell BTC when the reverse happens. The values of 100mins and 200mins are currently not exposed in the UI, but are represented in the code as shortEwma and longEwma.

However it doesn't work the way it is explained. In other word, after a drop in price the tbp position will soon reach 0 and not move from there (until price go back to when tribeca was started).

To fix that issue, the idea would be to auto adjust the position by 1% every minute towards a half fiat half bitcoin position.

An example with someone with 1 bitcoin in his account. Here the price starts at 1000€, drops a 900€ and then moves back to 1000€ With today's system: Tribeca starts with a tbp of 0.5, the price goes down and tbp is soon adjusted to 0. When the price moves back to 1000€ tbp will be 0.5 again.

With an EWMAhalf system: Tribeca will start at 0.5, price drops and tribeca adjusts to 0. After a few moment at 900€, tribeca will slowly adjusts to an half bitcoin half fiat position again. When the price moves back to 1000€, tbp will be full bitcoin until prices are stabilized and will again adjust to a half-half position.

I'm not 100% sure but I think it needs to be added there in position-management.ts l109 https://github.com/ctubio/tribeca/blob/master/src/service/position-management.ts if (this._latest === null || Math.abs(this._latest.data - targetBasePosition ) > 0.01) { this._latest = new Models.TargetBasePositionValue(targetBasePosition, this._timeProvider.utcNow()); this.NewTargetPosition.trigger();

Tell me what you think about it,

Camille

Camille92 commented 7 years ago

fixed #8

ctubio commented 7 years ago

eep Camille'' do you mean that we can close this issue because is fixed in #8?

Camille92 commented 7 years ago

Yes!

It's not perfect but better :)

Camille92 commented 7 years ago

Hey Carles,

After some testing 20 minutes seems to be the best result. It is way quicker than the 1h that was there before and and doesn't create too much noise as 10 minutes does!

ctubio commented 7 years ago

i will try to make this internal ewma values visible in the ui, hopefully in a chart together somehow with the other metrics. until then, is hard for me to understand what is exactly going on with this ewma values.. hope this will help to super tweak it (or help to discover some more missing configs to allow personal tweaks).

Camille92 commented 7 years ago

Yes good idea (as long as it is not taking too much ram ;p).

Here is how it works (from my understanding).

The ewma values are calculated every minute (as for the ewma protection) but in order to avoid having a too bumpy tbp evolution Michael made tribeca "look" at the ewma only once per hour.

It is what creates logs like that: {"name":"rfv","hostname":"c9aa591c2452","pid":14,"level":30,"msg":"recalculated regular fair value, short: 828.76 long: 817.54 target: 1 currentFv: `847.33","time":"2017-01-17T08:24:48.317Z","v":0}

The target represents where tbp should be (it goes from -1 to 1), it is then "translated" to your funding so that -1 means no BTC and 1 means full BTC.

{"name":"positionmanager","hostname":"c9aa591c2452","pid":14,"level":30,"msg":"recalculated target base position: (FULL BTC)","time":"2017-01-17T08:34:51.503Z","v":0}

The level is also adjusted according to real time price, so that if price crosses the short and long ewma etc.

When it was looking at the ewma only once per hour tribeca was less reactive to price change and reversion of price movement.

This small tweaking helps in the bot being more reacting, while still not having a too much noise on the tbp.

ctubio commented 7 years ago

:pencil2: ima leave this here: http://ta-lib.org/function.html http://ta-lib.org/hdr_lnk.html https://github.com/karpathy/convnetjs https://bitcointalk.org/index.php?topic=60501.0 https://github.com/Pascal66/gekko/blob/stable/docs/Trading_methods.md https://www.youtube.com/watch?v=iQyGMHNR614

Camille92 commented 7 years ago

After some more looking I think this was not a "real issue" after all.

Just with the 1h setting previously set it was taking too long to go back to the middle, which I interpreted as never going back. Also it was happening during the btc rally so when I thought it was block it is just that btc was so bullish.

Now with longer longer observation period, i'm sure it is able to go back on its own.