How to display results from pyfolio in dash

Hello folks,

can please somebody help me with an displaying results from pyfolio in dash application?

Additionaly, how can I display graphic correlation in app?

import pandas as pd
import json
import numpy as np
import pyfolio as pf


def getdata(file):
    with open(file) as f:
        data = json.load(f)    
        
    strategy=pd.DataFrame(data)
    strategy['day'] = pd.to_datetime(strategy['day'],dayfirst=False)
    strategy=strategy.set_index('den')
        
    strategy['Return']=strategy['Equity'].pct_change()
    strategy=strategy.fillna(value=0)
    strategy.index=strategy.index.tz_localize('UTC')
    del strategy['Equity']
    return strategy

strategyA=getdata('dataA.csv')
strategyB=getdata('dataB.csv')
strategyC=getdata('dataC.csv')

portfolio=pd.concat([strategyA,strategyB,strategyC], axis=1, ignore_index=False)
portfolio.columns=["A","B","C"]

portfolio.plot(figsize=(12,8))

portfolio.cumsum().plot(figsize=(12,8))


portfolio.corr()

portfolio_total_return = np.sum([0.20, 0.30, 0.50] * portfolio, axis=1)

portfolio_total_return[-100:].cumsum().plot(figsize=(12,8))



benchmark=getdata('index.csv')
benchmark.columns=["INDEX"]

pf.tears.create_returns_tear_sheet(portfolio_total_return,benchmark_rets=benchmark['INDEX'])

I run above in Jupyter Notebook, but would like to display all above results in my dash application.
Can you please suggest ?

Thanks,
Tom

1 Like