oceanprotocol / pdr-backend

Instructions & code to run predictoors, traders, more.
Apache License 2.0
26 stars 18 forks source link

[Pdr bot] Add approach 3: like approach 2, but one-sided difference of (larger - smaller) #889

Closed trentmc closed 3 months ago

trentmc commented 3 months ago

Background / motivation

What: like approach 2, but one-sided difference of (larger - smaller)

Context: Jaime in slack here. Copy is below.

TODOs / DoD

Implementation of calc_stakes3()

def calc_stakes3(self) -> Tuple[Eth, Eth]:
        """
        @description
          Calculate up-vs-down stake according to approach 3.
          How: Like approach 2, but one-sided difference of (larger - smaller)

        @return
          stake_up -- amt to stake up, in units of Eth
          stake_down -- amt to stake down, ""
        """
        (stake_up2, stake_down2) = self.calc_stakes2()
        if stake_up2 == stake_down2:
            return 0

        if stake_up2 > stake_down2:
            return (stake_up2 - stake_down2, 0)

        # stake_up2 < stake_down2
        return (0, stake_down2 - stake_up2)
trentmc commented 3 months ago

FYI @jfdelgad @trizin

trentmc commented 3 months ago

[Copy of Jaime's slack msg]

both sides Vs single side.

The models that we have been using are betting on both sides, with stakes weighted towards the predicted class, based on the classifier score. This means that if your stake is 100 and the predicted class is UP with an score p of 0.6, the bot stakes 60 to UP and 40 to DOWN.

However, numerically this is equivalent to stake in one side (UP) with a stake amount that is given by this expression stake*(2*p-1) in fact the both sides strategy can be seen as a combination of 50/50 + one side. In the example above this can be seen as staking 40 in both sides and then 20 in one side (the predicted side)

I tested this by launching a new bot that only stakes in one side using stake*(2*p-1) on the predicted side. To make this comparable with the current bot that does both side, I use the same value for stake in both bots and the same prediction models. The figure shows returns across time for both models starting around 5PM of April 4 until today. (real predictions with real tokens)

As you see the models perform almost the same, the variations are due to the 50/50 part of both sides as I explained above. Using the single side method consumes about half of the gas fees and leads to the same roughly the same returns, also it requires significantly less tokens to be used for stake. In the example in the figure, the both side method has 490 tokens at stake at any time, while the single side has stakes changing over time with a mean of 32 tokens at stake at any time.

In conclusion, if you have a lot of Ocean, perhaps the both side method is a good idea, If you do not have a large reserve of ocean, the single side method is the way to go. In both scenarios, it is assumed that your classifier is better than a random choice (ofcourse).

Finally, it is worth nothing that you need to size your bets based on how much you have and the accuracy of the classifier. It is important to note that using the scores to weight the bets seems to work but assumes that your token reserve is higher than your stake because statistically you can still be wrong several time in a row (see in the image below the amount of token lost around midnight of April 4.

More about the size of the bets in a next post, as a curiosity, notice that stake (2*p-1) happens to be the result of the Kelly criterion when the odds are 1:1 and the accuracy is p. but p is not the correct parameter if you do not want to go bankrupt assuming that your bankroll is stake.

image