ranaroussi / quantstats

Portfolio analytics for quants, written in Python
Apache License 2.0
4.9k stars 850 forks source link

How to export tables to csv? #80

Closed stanleyy123 closed 1 year ago

stanleyy123 commented 3 years ago

Is there a way to export the tables to a gsheet/csv/excel?

datatalking commented 3 years ago

Which tables are you referring to pulling the data from in what format?

I recently did something like this with pandas but would need context.

stanleyy123 commented 3 years ago

Hi Andrew. I'm just looking to export some of the performance table. Is there a different requirement to export different table? How were you able to extract the individual tables? On Thursday, July 8, 2021, 03:16:56 PM PDT, Andrew Schell @.***> wrote:

Which tables are you referring to pulling the data from in what format?

I recently did something like this with pandas but would need context.

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

datatalking commented 3 years ago

@stanleyy123 If you can give me an error, or give me more specific file/folder or table name that you are referencingI can dig into the code.

windowshopr commented 2 years ago

Found this thread and am curious about the same thing.

I'm trying to extract the qs.reports.metrics(test_run_trading_report_df['returns'], mode='full') report to a CSV file, but this report is in a weird format or something, I don't know how to work with it. It's not a DataFrame, it's not something we can iterate through, WHAT IS IT? lol is it a series of series's?

Anyway, I want this to be in a .csv file!

                           Strategy
-------------------------  ----------
Start Period               2020-01-06
End Period                 2022-06-08
Risk-Free Rate             0.0%
Time in Market             100.0%

Cumulative Return          110.23%
CAGR﹪                     35.91%

Sharpe                     3.77
Smart Sharpe               3.25
Sortino                    8.91
Smart Sortino              7.67
Sortino/√2                 6.3
Smart Sortino/√2           5.42
Omega                      2.34

Max Drawdown               -10.12%
Longest DD Days            371
Volatility (ann.)          45.54%
Calmar                     3.55
Skew                       1.88
Kurtosis                   7.21

Expected Daily %           0.64%
Expected Monthly %         2.6%
Expected Yearly %          28.11%
Kelly Criterion            34.41%
Risk of Ruin               0.0%
Daily Value-at-Risk        -4.04%
Expected Shortfall (cVaR)  -4.04%

Gain/Pain Ratio            1.39
Gain/Pain (1M)             3.46

Payoff Ratio               1.56
Profit Factor              2.34
Common Sense Ratio         5.34
CPC Index                  2.2
Tail Ratio                 2.28
Outlier Win Ratio          5.7
Outlier Loss Ratio         4.33

MTD                        -2.51%
3M                         11.5%
6M                         39.26%
YTD                        31.62%
1Y                         51.78%
3Y (ann.)                  35.91%
5Y (ann.)                  35.91%
10Y (ann.)                 35.91%
All-time (ann.)            35.91%

Best Day                   15.14%
Worst Day                  -6.46%
Best Month                 19.35%
Worst Month                -7.01%
Best Year                  31.62%
Worst Year                 22.35%

Avg. Drawdown              -2.53%
Avg. Drawdown Days         36
Recovery Factor            10.89
Ulcer Index                0.03
Serenity Index             14.21

Avg. Up Month              4.85%
Avg. Down Month            -2.85%
Win Days %                 60.0%
Win Month %                72.41%
Win Quarter %              70.0%
Win Year %                 100.0%
windowshopr commented 2 years ago

Disregard my last, after doing a bit of code surfing, I noticed this chunk

    if display:
        print(_tabulate(metrics, headers="keys", tablefmt='simple'))
        return None

So I just set display=False and now I can deal with it like a DataFrame. Having it return None seems annoying, should still return metrics...