Comments (4)
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.
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.
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.
from ta4j.
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)
- Zig Zag indicator implementation question HOT 3
- Create releases more often HOT 23
- Trade style specific question [Support and resistence] HOT 8
- Can ta4j backtest trading multiple stocks simultaneously HOT 2
- [BUG] ProfitLossCriterion: Javadoc says "excludes trading costs" but code uses trading cost HOT 5
- Backtest with fixed entry amount like a new BarSeriesManager or Strategy
- [BUG] VersusEnterAndHoldCriterion should use 'amount' to match comparsion
- [BUG]
- Suggestion for improving the organization of the proyect folders and classes HOT 4
- [BUG] HOT 1
- Suggestion to secure the correct functionality of the library HOT 3
- SMAIndicator inner cache
- Improve stability propagation HOT 7
- Distinction between Rule and Indicator HOT 2
- Move minimal supported base JDK at least to JDK 21 HOT 1
- Indicator and BarSerie should not be responsible for managing constants nor series HOT 2
- Implement reversal candles indicator
- [BUG] Contractf of Num.compareTo is broken
- how to test a strategy with averaging? HOT 3
- [BUG] VarianceIndicator calculation seems to be wrong HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ta4j.