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

No where to change benchmark? #2311

Closed
liyi-1989 opened this issue Sep 29, 2018 · 2 comments
Closed

No where to change benchmark? #2311

liyi-1989 opened this issue Sep 29, 2018 · 2 comments

Comments

@liyi-1989
Copy link

liyi-1989 commented Sep 29, 2018

Say, I am using v1.3.0 and trying to use zipline.run_algorithm() to run the algorithm. If I do not change the source code, I cannot find a way to change the benchmark.

  1. In the run_algo() source code, it essentially creates a TradingAlgorithm object by inputing an env variable.

  2. This env variable, defined in the function body, is created without explicitly giving the bm_symbol argument.

  3. Based on the definition of the TradingEnvironment class, the env has the bm_symbol always equals to SPY by default (and load variable always equals to None).

  4. In this way, the env.benchmark_return property is thus (always) created by bm_symbol='SPY'.

  5. Thus, when TradingAlgorithm uses it (env), it always uses the benchmark_return created by SPY.

(6. btw, adding context.set_benchmark(symbol('XXX')) in the initialize() function is not useful, since it runs after the above environment process.)

So, it looks like the only way to change the benchmark from SPY to something else is to:

  • change the code of TradingEnvironment class, the default of bm_symbol
  • or, when creating the env variable in run_algorithm() source code, explicitly add the bm_symbol argument. (and probably add a bm_symbol argument for the run_algo function)

(in either way, we have to change the source code)
Am I right?

@marketwiz
Copy link

marketwiz commented Sep 29, 2018 via email

@ssanderson
Copy link
Contributor

Apologies for the slow reply to this issue. On Zipline master, you can now pass benchmark_returns or benchmark_sid to TradingAlgorithm. There's still no good way, however, to control the benchmark when running via the Zipline CLI. I'm tracking that issue in #2627.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants