Skip to content

Extra stats conditions when optimizing? #234

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

Closed
konradg40 opened this issue Jan 24, 2021 · 2 comments
Closed

Extra stats conditions when optimizing? #234

konradg40 opened this issue Jan 24, 2021 · 2 comments
Labels
question Not a bug, but a FAQ entry

Comments

@konradg40
Copy link

First of all, thank you for this wonderful library.

When I maximize sharpe ratio, I could get a very good sharpe but with higher volatility levels than I prefer.
My idea was to maximize sharpe ratio with a maximum volatility set, alternatively it would be nice if I could select the
highest sharpe ratio runs (that I find acceptable) and then reorder those again based on the volatility level.
I tried to find the answer in the documentation without luck.
Any help would be appreciated.

@kernc
Copy link
Owner

kernc commented Jan 24, 2021

Backtest.optimize(maximize=) parameter also takes a callable (function) that takes the run stats and returns an ordinal value. Some example functions you could use:

# Sharpe over some threshold and with minimum volatility
maximize_func = lambda s: int(s['Sharpe Ratio'] > acceptable_threshold) * -s['Volatility (Ann.) [%]']
# Sharpe, divided by annual volatility
maximize_func = lambda s: s['Sharpe Ratio'] / s['Volatility (Ann.) [%]']
# Calmar ratio = rate of return over max drawdown
maximize_func = 'Calmar Ratio'

... = bt.optimize(..., maximize=maximize_func)

@kernc kernc closed this as completed Jan 24, 2021
@kernc kernc added the question Not a bug, but a FAQ entry label Jan 24, 2021
@konradg40
Copy link
Author

Thank you for the quick and clear answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Not a bug, but a FAQ entry
Projects
None yet
Development

No branches or pull requests

2 participants