quantopian / pyfolio

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

How to show pyfolio result on Flask Web page #630

Open singhvivek2503 opened 4 years ago

singhvivek2503 commented 4 years ago

Problem Description

I want to display create_full_tear_sheet() result on my Flask webpage. How can I do this? Please provide a minimal, self-contained, and reproducible example:

def getSheet():    
    #get_ipython().magic("matplotlib inline")
    warnings.filterwarnings('ignore')
    matplotlib.pyplot.ion()

    ret = pd.read_csv(r'D:\pyfoliodata\returns.csv', index_col=None);
    ret['date'] = pd.DatetimeIndex(ret['date']);
    #ret.set_index('date', inplace=True, drop = True)
    returns = pd.Series(ret['return'].values, index=ret['date']);

    tran = pd.read_csv(r'D:\pyfoliodata\tran.csv', index_col=None);
    tran['dt'] = pd.DatetimeIndex(tran['dt']);
    tran['close_dt'] = pd.DatetimeIndex(tran['close_dt']);
    tran.set_index('dt', inplace=True, drop = True);

    positions = pd.read_csv(r'D:\pyfoliodata\positions.csv', index_col=None);
    positions['date'] = pd.DatetimeIndex(positions['date']);
    positions.set_index('date', inplace=True, drop = True);

    benchmark_ret = pd.read_csv(r'D:\pyfoliodata\benchmark_returns.csv', index_col=None);
    benchmark_ret['date'] = pd.DatetimeIndex(benchmark_ret['date']);
    benchmark_returns = pd.Series(benchmark_ret['return'].values, index=benchmark_ret['date']);    
    f = pf.create_full_tear_sheet(returns=returns, positions=positions, transactions=tran,benchmark_rets=benchmark_returns, round_trips=True);

Please provide any additional information below: I have all the data needed in .csv files in my application folder.

Versions

vovapyc commented 4 years ago

Hi @singhvivek2503, have you manage it? I'll be appreciate for solution.

vovapyc commented 4 years ago

I used method create_returns_tear_sheet() that returns mathplotlib object and method savefig() of the object to save it to PDF