ranaroussi / quantstats

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

Showing qs.reports.html in streamlit #179

Open ceciliabonucchi opened 2 years ago

ceciliabonucchi commented 2 years ago

Hello, thank you so much for developing this amazing library! I am trying to use it in my streamlit app, however even after extensive research I was not able to make it work. It doesn't seems to save the html output if I'm working outside of a Jupyter notebook.

Here's the code I came up with:

stock = qs.utils.download_returns('QQQ', period="10y") qs.reports.html(stock, "SPY", title="QQQ vs. SPY", output='Output.html')

Show

import streamlit.components.v1 as components HtmlFile = open('Output.html', 'r', encoding='utf-8') source_code = HtmlFile.read() print(source_code) components.html(source_code, height = 900)

But it's not working. Can you help me? Thank you very much!

eervin123 commented 2 years ago

Would love to see this ^ +1 on the up vote.

jamesfulford commented 1 year ago

@ceciliabonucchi I haven't tried in streamlit, but I know I have to specify output=filepath, download_filename=filepath for it to actually save to that filepath. Maybe that's the problem here, if your print is printing nothing.

TradingDominion commented 1 year ago

@ceciliabonucchi

You can do it like this:

        stock = qs.utils.download_returns('AAPL')
        fig = qs.plots.snapshot(stock, title='AAPL Performance', show=False)
        st.write(fig)
TradingDominion commented 1 year ago

Now that I've managed to get the plots working in Streamlit, I've been trying to get them converted over to Plotly format in order to make them interactive. I've tried a whole bunch of variations but I haven't had any luck. If someone figures out, please post the solution in this thread.

georgosqlab commented 1 year ago

Could someone tell me how to integrate qs.reports.metrics report into streamlit app? Unfortunately it does not work with st.write() st.table(), st.markdown()...

Harsh-Maheshwari commented 1 week ago

Is there any update on this?