Skip to content
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

[BUG] ProfitLossCriterion: Javadoc says "excludes trading costs" but code uses trading cost #1130

Open
2 tasks done
Cashmeiser opened this issue Feb 14, 2024 · 5 comments
Open
2 tasks done
Labels
bug Issue describing or discussing an bug in this library

Comments

@Cashmeiser
Copy link

I have checked existing issues and wiki

Describe the bug
Javadoc in ProfitLossCriterion says "Net Profit and loss criterion (absolute PnL, excludes trading costs)."
The code uses: position.getProfit();
and that code is:

    /**
     * Calculates the net profit of the position if it is closed. The net profit
     * **includes any trading costs.**
     *
     * @return the profit or loss of the position
     */
    public Num getProfit() {
        if (isOpened()) {
            return zero();
        } else {
            return getGrossProfit(exit.getPricePerAsset()).minus(**getPositionCost()**);
        }
    }

So, what is expected from ProfitLossCriterion? With Costs as code, or exclude cost as javadoc says?

Expected behavior
Consistency between Javadoc and Implementation

@Cashmeiser Cashmeiser added the bug Issue describing or discussing an bug in this library label Feb 14, 2024
@TheCookieLab
Copy link
Member

TheCookieLab commented Feb 15, 2024 via email

@Cashmeiser
Copy link
Author

Yes, I have a fix (like other criteria) with a constructor with boolean excludeCosts and a default one with excludeCost=false.
There is more job with fixing ReturnCriterion which also is inconsistence with java doc vs actual code. But this fix enforces some new methods in Positions as well to calculate Return with costs. Missing getNetGrossReturn methods.

But to do this, I need Permission to push a repo. Can you give it to me?

@TheCookieLab
Copy link
Member

TheCookieLab commented Feb 16, 2024

Typically contributing to open source projects is done via pull requests. Please see the contribution guide here: https://ta4j.github.io/ta4j-wiki/How-to-contribute

As for the implementation, to be consistent with the rest of the org.ta4j.core.criteria.pnl package it's preferable to make separate classes for "Gross" and "Net" profit/loss rather than using a boolean param.

@Cashmeiser
Copy link
Author

I get permission denied when I try to push my feature-branch:

> git push --set-upstream origin feature/1130-improve-pnl-criteria
info: please complete authentication in your browser...
remote: Permission to ta4j/ta4j.git denied to Cashmeiser.
fatal: unable to access 'https://github.com/ta4j/ta4j.git/': The requested URL returned error: 403

About the implementation, I took the boolean param from the other existing PnL: https://github.com/ta4j/ta4j/blob/master/ta4j-core/src/main/java/org/ta4j/core/criteria/pnl/ProfitCriterion.java#L42

@Cashmeiser
Copy link
Author

Maybe its on my side then. I had cloned the repo, created a feature-branch but couldn't push.
Tried to start over with the ta4j-wiki but then I couldn't even clone it:

git clone https://github.com/Cashmeiser/ta4j.git
Cloning into 'ta4j'...
info: please complete authentication in your browser...
remote: Repository not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue describing or discussing an bug in this library
Projects
None yet
Development

No branches or pull requests

2 participants