quantopian / pyfolio

Portfolio and risk analytics in Python
https://quantopian.github.io/pyfolio
Apache License 2.0
5.69k stars 1.78k forks source link

Return outputs of compute functions #405

Open eigenfoo opened 7 years ago

eigenfoo commented 7 years ago

Currently, pyfolio takes inputs, feeds them into the compute functions, plots the output, and then (usually) throws away the results of the compute functions. This is undesirable, both for Q internal use and open-source use.

Ideally, we would like create_x_tear_sheet to return an object that contains all the results of pyfolio analysis. E.g. a round_trips_analysis object/dict that I can query to find all numerical output or features. This will make pyfolio much more useful for algo analysis.

eigenfoo commented 7 years ago

Proposal: we'll have a class called analysis which will serve as a container for all floats/series/dataframes produced by a tear sheet. This class can be instantiated by any tear sheet: i.e. we'll optionally return a round_trips_analysis object of we call create_round_trips_tear_sheet and pass in return_analysis=True.

@twiecki @gusgordon thoughts?

gusgordon commented 7 years ago

Yes, I like that solution @georgh0021. Would analysis also include plots - ie matplotlib plt or ax objects? If not, analysis could also just be a dict that returns all the stats in the perf_stats table - that solution is much simpler.

Returning the plots is partially redundant, because we have a return_fig option on the tear sheets already. So I favor the dict solution, but I'm open.

eigenfoo commented 7 years ago

@gusgordon I mainly just wanted a class so we could tab-complete on class attributes... 😃 But a dict would be easier to implement.

I agree about not needing to include plt and ax objects in the dict, however, I think we need to be more ambitious that just returning perf_stats: I'd like it so that if I called create_round_trips_tear_sheet, I'd get the round_trips dataframe, as well any other objects that are outputted, such as sector_round_trips.

gusgordon commented 7 years ago

Yup, agree. That all makes sense.

On Jul 28, 2017, at 2:08 PM, George Ho notifications@github.com wrote:

@gusgordon I mainly just wanted a class so we could tab-complete on class attributes... 😃 But a dict would be easier to implement.

I agree about not needing to include plt and ax objects in the dict, however, I think we need to be more ambitious that just returning perf_stats: I'd like it so that if I called create_round_trips_tear_sheet, I'd get the round_trips dataframe, as well any other objects that are outputted, such as sector_round_trips.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

twiecki commented 7 years ago

Maybe return a named tuple.

The more general way to solve this would be to convert pyfolio to an OO-style. Then one could do algorithm.create_full_tear_sheet(), algorithm.perf_stats, etc