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.
Spelling mistake in asset ("assert")
There was a problem hiding this comment.
Same applies to other parts of code
There was a problem hiding this comment.
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.
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.
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.
How do we know the PNL without setting a base currency we check against?
There was a problem hiding this comment.
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.
Does the PortfolioSwap sold not already include the assets sold?
There was a problem hiding this comment.
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( |
Co-authored-by: Arnaud Flament <17051690+aflament@users.noreply.github.com>
Implementation of PNL into Portfolio service