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

SQN calculation not using expectancy? #558

Open
souresia opened this issue Dec 23, 2021 · 1 comment
Open

SQN calculation not using expectancy? #558

souresia opened this issue Dec 23, 2021 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@souresia
Copy link

Hi,

It's good to see the stats include SQN. According to https://evilspeculator.com/tools-section/concepts/:

SQN = root(n) * expectancy / stdev(R)

but I suspect it's not correctly calculated:

s.loc['SQN'] = np.sqrt(n_trades) * pl.mean() / (pl.std() or np.nan)

as it's not using the result of expectancy:

s.loc['Expectancy [%]'] = returns.mean() * 100

Unless I am missing something?

Thanks!

@kernc
Copy link
Owner

kernc commented Dec 24, 2021

If we look slightly higher up:

pl = trades_df['PnL']
returns = trades_df['ReturnPct']

returns for expectancy are in percent whereas pl are in absolute currency units.

I see Van Tharp mentions expectancy and R-multiples (reward/risk), which are percent-based, but I modeled it after backtrader and thought those pnl were absolute values:
https://github.com/mementum/backtrader/blob/e2674b1690f6366e08646d8cfd44af7bb71b3970/backtrader/analyzers/sqn.py#L75-L78

I guess we might be using the wrong values then. 😬

@kernc kernc marked this as a duplicate of #1108 Feb 19, 2025
@kernc kernc added the help wanted Extra attention is needed label Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants