Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Colab is not recognized as "notebook" by quantstats #370

Open
daviddwlee84 opened this issue Oct 17, 2024 · 0 comments
Open

Google Colab is not recognized as "notebook" by quantstats #370

daviddwlee84 opened this issue Oct 17, 2024 · 0 comments

Comments

@daviddwlee84
Copy link

Currently, using quantstats.report.html in Google Colab cannot recognize it as a Jupyter Notebook session.
So we need to set an output file and display it manually:

# Workaround
import quantstats as qs
from IPython.display import display, HTML
returns = qs.utils.download_returns('META')
qs.reports.html(returns, "SPY", output='META_versus_SPY.html')
display(HTML(filename='META_versus_SPY.html'))

def html(
returns,
benchmark=None,
rf=0.0,
grayscale=False,
title="Strategy Tearsheet",
output=None,
compounded=True,
periods_per_year=252,
download_filename="quantstats-tearsheet.html",
figfmt="svg",
template_path=None,
match_dates=True,
**kwargs,
):
if output is None and not _utils._in_notebook():
raise ValueError("`output` must be specified")

def _in_notebook(matplotlib_inline=False):
"""Identify enviroment (notebook, terminal, etc)"""
try:
shell = get_ipython().__class__.__name__
if shell == "ZMQInteractiveShell":
# Jupyter notebook or qtconsole
if matplotlib_inline:
get_ipython().magic("matplotlib inline")
return True
if shell == "TerminalInteractiveShell":
# Terminal running IPython
return False
# Other type (?)
return False
except NameError:
# Probably standard Python interpreter
return False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant