Giter VIP home page Giter VIP logo

Comments (4)

nimo23 avatar nimo23 commented on June 10, 2024

I think, it uses pow because it calculates the geometric average return per bar, because of the compounding nature of returns over multiple bars. But I am not sure..

from ta4j.

nimo23 avatar nimo23 commented on June 10, 2024

Despite the fact that AverageReturnPerBarCriterion includes the ReturnCriterion (with base) which seems to be a bug (because the AverageReturnPerBar implicitly inlcudes 100% and assumes that it's a profit, which is not)

We must include the base here if we use this formula with pow, because if we do not, then if we have a negative number (e.g. return = -0.3) with a fractional exponent, it returns NaN as the result (e.g. Math.pow(-0.3, 0.2) = NaN).

Using simply Return(without base) / NumberOfBars, then it would work. Actually, I don't fully understand why we need to add the compounding effect (with pow) for this use case as we already have the full value of Return which we can simply divide by the number of bars. I think this is more accurate than having pow and "including the base", or am I missing something?

from ta4j.

phong-phuong avatar phong-phuong commented on June 10, 2024

No, we can't simply divide the percent profit by the number of bars, as this does not take into the affect of compounding.
The fractional use of power was used to effectively "undo" the power of compounding in order to correctly calculate the return (on the assumption that ReturnCriterion is implemented correctly).

It is worthwhile to use to spreadsheet to see the effects of the formula to verify one's understanding.

The Return used includes the base as with everything in ta4j.

I think this is what the intended criterion was supposed to calculate:

AvgExcessReturnPerBar = Math.pow(FinalReturnWithBase, 1/NumOfBars) - Base
where NumOfBars is the number of bars after the initial bar.

image

from ta4j.

phong-phuong avatar phong-phuong commented on June 10, 2024

To clarify further, the value returned by the current AverageReturnPerBarCriterion is actually the Return Multiple.
By that, I mean, if it returns a value of 2, this means the account is doubled every bar on average.

This is not to be confused with the absolute or dollar value.

Two sides of the same coin:

1x return = 100% return = 0% profit after subtracting base
2x return = 200% return = 100% profit after subtracting base
...
10x return = 1000% return = 900% profit after subtracting base

from ta4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.