dcajasn / Riskfolio-Lib

Portfolio Optimization and Quantitative Strategic Asset Allocation in Python
https://riskfolio-lib.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
3.02k stars 514 forks source link

LaTeX legend with ParserError #175

Closed lcscosta closed 10 months ago

lcscosta commented 1 year ago

Hi, thanks for your work.

I'm testing your library and find this error:

ValueError: 
 Normal: $\mu=0.07%$%, $\sigma=1.29%$%
                ^
ParseException: Expected end of text, found '$'  (at char 8), (line:1, col:9)

I discovered that this error are from riskfolio.jupyter_report(), searching a little bit more I get the lines of this error and I make a modification to be able to run this function.

https://github.com/dcajasn/Riskfolio-Lib/blob/06dfe24745dd8ab40665621e72cfeb40a80c2b2e/riskfolio/src/PlotFunctions.py#L1489-L1493

I rewrited this segment as:

label='Normal: $\mu=$'
        + '{0:.2%}'.format(mu)
        + ', $\sigma=$'
        + '{0:.2%}'.format(sigma),

Now the module are working as expected. If you need more information to try to reproduce the error, you can message me.

This is my pip freeze, if you want to test, I removed the riskfolio because I do modifications and installed from path:

anyio==4.0.0
appdirs==1.4.4
arch==6.1.0
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
astropy==5.3.3
asttokens==2.4.0
async-lru==2.0.4
attrs==23.1.0
Babel==2.12.1
backcall==0.2.0
beautifulsoup4==4.12.2
bleach==6.0.0
certifi==2023.7.22
cffi==1.15.1
charset-normalizer==3.2.0
comm==0.1.4
contourpy==1.1.1
cvxpy==1.3.2
cycler==0.11.0
debugpy==1.8.0
decorator==5.1.1
defusedxml==0.7.1
ecos==2.0.12
et-xmlfile==1.1.0
executing==1.2.0
fastjsonschema==2.18.0
fonttools==4.42.1
fqdn==1.5.1
frozendict==2.3.8
html5lib==1.1
idna==3.4
ipykernel==6.25.2
ipython==8.15.0
isoduration==20.11.0
jedi==0.19.0
Jinja2==3.1.2
joblib==1.3.2
json5==0.9.14
jsonpointer==2.4
jsonschema==4.19.1
jsonschema-specifications==2023.7.1
jupyter-events==0.7.0
jupyter-lsp==2.2.0
jupyter_client==8.3.1
jupyter_core==5.3.1
jupyter_server==2.7.3
jupyter_server_terminals==0.4.4
jupyterlab==4.0.6
jupyterlab-pygments==0.2.2
jupyterlab_server==2.25.0
kiwisolver==1.4.5
lxml==4.9.3
MarkupSafe==2.1.3
matplotlib==3.8.0
matplotlib-inline==0.1.6
mistune==3.0.1
multitasking==0.0.11
nbclient==0.8.0
nbconvert==7.8.0
nbformat==5.9.2
nest-asyncio==1.5.8
networkx==3.1
notebook_shim==0.2.3
numpy==1.26.0
openpyxl==3.1.2
osqp==0.6.3
overrides==7.4.0
packaging==23.1
pandas==2.1.0
pandocfilters==1.5.0
parso==0.8.3
patsy==0.5.3
pexpect==4.8.0
pickleshare==0.7.5
Pillow==10.0.1
platformdirs==3.10.0
prometheus-client==0.17.1
prompt-toolkit==3.0.39
psutil==5.9.5
ptyprocess==0.7.0
pure-eval==0.2.2
pybind11==2.11.1
pycparser==2.21
pyerfa==2.0.0.3
Pygments==2.16.1
pyparsing==3.1.1
python-dateutil==2.8.2
python-json-logger==2.0.7
pytz==2023.3.post1
PyYAML==6.0.1
pyzmq==25.1.1
qdldl==0.1.7.post0
referencing==0.30.2
requests==2.31.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rpds-py==0.10.3
scikit-learn==1.3.0
scipy==1.11.2
scs==3.2.3
Send2Trash==1.8.2
six==1.16.0
sniffio==1.3.0
soupsieve==2.5
stack-data==0.6.2
statsmodels==0.14.0
terminado==0.17.1
threadpoolctl==3.2.0
tinycss2==1.2.1
tornado==6.3.3
traitlets==5.10.0
tzdata==2023.3
uri-template==1.3.0
urllib3==2.0.5
wcwidth==0.2.6
webcolors==1.13
webencodings==0.5.1
websocket-client==1.6.3
XlsxWriter==3.1.4
yfinance==0.2.28
dcajasn commented 10 months ago

Hi @lcscosta, there is no error. I've just tried it with several versions of matplotlib higher than 3.5 and it works well. I recommend you to use a scientific Python distribution like Anaconda or Winpython to avoid problems.

GrantWise commented 8 months ago

Hi, I am runnng Anaconda and have Matplotlib version 3.8.2 and also get the error.

ValueError: 
Normal: $\mu=0.09%$%, $\sigma=0.80%$%
        ^
ParseException: Expected end of text, found '$'  (at char 8), (line:1, col:9)
dcajasn commented 8 months ago

Hi @GrantWise,

Do you have installed Riskfolio-Lib=5.0.1 ?

Best, Dany