Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions opinion.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# My Opinion on jQuantStats

## Overview
## 📊 Overview

jQuantStats is a Python library for portfolio analytics aimed at quants and portfolio managers. It's a modernized fork
of QuantStats, focusing on providing a clean API with enhanced visualization capabilities using Plotly instead of
Matplotlib.

## Strengths
## 💪 Strengths

### Code Quality

Expand Down Expand Up @@ -38,7 +38,7 @@ Matplotlib.
- **CI/CD Integration**: GitHub Actions workflows for continuous integration.
- **Pre-commit Hooks**: Ensures code quality before commits.

## Areas for Improvement
## 🔍 Areas for Improvement

### Documentation

Expand All @@ -53,7 +53,7 @@ removed with the intention to bring them back later.

- The version number (0.0.0) indicates this is still in very early development.

## Conclusion
## 🏁 Conclusion

jQuantStats is a well-designed, modern Python library that shows excellent
software engineering practices. The code is clean, well-tested, and follows
Expand Down
8 changes: 7 additions & 1 deletion src/jquantstats/_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,20 @@ def hex_to_rgba(hex_color: str, alpha: float = 0.5) -> str:
# Get monthly returns values as a list for coloring
monthly_values = monthly_returns[ticker].to_list()

# If there's only one ticker, use green for positive returns and red for negative returns
if len(tickers) == 1:
bar_colors = ["green" if val > 0 else "red" for val in monthly_values]
else:
bar_colors = [COLORS[ticker] if val > 0 else COLORS[f"{ticker}_light"] for val in monthly_values]

fig.add_trace(
go.Bar(
x=monthly_returns[date_col],
y=monthly_returns[ticker],
name=ticker,
legendgroup=ticker,
marker=dict(
color=[COLORS[ticker] if val > 0 else COLORS[f"{ticker}_light"] for val in monthly_values],
color=bar_colors,
line=dict(width=0),
),
opacity=0.8,
Expand Down
10 changes: 10 additions & 0 deletions src/tests/test_plots.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from jquantstats import build_data


@pytest.fixture
def plots(data):
Expand Down Expand Up @@ -39,3 +41,11 @@ def test_plot_snapshot(plots):

# causing sometimes problems
# fig.show()

def test_plot_snapshot_one_symbol(returns):
fig = build_data(returns=returns).plots.plot_snapshot()

assert fig is not None
assert hasattr(fig, 'show')
# causing sometimes problems
# fig.show()