quantopian / pyfolio

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

Export Tear Sheet/Save Values to variables #578

Open ElliotP123 opened 5 years ago

ElliotP123 commented 5 years ago

Afternoon,

This is an amazing package, thank you so much for it. I am trying to export the values calculated for the full tear sheet. I have tried to save the result to a variable but it doesn't seem to work. When I had a look at the code it seems to print calculated values, but I couldn't see the code which calculates things like "annual return", "cumulative return" and presents a figure.

Would somebody be able to point me in the right direction to access those calculated values? Or would it be easier to calculate my own tear sheet from the positions, transactions, etc?

Kind Regards

abk11 commented 5 years ago

Hi,

After inspecting the docs a bit, I might have found a solution useful for you: from pyfolio import timeseries perf_func = timeseries.perf_stats perf_stats_all = perf_func( returns=your_portfolio_returns_as_a_pdSeries, factor_returns=your_benchmark_returns_as_a_pdSeries, positions=None, transactions=None, turnover_denom="AGB")

"perf_stats_all" is a pd.Series that reports the values for: ['Annual return', 'Cumulative returns', 'Annual volatility', 'Sharpe ratio', 'Calmar ratio', 'Stability', 'Max drawdown', 'Omega ratio', 'Sortino ratio', 'Skew', 'Kurtosis', 'Tail ratio', 'Common sense ratio', 'Daily value at risk', 'Alpha', 'Beta']