New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Position#getGrossReturn-addBase #1080
base: master
Are you sure you want to change the base?
Conversation
3eba51e
to
836fbde
Compare
836fbde
to
b3c2d38
Compare
The fact that we include the base/principal in the return value is a choice of convention and not some kind of bug. Unless egregiously off the wall, conventions are neither right or wrong, they are simply a choice. "Correcting" a convention just because it may not have been the one you would have chosen is misguided and only leads to unnecessary complexity. All frameworks and libraries have conventions, if a user is initially confused then the solution is simply to learn and adapt and not cater to every subjective preference out there. By doing the latter we establish precedent and potentially create a slippery slope of supporting all manners of representation variations. Another potential problem with this change is negative returns. In a scenario where one wants to calculate aggregate returns of multiple investments, say, +10%, -2%, and +5% the current representation can correctly calculate it as 1.1 * 0.98 * 1.05 = 1.1254. |
Without my fix, the user doesn't see at first glance whether a
This is not relevant to this PR, as this PR does not exclude any
This fix does not correct any convention. It only gives the user a choice when using the |
But @TheCookieLab If you do not agree with this PR, please create a new PR with the following points:
As long as there is no counter-PR, the above shortcomings and the bug remain. After getting this PR from you, we can decide which one is better (e.g. which PR gives more options for the user) - I guess my PR :) |
@team172011 After this PR has been merged, I will create another PR that removes the |
Fixes #.
Changes proposed in this pull request:
added the parameter
addBase
to the following methods to be able to include or exlude the base from the result. The developer must now make a conscious decision whether to setaddBase
totrue
orfalse
to avoid implicit bugs:Position.getGrossReturn()
toPosition.getGrossReturn(boolean addBase)
Position.getGrossReturn(Num finalPrice)
toPosition.getGrossReturn(Num finalPrice, boolean addBase)
Position.getGrossReturn(BarSeries barSeries)
toPosition.getGrossReturn(BarSeries barSeries, boolean addBase)
Position.getGrossReturn(Num entryPrice, Num exitPrice)
toPosition.getGrossReturn(Num entryPrice, Num exitPrice, boolean addBase)
With the above methods, we now make it explicit, whether a method (e.g.
EnterAndHoldCriterion
) is calculated with or without a basis - this will better avoid future bugs as the developer now must make a conscious choice whether to setaddBase
to true or false.With the above methods, we also solved a bug in
ReturnCriterion#calculate(BarSeries series, Position position)
as we are now able to include or exclude the base per position.added an entry with related ticket number(s) to the unreleased section of
CHANGES.md