-
Notifications
You must be signed in to change notification settings - Fork 15
Feature portfolio PNL #92
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
Conversation
| def __init__(self, bought: PortfolioSwap, selling_price: Decimal, asset_sold: Decimal, is_realized: bool) -> None: | ||
| self._bought = bought | ||
| self._selling_price = selling_price | ||
| self._assert_sold = asset_sold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling mistake in asset ("assert")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same applies to other parts of code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, that is one I'm making constanstly
| return sum([pnl for asset, pnl in self.pnl_per_asset(mode).items()], Decimal(0)) | ||
|
|
||
|
|
||
| class PortfolioPNLDetail: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does a PortfolioPNLDetail represent? My understanding reading through the code is that these could be individual trading lots (single purchases or sells for an asset)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PortfolioSwaprepresents either a buy or a sell transaction, depending on which token is the base token.PortfolioPNLDetailrepresents either a partial lot of a full lot. It also represent a line item in the PNL report.PortfolioRealizedPNLDetail: this represent either a partial of full lot that has a matching sell transaction. The sold asset represent the amount of the position that was sold.sold_assetis computed in a way so that there is only one buying and selling price.PortoflioUnrealizedPNLDetail: a full or partial lot that has no matching sell transaction
| def add_details(self, asset: str, details: Iterable[PortfolioPNLDetail]) -> None: | ||
| self._details_per_asset[asset] = list(details) | ||
|
|
||
| def pnl_per_asset(self, mode: PnlMode = PnlMode.TOTAL) -> Dict[str, Decimal]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we know the PNL without setting a base currency we check against?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the computation of the PNL is call, the base currency/token is passed as a parameter. That base token is passed to the PNL report.
This function here is a helper function on the report itself, so the base token is already known
|
|
||
|
|
||
| class PortfolioRealizedPNLDetail(PortfolioPNLDetail): | ||
| def __init__(self, bought: PortfolioSwap, sold: PortfolioSwap, asset_sold: Decimal) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the PortfolioSwap sold not already include the assets sold?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asset_sold, represents the amount of asset being sold for that line item. Maybe a better name would be amount_sold.
It is different than the PortfolioSwap sold because the sell transaction may impact multiple positions.
| return self._wallet.chain | ||
|
|
||
| @classmethod | ||
| def compute_pnl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to PortfolioPNL
aflament
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with comments
Co-authored-by: Arnaud Flament <17051690+aflament@users.noreply.github.com>
Implementation of PNL into Portfolio service