zerodha / pykiteconnect

The official Python client library for the Kite Connect trading APIs
MIT License
978 stars 467 forks source link

Please add a function to calculate the PNL value from the list of positions and prices. :feature: #129

Closed hemangjoshi37a closed 2 years ago

hemangjoshi37a commented 2 years ago

Hello Devs,

I need your help to calculate the PNL from the list of positions and the prices because I tried so many methods to calculate it by my own but I failed to get the same results as the PNL shown in my Zerodha Console.

I tried different methods from this website which did not worked and gave some not correct results. https://quant.stackexchange.com/questions/9002/calculate-average-price-cost-unrealized-pl-of-a-position-based-on-executed

Thank you.

vividvilla commented 2 years ago

You can never match it with Console since it EOD report and won't be real-time. Here is the formula which we use to show live PNL in Kite.

pnl = (position.sell_value - position.buy_value) + (position.quantity * lastPrice * position.multiplier)

You need to get lastPrice from ticker and other fields are part of positions response.

hemangjoshi37a commented 2 years ago

What about the charges though? I already know the method you mentioned above.

On Tue, 23 Nov 2021 at 15:54, Vivek R @.***> wrote:

Closed #129 https://github.com/zerodha/pykiteconnect/issues/129.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/zerodha/pykiteconnect/issues/129#event-5659327472, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC6RPGN3FWTLTYD7NKYYSGLUNNTU7ANCNFSM5EKCKQLQ .

-- Regards, Hemang Joshi, Email : @.*** mobile : +919409077371