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: New ApMode -> 3 EWMA System #115

Closed Camille92 closed 7 years ago

Camille92 commented 7 years ago

Hello Carles and everyone,

I keep going with my "one improvement a week" idea, but this one is easy to implement and will, hopefully, give big rewards.

The concept is to ameliorate today's ewma basic by adding to it more ewma. Originally this is a scalping strategy that I adapted for Tribeca. It should be faster to react to the market while still keeping into account longer ewma. Read more here https://www.forexstrategiesresources.com/scalping-forex-strategies/2-scalp-with-emapredictive/ and here http://www.profitf.com/forex-strategies/3-ema-scalping-system-1-min/

1) Necessary and configurable parts:

Recommanded default values: ewmaLong : 200, ewmaMedium: 100, ewmaShort: 50, sensibility: 0.5%

The sensibility represents the % you have between 2 ewma to activate a target position of nothing or everything. It is currently configured at 0.2% for Tribeca. I recommend using 0.5% because we're going to add percentages.

2) Calculation:

Here is the original formula of EWMA basic: let newTargetPosition = ((this.newShort * 100/ this.newLong) - 100) * 5; in https://github.com/ctubio/tribeca/blob/master/src/server/position-management.ts

If 3EWMA mode is activated, here is what the calculation should look like:

let newTrend = ((this.SMA3 100/ this.newLong) - 100); let newEwmacrossing = ((this.newShort 100/ this.newMedium) - 100); let newTargetPosition = ((this.trend + this.ewmacrossing)/2) * (1/sensibility);

3) Explanation

What we do here is to determine a trend, so if the market is above or under the ewmaLong and we add to it a shorter term crossover.

If the trend is up new Trend will be positive and add positive value to the TP calculation. If it's negative, it will give a negative value to TP calculation. Same for ewma crossing.

In practice, it means that -> if we have both a positive crossing and the market above the trend line, TBP position will be high.

If both are negative -> TP will close to 0

If one is negative and the other one positive, TP will be around neutral and its sign will depend on the strength of the movement.

4) Comparison with EWMA Basic:

3 ewma: (50,100, 200) capture d ecran 2017-05-31 a 17 56 47 ewma classic: (100, 200) capture d ecran 2017-05-31 a 17 56 13

Please tell me what you think and if you have any questions!

Ps: We can link that to #114 with the idea of making ewmaShort, Long, sensibility and time interval customizable !

ctubio commented 7 years ago

so this is to replace the current EWMABasic (long and short) with 3 (long, medium, short?)

or you wanna keep current EWMABasic functionality available to be selected too?

Camille92 commented 7 years ago

I think keeping the Ewma basic can't hurt! And it follows the logic of the "more option the better".

I wanted to do it, but I don't know where is the length of an ewma defined in Tribeca.

Ps: Thank you for the "genius improvement" I'm very flattered!

ctubio commented 7 years ago

coOl ok lets keep all options :dancer:

i believe thats what caused all my confusion with ewma value, cos at the end is pretty simple concept xD

the issue is that currently tribeca calculcates the ewma values using the accumulated calculated value, not the sequence of recorded values.

Using https://github.com/ctubio/tribeca/blob/master/src/server/main.ts#L76 at https://github.com/ctubio/tribeca/blob/master/src/server/statistics.ts#L44 where newValue is the current fair value, alpha is a variable representing both ewmaLong and ewmaShort defined at the top of main.ts (first link), and previous is the last ewma value calculated,

So, every 10 minutes - lets say, tribeca takes the fair value, the last ewma, and the magic factor ewmaLong or ewmaShort from main.ts to calculate the next current ewma value. no need for a sequence.

Then, if we want to modify this as you said, or we start using a sequecnce of recorded periods with customizable length, or otherwise we need to work with this magic factor value, that is not easy to understand at the first glance for the normal (like me) user. (is neat for computing resources, but is not easy to make use of it from the human point of view)

how feels in your body? xD

Camille92 commented 7 years ago

Hum I see,

I'm not 100% sure how to adjust this vector. Is 4*0.095 then the ewma 50?

Otherwise, I bumped into that googling https://github.com/fredrick/gauss#vectorema would that be easier and efficient?

ctubio commented 7 years ago

yea lets grab that function xD seems more robust for sure; then lets continue trying to customize it using the new ewma function xD awesome plan'¡

Camille92 commented 7 years ago

Yeahh! So cool and it offers a lot of stats tools to play with them after! :)

Camille92 commented 7 years ago

Ps: For the sake of easy comparison with ewma classic in the definition of sensibility. I think it's better to use the average of 2. It doesn't change anything but we're still able to use the 0.2% setting like before :)

So: let newTargetPosition = ((this.trend + this.ewmacrossing)/2) * (1/sensibility)

ctubio commented 7 years ago

ok so now we have medium ewma, but i dont think sensibility should be a customizable value (cos i dont see it as an option in any other charts out there where you can confiugure some ewmas [not because i have an idea xD])

do you really think sensibility should be customizable?

Camille92 commented 7 years ago

Hey yes, I still think so haha.

It can be seen as a trigger in case of false breakout, it can be particularly interesting if someone chooses to use smaller ewma :).

You can find an example here https://gekko.wizb.it/docs/strategies/example_strategies.html

it's what's usually referred to as the "threshold" :)

Camille92 commented 7 years ago

A general argument in favor of customization is that any trading strategy, as good as it can be if it is used by a lot of people will not work at all.

So by having different settings we assure that the probability for two Tribeca' users to have the same strategy is greatly reduced. In the end, this makes Tribeca stronger for having extra people to use it without killing everyone's profit :)

ctubio commented 7 years ago

ok so, 1 sensibility or 2 customizable sensibilities?

cos we have ewma protection but also ewma position rebalancing :S

ty for your time''

Camille92 commented 7 years ago

Only one for the ewma position rebalancing because this one acts as a "buffer" to TBP. It allows having values between 0 and full BTC for your tbp.

The other one is just a protection, using the ewma as a minimum value. If we want this one to be more reactive we just change the length of the ewma :)

ctubio commented 7 years ago

ah yea i understand now xD

ctubio commented 7 years ago

ok so last quesiton i hope: what means SMA3 in:

let newTrend = ((this.SMA3 * 100/ this.newLong) - 100);
let newEwmacrossing = ((this.newShort * 100/ this.newMedium) - 100);
let newTargetPosition = ((this.newTrend + this.newEwmacrossing)/2) * (1/sensibility);

SMA3 is the result of calculate the ewma of the fair value using 3 periods? so the alpha variable for SMA3 should be: 2 / (3 + 1), no?

theen.. is not ewma3 same as sma3? xD

Camille92 commented 7 years ago

Hey no problem for the questions,

SMA is the simple moving average of the price it means: SMA(3) = (FV(-2) + FV (-1) + FV (latest)) /3

But after looking at a chart they look very very very similar so EWMA 3 or 5 or SMA 3 or 5 should all do the job perfeclty. (Look at the chart below).

What we need here is just a very very short average that reflects the current price BUT are not subject to a 1mn explosion of the price. :)

capture d ecran 2017-06-04 a 21 02 15

ctubio commented 7 years ago

ok finally something easy :D many thanks'¡

ctubio commented 7 years ago

hope you dont miss nothing'¡ as far as i could test is niiiiice

ctubio commented 7 years ago

ah yea we miss EwmaBasic now xD will recover tomorrow

Camille92 commented 7 years ago

Yess it looks good!

I need a few days to see if it's giving good results as expected but so far so good!