openbb-charting 2.2.3__tar.gz → 2.2.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/PKG-INFO +2 -2
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/charting.py +51 -1
- openbb_charting-2.2.5/openbb_charting/charts/correlation_matrix.py +119 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/charts/generic_charts.py +1 -1
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/openbb_figure.py +1 -1
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/pyproject.toml +2 -2
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/README.md +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/__init__.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/charts/__init__.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/charts/helpers.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/charts/price_historical.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/charts/price_performance.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/charts/relative_rotation.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/__init__.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/assets/Terminal_icon.png +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/assets/plotly-2.32.0.min.js +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/backend.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/chart_style.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/config/__init__.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/config/openbb_styles.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/dummy_backend.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly.html +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/__init__.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/base.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/data_classes.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/plugins/__init__.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/plugins/custom_indicators_plugin.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/plugins/momentum_plugin.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/plugins/overlap_plugin.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/plugins/trend_indicators_plugin.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/plugins/volatility_plugin.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/plugins/volume_plugin.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/ta_class.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/ta_helpers.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/table.html +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/to_chart.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/query_params.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/styles/__init__.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/styles/colors.py +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/styles/default/dark.pltstyle.json +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/styles/default/light.pltstyle.json +0 -0
- {openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/styles/default/tables.pltstyle.json +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: openbb-charting
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.5
|
|
4
4
|
Summary: Charting extension for OpenBB
|
|
5
5
|
License: AGPL-3.0-only
|
|
6
6
|
Author: OpenBB Team
|
|
@@ -15,7 +15,7 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
15
15
|
Provides-Extra: pywry
|
|
16
16
|
Requires-Dist: nbformat (>=5.9.2,<6.0.0)
|
|
17
17
|
Requires-Dist: numpy (>=1,<2)
|
|
18
|
-
Requires-Dist: openbb-core (>=1.3.
|
|
18
|
+
Requires-Dist: openbb-core (>=1.3.6,<2.0.0)
|
|
19
19
|
Requires-Dist: pandas-ta (>=0.3.14b,<0.4.0)
|
|
20
20
|
Requires-Dist: plotly (>=5.17.0,<6.0.0)
|
|
21
21
|
Requires-Dist: pywry (>=0.6.1,<0.7.0) ; extra == "pywry"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Charting Class implementation."""
|
|
2
2
|
|
|
3
|
-
# pylint: disable=too-many-arguments,unused-argument
|
|
3
|
+
# pylint: disable=too-many-arguments,unused-argument,too-many-positional-arguments
|
|
4
4
|
|
|
5
5
|
from typing import (
|
|
6
6
|
TYPE_CHECKING,
|
|
@@ -57,6 +57,8 @@ class Charting:
|
|
|
57
57
|
Create a line chart from external data.
|
|
58
58
|
create_bar_chart
|
|
59
59
|
Create a bar chart, on a single x-axis with one or more values for the y-axis, from external data.
|
|
60
|
+
create_correlation_matrix
|
|
61
|
+
Create a correlation matrix from external data.
|
|
60
62
|
toggle_chart_style
|
|
61
63
|
Toggle the chart style, of an existing chart, between light and dark mode.
|
|
62
64
|
"""
|
|
@@ -367,6 +369,54 @@ class Charting:
|
|
|
367
369
|
|
|
368
370
|
return fig
|
|
369
371
|
|
|
372
|
+
def create_correlation_matrix(
|
|
373
|
+
self,
|
|
374
|
+
data: Union[
|
|
375
|
+
list[Data],
|
|
376
|
+
"DataFrame",
|
|
377
|
+
],
|
|
378
|
+
method: Literal["pearson", "kendall", "spearman"] = "pearson",
|
|
379
|
+
colorscale: str = "RdBu",
|
|
380
|
+
title: str = "Asset Correlation Matrix",
|
|
381
|
+
layout_kwargs: Optional[Dict[str, Any]] = None,
|
|
382
|
+
):
|
|
383
|
+
"""Create a correlation matrix from external data.
|
|
384
|
+
|
|
385
|
+
Parameters
|
|
386
|
+
----------
|
|
387
|
+
data : Union[list[Data], DataFrame]
|
|
388
|
+
Input dataset.
|
|
389
|
+
method : Literal["pearson", "kendall", "spearman"]
|
|
390
|
+
Method to use for correlation calculation. Default is "pearson".
|
|
391
|
+
pearson : standard correlation coefficient
|
|
392
|
+
kendall : Kendall Tau correlation coefficient
|
|
393
|
+
spearman : Spearman rank correlation
|
|
394
|
+
colorscale : str
|
|
395
|
+
Plotly colorscale to use for the heatmap. Default is "RdBu".
|
|
396
|
+
title : str
|
|
397
|
+
Title of the chart. Default is "Asset Correlation Matrix".
|
|
398
|
+
layout_kwargs : Dict[str, Any]
|
|
399
|
+
Additional keyword arguments to apply with figure.update_layout(), by default None.
|
|
400
|
+
|
|
401
|
+
Returns
|
|
402
|
+
-------
|
|
403
|
+
OpenBBFigure
|
|
404
|
+
The OpenBBFigure object.
|
|
405
|
+
"""
|
|
406
|
+
# pylint: disable=import-outside-toplevel
|
|
407
|
+
from openbb_charting.charts.correlation_matrix import correlation_matrix
|
|
408
|
+
|
|
409
|
+
kwargs = {
|
|
410
|
+
"data": data,
|
|
411
|
+
"method": method,
|
|
412
|
+
"colorscale": colorscale,
|
|
413
|
+
"title": title,
|
|
414
|
+
"layout_kwargs": layout_kwargs,
|
|
415
|
+
}
|
|
416
|
+
fig, _ = correlation_matrix(**kwargs)
|
|
417
|
+
fig = self._set_chart_style(fig)
|
|
418
|
+
return fig
|
|
419
|
+
|
|
370
420
|
# pylint: disable=inconsistent-return-statements
|
|
371
421
|
def show(self, render: bool = True, **kwargs):
|
|
372
422
|
"""Display chart and save it to the OBBject."""
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""Correlation Matrix Chart."""
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Union
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from plotly.graph_objs import Figure # noqa
|
|
7
|
+
from openbb_charting.core.openbb_figure import OpenBBFigure # noqa
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def correlation_matrix( # noqa: PLR0912
|
|
11
|
+
**kwargs,
|
|
12
|
+
) -> tuple[Union["OpenBBFigure", "Figure"], dict[str, Any]]:
|
|
13
|
+
"""Correlation Matrix Chart."""
|
|
14
|
+
# pylint: disable=import-outside-toplevel
|
|
15
|
+
from numpy import ones_like, triu # noqa
|
|
16
|
+
from openbb_core.app.utils import basemodel_to_df # noqa
|
|
17
|
+
from openbb_charting.core.openbb_figure import OpenBBFigure
|
|
18
|
+
from openbb_charting.core.chart_style import ChartStyle
|
|
19
|
+
from plotly.graph_objs import Figure, Heatmap, Layout
|
|
20
|
+
from pandas import DataFrame
|
|
21
|
+
|
|
22
|
+
if "data" in kwargs and isinstance(kwargs["data"], DataFrame):
|
|
23
|
+
corr = kwargs["data"]
|
|
24
|
+
elif "data" in kwargs and isinstance(kwargs["data"], list):
|
|
25
|
+
corr = basemodel_to_df(kwargs["data"], index=kwargs.get("index", "date")) # type: ignore
|
|
26
|
+
else:
|
|
27
|
+
corr = basemodel_to_df(
|
|
28
|
+
kwargs["obbject_item"], index=kwargs.get("index", "date") # type: ignore
|
|
29
|
+
)
|
|
30
|
+
if (
|
|
31
|
+
"symbol" in corr.columns
|
|
32
|
+
and len(corr.symbol.unique()) > 1
|
|
33
|
+
and "close" in corr.columns
|
|
34
|
+
):
|
|
35
|
+
corr = corr.pivot(
|
|
36
|
+
columns="symbol",
|
|
37
|
+
values="close",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
method = kwargs.get("method") or "pearson"
|
|
41
|
+
corr = corr.corr(method=method, numeric_only=True)
|
|
42
|
+
|
|
43
|
+
X = corr.columns.to_list()
|
|
44
|
+
x_replace = X[-1]
|
|
45
|
+
Y = X.copy()
|
|
46
|
+
y_replace = Y[0]
|
|
47
|
+
X = [x if x != x_replace else "" for x in X]
|
|
48
|
+
Y = [y if y != y_replace else "" for y in Y]
|
|
49
|
+
mask = triu(ones_like(corr, dtype=bool))
|
|
50
|
+
df = corr.mask(mask)
|
|
51
|
+
title = kwargs.get("title") or "Asset Correlation Matrix"
|
|
52
|
+
text_color = "white" if ChartStyle().plt_style == "dark" else "black"
|
|
53
|
+
colorscale = kwargs.get("colorscale") or "RdBu"
|
|
54
|
+
|
|
55
|
+
heatmap = Heatmap(
|
|
56
|
+
z=df,
|
|
57
|
+
x=X,
|
|
58
|
+
y=Y,
|
|
59
|
+
xgap=1,
|
|
60
|
+
ygap=1,
|
|
61
|
+
colorscale=colorscale,
|
|
62
|
+
colorbar=dict(
|
|
63
|
+
orientation="v",
|
|
64
|
+
x=0.8,
|
|
65
|
+
y=0.5,
|
|
66
|
+
xanchor="left",
|
|
67
|
+
yanchor="middle",
|
|
68
|
+
xref="container",
|
|
69
|
+
yref="paper",
|
|
70
|
+
len=0.66,
|
|
71
|
+
bgcolor="rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)",
|
|
72
|
+
),
|
|
73
|
+
text=df.fillna(""),
|
|
74
|
+
texttemplate="%{text:.4f}",
|
|
75
|
+
hoverongaps=False,
|
|
76
|
+
hovertemplate="%{x} - %{y} : %{z:.4f}<extra></extra>",
|
|
77
|
+
)
|
|
78
|
+
layout = Layout(
|
|
79
|
+
title=title,
|
|
80
|
+
title_x=0.5,
|
|
81
|
+
xaxis=dict(
|
|
82
|
+
showgrid=False,
|
|
83
|
+
showline=False,
|
|
84
|
+
ticklen=0,
|
|
85
|
+
domain=[0.03, 1],
|
|
86
|
+
tickangle=90,
|
|
87
|
+
automargin=False,
|
|
88
|
+
),
|
|
89
|
+
yaxis=dict(
|
|
90
|
+
showgrid=False,
|
|
91
|
+
side="left",
|
|
92
|
+
autorange="reversed",
|
|
93
|
+
showline=False,
|
|
94
|
+
ticklen=0,
|
|
95
|
+
automargin="height+width+left",
|
|
96
|
+
tickmode="auto",
|
|
97
|
+
),
|
|
98
|
+
margin=dict(l=10, r=0, t=0, b=10),
|
|
99
|
+
dragmode="pan",
|
|
100
|
+
)
|
|
101
|
+
fig = Figure(data=[heatmap], layout=layout)
|
|
102
|
+
figure = OpenBBFigure(fig=fig)
|
|
103
|
+
figure.update_layout(
|
|
104
|
+
font=dict(color=text_color),
|
|
105
|
+
paper_bgcolor=(
|
|
106
|
+
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
|
107
|
+
),
|
|
108
|
+
plot_bgcolor=(
|
|
109
|
+
"rgba(0,0,0,0)" if text_color == "white" else "rgba(255,255,255,0)"
|
|
110
|
+
),
|
|
111
|
+
)
|
|
112
|
+
layout_kwargs = kwargs.get("layout_kwargs", {})
|
|
113
|
+
|
|
114
|
+
if layout_kwargs:
|
|
115
|
+
figure.update_layout(**layout_kwargs)
|
|
116
|
+
|
|
117
|
+
content = figure.show(external=True).to_plotly_json() # type: ignore
|
|
118
|
+
|
|
119
|
+
return figure, content
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Generic Charts Module."""
|
|
2
2
|
|
|
3
|
-
# pylint: disable=too-many-arguments,unused-argument,too-many-locals, too-many-branches, too-many-lines, too-many-statements, use-dict-literal, broad-exception-caught, too-many-nested-blocks
|
|
3
|
+
# pylint: disable=too-many-arguments,unused-argument,too-many-locals, too-many-branches, too-many-lines, too-many-statements, use-dict-literal, broad-exception-caught, too-many-nested-blocks, too-many-positional-arguments
|
|
4
4
|
|
|
5
5
|
from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Union
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "openbb-charting"
|
|
3
|
-
version = "2.2.
|
|
3
|
+
version = "2.2.5"
|
|
4
4
|
description = "Charting extension for OpenBB"
|
|
5
5
|
authors = ["OpenBB Team <hello@openbb.co>"]
|
|
6
6
|
license = "AGPL-3.0-only"
|
|
@@ -15,7 +15,7 @@ statsmodels = "^0.14.0"
|
|
|
15
15
|
pywry = { version = "^0.6.1", optional = true }
|
|
16
16
|
nbformat = "^5.9.2"
|
|
17
17
|
pandas-ta = "^0.3.14b"
|
|
18
|
-
openbb-core = "^1.3.
|
|
18
|
+
openbb-core = "^1.3.6"
|
|
19
19
|
numpy = "^1"
|
|
20
20
|
|
|
21
21
|
[tool.poetry.extras]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/assets/Terminal_icon.png
RENAMED
|
File without changes
|
{openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/assets/plotly-2.32.0.min.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/config/openbb_styles.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/data_classes.py
RENAMED
|
File without changes
|
{openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/plugins/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/core/plotly_ta/ta_helpers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/styles/default/dark.pltstyle.json
RENAMED
|
File without changes
|
{openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/styles/default/light.pltstyle.json
RENAMED
|
File without changes
|
{openbb_charting-2.2.3 → openbb_charting-2.2.5}/openbb_charting/styles/default/tables.pltstyle.json
RENAMED
|
File without changes
|