-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
is there a way to get final PnL in pips #8
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
Comments
IIUC, the final P/L in money and percentage is already provided: backtesting.py/backtesting/backtesting.py Line 881 in a7d1d4f
backtesting.py/backtesting/backtesting.py Line 883 in a7d1d4f
For the P/L in pips, you can divide the backtesting.py/backtesting/_util.py Lines 100 to 101 in a7d1d4f
Does this work for you? |
Thanks.
so result['Equity Final [$]']/pip_size, I though this would have been true
if the position size for every trade was exactly the same, but in our case
the position size is the max amount, while the equity is growing or
falling, where's the catch?
…On Thu, Jul 4, 2019 at 4:23 PM kernc ***@***.***> wrote:
IIUC, the final P/L in money and percentage is already provided:
https://github.com/kernc/backtesting.py/blob/a7d1d4f3fa658290182dfa2fdbf69bffe6a8f018/backtesting/backtesting.py#L881
https://github.com/kernc/backtesting.py/blob/a7d1d4f3fa658290182dfa2fdbf69bffe6a8f018/backtesting/backtesting.py#L883
For the P/L in pips, you can divide the s['Equity Final [$]'] value by
pip size. If you don't know it, backtesting.py uses the following heuristic
formula to determine it from closing values:
https://github.com/kernc/backtesting.py/blob/a7d1d4f3fa658290182dfa2fdbf69bffe6a8f018/backtesting/_util.py#L100-L101
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8?email_source=notifications&email_token=AE7J6THA5RETK75AAHKY7KTP5X2TLA5CNFSM4H52BIO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZHM4EY#issuecomment-508481043>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AE7J6TGVWPV43NJIPEYDCELP5X2TLANCNFSM4H52BIOQ>
.
--
Kindest regards,
Eduard Samokhvalov
Phone
+7 977 119 23 66
Web
https://packandsell.org
LinkedIn
https://www.linkedin.com/in/esamokhvalov/
Skype
edward.samokhvalov
|
The equity changes along with asset price. Indeed, self.position.pl / self.data.pip within bt = Backtest(...)
result = bt.run()
per_trade_pips = result._trade_data['P/L'].dropna() / pip_size |
Or ... if you are interested in mere price difference in pips of your individual trades, you have to additionally divide by position size in self.position.pl / self.position.size / self.data.pip
# or
(self.data.Close - self.position.open_price) / self.data.pip # (*-1) for short positions Or, at the end of a backtest run, using undocumented API: td = res._trade_data
td = td.ffill().loc[td['P/L'].dropna().index]
(td['Exit Price'] - td['Entry Price']) / pip_size |
I understand the suggestion here is to amended |
Dear Kernc, Here's the screenshot of PnL calculated in Excel VS debug data from the Python class. I've attached the screenshot, data (open price/signals in sample.txt) and code. The comparison values are in google sheets here. Your help is appreciated a big time. The python.txt file contains code. |
In delta_pips = self.position.pl / self.position.size In order to get this value in terms of number of pips, you have to, additionally, divide by pip size: pnl_in_pips = self.position.pl / self.position.size / self.data.pip |
Thanks for the tip. It seems to work now. |
As PnL in pips is easily computable, |
Expected Behavior
PnL in pips
Actual Behavior
PnL in money or percentage, which is also useful
The text was updated successfully, but these errors were encountered: