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

How can I add benchmark daily_returns to results df? #18

Closed
EcoFin opened this issue May 12, 2021 · 2 comments
Closed

How can I add benchmark daily_returns to results df? #18

EcoFin opened this issue May 12, 2021 · 2 comments

Comments

@EcoFin
Copy link

EcoFin commented May 12, 2021

Dear Zipline Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

Win 10 x64 zipline-reloaded 2.0.0rc4; Norgate data source

Now that you know a little about me, let me tell you about the issue I am having:

Description of Issue

This is a problem with me, not with zipline-reloaded which I have working quite well now!.

I can't figure out a way to add daily returns for a benchmark asset (that is already in the ingested bundle) to the results of run_algorithm.

  1. in initialize, do set_benchmark(symbol('$SPX'))
  2. results df reports benchmark_period_return and benchmark_volatility

but I need daily returns too.

I know I could (i) download them from an external web source, (ii) create them from an existing csv file or (iii) get them directly from my Norgate database.

But those aren't elegant solutions and the data series is already in the ingested bundle. There has got to be an easy way that I just can't see to identify them to run_algorithm:

run_algorithm(..., benchmark_returns = [what to put here?] ...)

It seems to me that BenchmarkReturnsAndVolatility calculates, but doesn't return, the daily_returns.

What steps have you taken to resolve this already?

I have looked high and low for a working example without success, have read all the relevant code and documentation and have tried everything I can think of myself without hitting on a working solution.

Anything else?

I'm just not as good at python as I would like to be.

Sincerely,
arthur

@AnilG3
Copy link

AnilG3 commented Jun 7, 2021

In analyze section, consider writing code to calculate daily_returns

daily_returns = (1 + benchmark_period_return) / (1 + benchmark_period_return.shift()) - 1

@stefan-jansen
Copy link
Owner

Closing for now due to lack of activity.

stefan-jansen pushed a commit that referenced this issue Jul 10, 2023
* Feature/zipline3dev (#18)

* pandas > 2.0 + * sqlalchemy > 2 migration
* numpy fixes

* fix pytest config

* pandas < 2 is no longer tested or supported

* fix ci yml pandas2
stefan-jansen pushed a commit that referenced this issue Jul 11, 2023
* pandas > 2.0 + * sqlalchemy > 2 migration
* numpy fixes
stefan-jansen added a commit that referenced this issue Jul 13, 2023
* Feature/zipline3dev (#18)

* pandas > 2.0 + * sqlalchemy > 2 migration
* numpy fixes
* fix pytest config
* pandas < 2 is no longer tested or supported
* fix ci yml pandas2
* updated pre-commit hooks
* full CI on push to main
* update actions
* skip certain tests on GHA
---------

Co-authored-by: MBounouar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants