openbb-charting 2.5.1__tar.gz → 4.0.0__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-4.0.0/.gitignore +65 -0
- openbb_charting-4.0.0/PKG-INFO +188 -0
- openbb_charting-4.0.0/README.md +172 -0
- openbb_charting-4.0.0/examples.md +172 -0
- openbb_charting-4.0.0/index.md +361 -0
- openbb_charting-4.0.0/indicators.md +389 -0
- openbb_charting-4.0.0/installation.md +72 -0
- openbb_charting-4.0.0/integration/__init__.py +1 -0
- openbb_charting-4.0.0/integration/conftest.py +166 -0
- openbb_charting-4.0.0/integration/test_charting_api.py +35 -0
- openbb_charting-4.0.0/integration/test_charting_python.py +29 -0
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/__init__.py +1 -3
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/charting.py +244 -280
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/charts/correlation_matrix.py +3 -4
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/charts/generic_charts.py +40 -45
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/charts/helpers.py +4 -9
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/charts/price_historical.py +18 -22
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/charts/price_performance.py +7 -8
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/charts/relative_rotation.py +6 -20
- openbb_charting-4.0.0/openbb_charting/core/backend.py +484 -0
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/chart_style.py +55 -20
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/config/openbb_styles.py +10 -16
- openbb_charting-4.0.0/openbb_charting/core/dummy_backend.py +31 -0
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/openbb_figure.py +84 -216
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/plotly_ta/base.py +13 -28
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/plotly_ta/data_classes.py +14 -50
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/plotly_ta/plugins/custom_indicators_plugin.py +46 -24
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/plotly_ta/plugins/momentum_plugin.py +53 -60
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/plotly_ta/plugins/volatility_plugin.py +1 -1
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/plotly_ta/plugins/volume_plugin.py +0 -4
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/plotly_ta/ta_class.py +40 -92
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/plotly_ta/ta_helpers.py +1 -4
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/to_chart.py +2 -7
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/query_params.py +2 -4
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/styles/default/dark.pltstyle.json +2 -1
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/styles/default/light.pltstyle.json +2 -1
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/styles/default/tables.pltstyle.json +1 -1
- openbb_charting-4.0.0/pyproject.toml +86 -0
- openbb_charting-4.0.0/tests/__init__.py +1 -0
- openbb_charting-4.0.0/tests/conftest.py +163 -0
- openbb_charting-4.0.0/tests/test_backend.py +301 -0
- openbb_charting-4.0.0/tests/test_chart_style.py +270 -0
- openbb_charting-4.0.0/tests/test_charting.py +620 -0
- openbb_charting-4.0.0/tests/test_charting_core_ta_helpers.py +62 -0
- openbb_charting-4.0.0/tests/test_charts_helpers.py +206 -0
- openbb_charting-4.0.0/tests/test_colors.py +23 -0
- openbb_charting-4.0.0/tests/test_correlation_matrix.py +72 -0
- openbb_charting-4.0.0/tests/test_dummy_backend.py +48 -0
- openbb_charting-4.0.0/tests/test_generic_charts.py +440 -0
- openbb_charting-4.0.0/tests/test_openbb_figure.py +800 -0
- openbb_charting-4.0.0/tests/test_openbb_styles.py +87 -0
- openbb_charting-4.0.0/tests/test_plotly_ta_base.py +338 -0
- openbb_charting-4.0.0/tests/test_plotly_ta_class.py +423 -0
- openbb_charting-4.0.0/tests/test_plotly_ta_data_classes.py +393 -0
- openbb_charting-4.0.0/tests/test_plotly_ta_plugins.py +529 -0
- openbb_charting-4.0.0/tests/test_price_historical.py +237 -0
- openbb_charting-4.0.0/tests/test_price_performance.py +109 -0
- openbb_charting-4.0.0/tests/test_query_params.py +152 -0
- openbb_charting-4.0.0/tests/test_relative_rotation.py +113 -0
- openbb_charting-4.0.0/tests/test_to_chart.py +30 -0
- openbb_charting-4.0.0/uv.lock +3792 -0
- openbb_charting-2.5.1/PKG-INFO +0 -198
- openbb_charting-2.5.1/README.md +0 -174
- openbb_charting-2.5.1/openbb_charting/core/assets/plotly-3.1.0.min.js +0 -3882
- openbb_charting-2.5.1/openbb_charting/core/backend.py +0 -441
- openbb_charting-2.5.1/openbb_charting/core/dummy_backend.py +0 -55
- openbb_charting-2.5.1/openbb_charting/core/plotly.html +0 -4031
- openbb_charting-2.5.1/openbb_charting/core/table.html +0 -165
- openbb_charting-2.5.1/pyproject.toml +0 -26
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/charts/__init__.py +0 -0
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/__init__.py +0 -0
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/assets/Terminal_icon.png +0 -0
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/config/__init__.py +0 -0
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/plotly_ta/__init__.py +0 -0
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/plotly_ta/plugins/__init__.py +0 -0
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/plotly_ta/plugins/overlap_plugin.py +0 -0
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/core/plotly_ta/plugins/trend_indicators_plugin.py +0 -0
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/styles/__init__.py +0 -0
- {openbb_charting-2.5.1 → openbb_charting-4.0.0}/openbb_charting/styles/colors.py +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# General
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.pyc
|
|
4
|
+
.DS_Store
|
|
5
|
+
*.env
|
|
6
|
+
.venv
|
|
7
|
+
venv*/
|
|
8
|
+
venv
|
|
9
|
+
.vscode
|
|
10
|
+
*.ipynb
|
|
11
|
+
env/
|
|
12
|
+
venv/
|
|
13
|
+
!notebooks/jupyter/.gitkeep
|
|
14
|
+
.python-version
|
|
15
|
+
.mypy_cache
|
|
16
|
+
.ruff_cache
|
|
17
|
+
.pytest_cache
|
|
18
|
+
iframe_figures/
|
|
19
|
+
exports/*
|
|
20
|
+
.idea
|
|
21
|
+
.coverage
|
|
22
|
+
.scannerwork
|
|
23
|
+
htmlcov
|
|
24
|
+
**/.ipynb_checkpoints
|
|
25
|
+
*.swp
|
|
26
|
+
*.http
|
|
27
|
+
.coverage.*
|
|
28
|
+
*_tests.csv
|
|
29
|
+
*_sdk_audit.csv
|
|
30
|
+
!build/docker/compose.env
|
|
31
|
+
.dccache
|
|
32
|
+
*rome.json
|
|
33
|
+
**/node_modules/*
|
|
34
|
+
.cursorignore
|
|
35
|
+
darts_logs/
|
|
36
|
+
custom_imports/*.csv
|
|
37
|
+
custom_imports/*/*.csv
|
|
38
|
+
cache/
|
|
39
|
+
lightning_logs/
|
|
40
|
+
*/mocked_path
|
|
41
|
+
*.pem
|
|
42
|
+
|
|
43
|
+
# CLI
|
|
44
|
+
*.pyo
|
|
45
|
+
**/dist/*
|
|
46
|
+
build/cli
|
|
47
|
+
build/nsis/app
|
|
48
|
+
DMG/*
|
|
49
|
+
*.dmg
|
|
50
|
+
*.sh
|
|
51
|
+
cli/openbb_cli/assets/styles/user/*
|
|
52
|
+
|
|
53
|
+
# Platform
|
|
54
|
+
openbb_platform/core/openbb/package/*
|
|
55
|
+
openbb_platform/core/openbb/.build.lock
|
|
56
|
+
**/assets/*.json.xz
|
|
57
|
+
|
|
58
|
+
# Dev Container env
|
|
59
|
+
obb/*
|
|
60
|
+
|
|
61
|
+
# OpenBB Distribution
|
|
62
|
+
!build/conda/installer/*.sh
|
|
63
|
+
*.pkg
|
|
64
|
+
*.exe
|
|
65
|
+
build/conda/tmp
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: openbb-charting
|
|
3
|
+
Version: 4.0.0
|
|
4
|
+
Summary: Charting extension for OpenBB
|
|
5
|
+
Project-URL: Homepage, https://openbb.co
|
|
6
|
+
Project-URL: Repository, https://github.com/OpenBB-finance/OpenBB
|
|
7
|
+
Author-email: OpenBB Team <hello@openbb.co>
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
Requires-Python: <4,>=3.10
|
|
10
|
+
Requires-Dist: openbb-core[pandas]>=2.0.0
|
|
11
|
+
Requires-Dist: pandas-ta-openbb>=0.4.24
|
|
12
|
+
Requires-Dist: plotly>=6.3.1
|
|
13
|
+
Provides-Extra: pywry
|
|
14
|
+
Requires-Dist: pywry>=2.0.4; extra == 'pywry'
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# OpenBB Charting
|
|
18
|
+
|
|
19
|
+
Plotly-based charting for the OpenBB Platform. Installing this package registers a `charting` accessor on every `OBBject` command result and enables the `chart=True` argument on Platform endpoints that have a chart.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install openbb-charting
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
To display charts in a native desktop window, install the PyWry extra:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install "openbb-charting[pywry]"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
On Linux, PyWry requires system WebKit/GTK libraries:
|
|
34
|
+
|
|
35
|
+
- Debian / Ubuntu / Mint: `sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev`
|
|
36
|
+
- Arch / Manjaro: `sudo pacman -S webkit2gtk`
|
|
37
|
+
- Fedora: `sudo dnf install gtk3-devel webkit2gtk3-devel`
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
Pass `chart=True` to an endpoint that has a chart, then call `show()` on the result:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from openbb import obb
|
|
45
|
+
|
|
46
|
+
data = obb.equity.price.historical("AAPL", provider="yfinance", chart=True)
|
|
47
|
+
data.show()
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The same chart is reachable through the `charting` accessor on any result, without `chart=True`:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
res = obb.equity.price.historical("AAPL", provider="yfinance")
|
|
54
|
+
res.charting.show()
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Which commands have a chart
|
|
58
|
+
|
|
59
|
+
Charts are contributed by the installed extensions. List the registered routes:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from openbb_charting import Charting
|
|
63
|
+
|
|
64
|
+
Charting.functions()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Technical-analysis overlays — `to_chart`
|
|
68
|
+
|
|
69
|
+
`to_chart` rebuilds the chart of a time-series (OHLCV) result with indicator overlays. Indicators and their parameters are passed through the `indicators` argument:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
res = obb.equity.price.historical("AAPL", provider="yfinance")
|
|
73
|
+
res.charting.to_chart(
|
|
74
|
+
indicators=dict(
|
|
75
|
+
sma=dict(length=[20, 50]),
|
|
76
|
+
rsi=dict(length=14),
|
|
77
|
+
macd=dict(fast=12, slow=26, signal=9),
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
res.show()
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
List every available indicator and its parameters:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
res.charting.indicators() # from a result
|
|
87
|
+
Charting.indicators() # standalone
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Building charts directly from data
|
|
91
|
+
|
|
92
|
+
The accessor exposes builders that accept a DataFrame or a list of `Data` (such as `OBBject.results`) and return an `OpenBBFigure`. Their input signatures differ; `create_line_chart` and `create_bar_chart` also display the chart by default — pass `render=False` to build it without displaying.
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
res = obb.equity.price.historical("AAPL", provider="yfinance")
|
|
96
|
+
df = res.to_dataframe()
|
|
97
|
+
|
|
98
|
+
fig = res.charting.create_line_chart(data=res.results, target="close", render=False)
|
|
99
|
+
fig = res.charting.create_bar_chart(
|
|
100
|
+
data=res.results, x="date", y="volume", render=False
|
|
101
|
+
)
|
|
102
|
+
fig = res.charting.create_correlation_matrix(data=res.results, method="pearson")
|
|
103
|
+
fig = res.charting.create_3d_surface(X=df["open"], Y=df["high"], Z=df["close"])
|
|
104
|
+
fig.show()
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Adding a chart to a command
|
|
108
|
+
|
|
109
|
+
Register a charting-view class through the `openbb_charting_extension` entry-point group in your `pyproject.toml`:
|
|
110
|
+
|
|
111
|
+
```toml
|
|
112
|
+
[project.entry-points."openbb_charting_extension"]
|
|
113
|
+
my_extension = "openbb_my_extension.my_extension_views:MyExtensionViews"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
A view method is matched to an endpoint by replacing the route's slashes with underscores: `/equity/price/historical` → `equity_price_historical`, `/technical/ema` → `technical_ema`. Each method receives the command output as `**kwargs` and returns a `tuple[OpenBBFigure, dict[str, Any]]` — the interactive figure plus the JSON content the API serializes.
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
"""Views for MyExtension."""
|
|
120
|
+
|
|
121
|
+
from typing import Any
|
|
122
|
+
|
|
123
|
+
from openbb_charting.charts.price_historical import price_historical
|
|
124
|
+
from openbb_charting.core.openbb_figure import OpenBBFigure
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class MyExtensionViews:
|
|
128
|
+
"""MyExtension Views."""
|
|
129
|
+
|
|
130
|
+
@staticmethod
|
|
131
|
+
def my_extension_price_historical(**kwargs) -> tuple[OpenBBFigure, dict[str, Any]]:
|
|
132
|
+
"""My Extension Price Historical Chart."""
|
|
133
|
+
return price_historical(**kwargs)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The chart is then produced by setting `chart=True` on the command, or via `result.charting.show()`.
|
|
137
|
+
|
|
138
|
+
## Replacing the engine, hooks, and backend
|
|
139
|
+
|
|
140
|
+
The Platform interfaces (Python, API, CLI, MCP) do not depend on `openbb-charting` by name; they resolve the active engine from whichever OBBject extension registers the `charting` accessor. Three things are pluggable through entry points alone.
|
|
141
|
+
|
|
142
|
+
### Replace the engine
|
|
143
|
+
|
|
144
|
+
Ship an OBBject extension that registers the `charting` accessor:
|
|
145
|
+
|
|
146
|
+
```toml
|
|
147
|
+
[project.entry-points."openbb_obbject_extension"]
|
|
148
|
+
my_charting = "openbb_my_charting:ext" # ext = Extension(name="charting")
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
If `openbb-charting` is uninstalled, your engine is used automatically. When both are installed, select one with `system_settings.charting_extension` (or the `OPENBB_CHARTING_EXTENSION` environment variable). An engine must expose the `functions()` classmethod, and `get_backend_class()` to be usable from the CLI.
|
|
152
|
+
|
|
153
|
+
### Chart lifecycle hooks
|
|
154
|
+
|
|
155
|
+
Register a `ChartingHook` subclass under the `openbb_charting_hooks` group. Hooks run inside chart creation, so they fire for every interface:
|
|
156
|
+
|
|
157
|
+
```toml
|
|
158
|
+
[project.entry-points."openbb_charting_hooks"]
|
|
159
|
+
my_hook = "openbb_my_pkg.hooks:MyHook"
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from openbb_core.app.charting import ChartingHook
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
class MyHook(ChartingHook):
|
|
167
|
+
"""Watermark every figure after it is built."""
|
|
168
|
+
|
|
169
|
+
routes = () # empty matches all routes
|
|
170
|
+
priority = 100 # lower runs first
|
|
171
|
+
|
|
172
|
+
def post_figure(self, context):
|
|
173
|
+
context.figure.add_annotation(text="INTERNAL", opacity=0.1)
|
|
174
|
+
return context
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Stages: `resolve_data`, `pre_figure`, `post_figure`, `pre_render`, `post_render`. A hook mutates `context` in place and/or returns a new one.
|
|
178
|
+
|
|
179
|
+
### Backend override
|
|
180
|
+
|
|
181
|
+
Swap the rendering backend (PyWry / browser / custom) without replacing the engine, via the `openbb_charting_backend` group:
|
|
182
|
+
|
|
183
|
+
```toml
|
|
184
|
+
[project.entry-points."openbb_charting_backend"]
|
|
185
|
+
my_backend = "openbb_my_pkg.backend:MyBackend"
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
A backend is constructed with a single `charting_settings` argument. The override is opt-in: set `system_settings.charting_backend` (or `OPENBB_CHARTING_BACKEND`) to the registered name. Without a selection, the engine keeps its built-in backend.
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# OpenBB Charting
|
|
2
|
+
|
|
3
|
+
Plotly-based charting for the OpenBB Platform. Installing this package registers a `charting` accessor on every `OBBject` command result and enables the `chart=True` argument on Platform endpoints that have a chart.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install openbb-charting
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
To display charts in a native desktop window, install the PyWry extra:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install "openbb-charting[pywry]"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
On Linux, PyWry requires system WebKit/GTK libraries:
|
|
18
|
+
|
|
19
|
+
- Debian / Ubuntu / Mint: `sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev`
|
|
20
|
+
- Arch / Manjaro: `sudo pacman -S webkit2gtk`
|
|
21
|
+
- Fedora: `sudo dnf install gtk3-devel webkit2gtk3-devel`
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Pass `chart=True` to an endpoint that has a chart, then call `show()` on the result:
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from openbb import obb
|
|
29
|
+
|
|
30
|
+
data = obb.equity.price.historical("AAPL", provider="yfinance", chart=True)
|
|
31
|
+
data.show()
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The same chart is reachable through the `charting` accessor on any result, without `chart=True`:
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
res = obb.equity.price.historical("AAPL", provider="yfinance")
|
|
38
|
+
res.charting.show()
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Which commands have a chart
|
|
42
|
+
|
|
43
|
+
Charts are contributed by the installed extensions. List the registered routes:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from openbb_charting import Charting
|
|
47
|
+
|
|
48
|
+
Charting.functions()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Technical-analysis overlays — `to_chart`
|
|
52
|
+
|
|
53
|
+
`to_chart` rebuilds the chart of a time-series (OHLCV) result with indicator overlays. Indicators and their parameters are passed through the `indicators` argument:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
res = obb.equity.price.historical("AAPL", provider="yfinance")
|
|
57
|
+
res.charting.to_chart(
|
|
58
|
+
indicators=dict(
|
|
59
|
+
sma=dict(length=[20, 50]),
|
|
60
|
+
rsi=dict(length=14),
|
|
61
|
+
macd=dict(fast=12, slow=26, signal=9),
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
res.show()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
List every available indicator and its parameters:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
res.charting.indicators() # from a result
|
|
71
|
+
Charting.indicators() # standalone
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Building charts directly from data
|
|
75
|
+
|
|
76
|
+
The accessor exposes builders that accept a DataFrame or a list of `Data` (such as `OBBject.results`) and return an `OpenBBFigure`. Their input signatures differ; `create_line_chart` and `create_bar_chart` also display the chart by default — pass `render=False` to build it without displaying.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
res = obb.equity.price.historical("AAPL", provider="yfinance")
|
|
80
|
+
df = res.to_dataframe()
|
|
81
|
+
|
|
82
|
+
fig = res.charting.create_line_chart(data=res.results, target="close", render=False)
|
|
83
|
+
fig = res.charting.create_bar_chart(
|
|
84
|
+
data=res.results, x="date", y="volume", render=False
|
|
85
|
+
)
|
|
86
|
+
fig = res.charting.create_correlation_matrix(data=res.results, method="pearson")
|
|
87
|
+
fig = res.charting.create_3d_surface(X=df["open"], Y=df["high"], Z=df["close"])
|
|
88
|
+
fig.show()
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Adding a chart to a command
|
|
92
|
+
|
|
93
|
+
Register a charting-view class through the `openbb_charting_extension` entry-point group in your `pyproject.toml`:
|
|
94
|
+
|
|
95
|
+
```toml
|
|
96
|
+
[project.entry-points."openbb_charting_extension"]
|
|
97
|
+
my_extension = "openbb_my_extension.my_extension_views:MyExtensionViews"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
A view method is matched to an endpoint by replacing the route's slashes with underscores: `/equity/price/historical` → `equity_price_historical`, `/technical/ema` → `technical_ema`. Each method receives the command output as `**kwargs` and returns a `tuple[OpenBBFigure, dict[str, Any]]` — the interactive figure plus the JSON content the API serializes.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
"""Views for MyExtension."""
|
|
104
|
+
|
|
105
|
+
from typing import Any
|
|
106
|
+
|
|
107
|
+
from openbb_charting.charts.price_historical import price_historical
|
|
108
|
+
from openbb_charting.core.openbb_figure import OpenBBFigure
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class MyExtensionViews:
|
|
112
|
+
"""MyExtension Views."""
|
|
113
|
+
|
|
114
|
+
@staticmethod
|
|
115
|
+
def my_extension_price_historical(**kwargs) -> tuple[OpenBBFigure, dict[str, Any]]:
|
|
116
|
+
"""My Extension Price Historical Chart."""
|
|
117
|
+
return price_historical(**kwargs)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The chart is then produced by setting `chart=True` on the command, or via `result.charting.show()`.
|
|
121
|
+
|
|
122
|
+
## Replacing the engine, hooks, and backend
|
|
123
|
+
|
|
124
|
+
The Platform interfaces (Python, API, CLI, MCP) do not depend on `openbb-charting` by name; they resolve the active engine from whichever OBBject extension registers the `charting` accessor. Three things are pluggable through entry points alone.
|
|
125
|
+
|
|
126
|
+
### Replace the engine
|
|
127
|
+
|
|
128
|
+
Ship an OBBject extension that registers the `charting` accessor:
|
|
129
|
+
|
|
130
|
+
```toml
|
|
131
|
+
[project.entry-points."openbb_obbject_extension"]
|
|
132
|
+
my_charting = "openbb_my_charting:ext" # ext = Extension(name="charting")
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
If `openbb-charting` is uninstalled, your engine is used automatically. When both are installed, select one with `system_settings.charting_extension` (or the `OPENBB_CHARTING_EXTENSION` environment variable). An engine must expose the `functions()` classmethod, and `get_backend_class()` to be usable from the CLI.
|
|
136
|
+
|
|
137
|
+
### Chart lifecycle hooks
|
|
138
|
+
|
|
139
|
+
Register a `ChartingHook` subclass under the `openbb_charting_hooks` group. Hooks run inside chart creation, so they fire for every interface:
|
|
140
|
+
|
|
141
|
+
```toml
|
|
142
|
+
[project.entry-points."openbb_charting_hooks"]
|
|
143
|
+
my_hook = "openbb_my_pkg.hooks:MyHook"
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from openbb_core.app.charting import ChartingHook
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class MyHook(ChartingHook):
|
|
151
|
+
"""Watermark every figure after it is built."""
|
|
152
|
+
|
|
153
|
+
routes = () # empty matches all routes
|
|
154
|
+
priority = 100 # lower runs first
|
|
155
|
+
|
|
156
|
+
def post_figure(self, context):
|
|
157
|
+
context.figure.add_annotation(text="INTERNAL", opacity=0.1)
|
|
158
|
+
return context
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Stages: `resolve_data`, `pre_figure`, `post_figure`, `pre_render`, `post_render`. A hook mutates `context` in place and/or returns a new one.
|
|
162
|
+
|
|
163
|
+
### Backend override
|
|
164
|
+
|
|
165
|
+
Swap the rendering backend (PyWry / browser / custom) without replacing the engine, via the `openbb_charting_backend` group:
|
|
166
|
+
|
|
167
|
+
```toml
|
|
168
|
+
[project.entry-points."openbb_charting_backend"]
|
|
169
|
+
my_backend = "openbb_my_pkg.backend:MyBackend"
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
A backend is constructed with a single `charting_settings` argument. The override is opt-in: set `system_settings.charting_backend` (or `OPENBB_CHARTING_BACKEND`) to the registered name. Without a selection, the engine keeps its built-in backend.
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Examples
|
|
3
|
+
sidebar_position: 1
|
|
4
|
+
description: This page provides examples of creating charts with the `openbb-charting` extension.
|
|
5
|
+
keywords:
|
|
6
|
+
- tutorial
|
|
7
|
+
- OpenBB Platform
|
|
8
|
+
- Python client
|
|
9
|
+
- Fast API
|
|
10
|
+
- getting started
|
|
11
|
+
- extensions
|
|
12
|
+
- charting
|
|
13
|
+
- view
|
|
14
|
+
- Plotly
|
|
15
|
+
- toolkits
|
|
16
|
+
- how-to
|
|
17
|
+
- generic
|
|
18
|
+
- figure
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
import HeadTitle from '@site/src/components/General/HeadTitle.tsx';
|
|
22
|
+
|
|
23
|
+
<HeadTitle title="Examples - OpenBB Charting - Extensions | OpenBB Platform Docs" />
|
|
24
|
+
|
|
25
|
+
## Overview
|
|
26
|
+
|
|
27
|
+
This page will walk through creating different charts using the `openbb-charting` extension.
|
|
28
|
+
The perspective for this content is from the Python Interface,
|
|
29
|
+
and the examples will assume that the OpenBB Platform is installed with all optional packages.
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from datetime import datetime, timedelta
|
|
33
|
+
from openbb import obb
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Cumulative Returns
|
|
37
|
+
|
|
38
|
+
The historical (equity) prices can be requested for multiple symbols.
|
|
39
|
+
The extension will attempt to handle variations accordingly.
|
|
40
|
+
By default, more than three symbols will draw the chart as cumulative returns from the beginning of the series.
|
|
41
|
+
|
|
42
|
+
### Default View
|
|
43
|
+
|
|
44
|
+
The tickers below are a collection of State Street Global Advisors SPDR funds, representing S&P 500 components.
|
|
45
|
+
The data is looking back five years.
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
SPDRS = [
|
|
49
|
+
"SPY",
|
|
50
|
+
"XLE",
|
|
51
|
+
"XLB",
|
|
52
|
+
"XLI",
|
|
53
|
+
"XHB",
|
|
54
|
+
"XLP",
|
|
55
|
+
"XLY",
|
|
56
|
+
"XRT",
|
|
57
|
+
"XLF",
|
|
58
|
+
"XLV",
|
|
59
|
+
"XLK",
|
|
60
|
+
"XLC",
|
|
61
|
+
"XLU",
|
|
62
|
+
"XLRE",
|
|
63
|
+
]
|
|
64
|
+
start_date = (datetime.now() - timedelta(weeks=52 * 5)).date()
|
|
65
|
+
spdrs = obb.equity.price.historical(
|
|
66
|
+
SPDRS, start_date=start_date, provider="yfinance", chart=True
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
spdrs.show()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+

|
|
73
|
+
|
|
74
|
+
### Redraw as YTD
|
|
75
|
+
|
|
76
|
+
The `charting` attribute of the command output has methods for creating the chart again.
|
|
77
|
+
The `data` parameter allows modifications to the data before creating the figure.
|
|
78
|
+
In this example, the length of the data is trimmed to the beginning of the year.
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
new_data = spdrs.to_df().loc[datetime(2024, 12, 29).date() :]
|
|
82
|
+
spdrs.charting.to_chart(data=new_data, title="YTD")
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
:::note
|
|
86
|
+
This replaces the chart that was already created.
|
|
87
|
+
:::
|
|
88
|
+
|
|
89
|
+

|
|
90
|
+
|
|
91
|
+
## Price Performance Bar Chart
|
|
92
|
+
|
|
93
|
+
The `obb.equity.price.performance` endpoint will create a bar chart over intervals.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
price_performance = obb.equity.price.performance(SPDRS, chart=True)
|
|
97
|
+
price_performance.show()
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+

|
|
101
|
+
|
|
102
|
+
### Create Bar Chart
|
|
103
|
+
|
|
104
|
+
This example uses the `create_bar_chart()` method, which does not replace the existing chart, in `price_performance.chart`.
|
|
105
|
+
It isolates the one-month performance and orients the layout as horizontal.
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
new_data = price_performance.to_df().set_index("symbol").multiply(100).reset_index()
|
|
109
|
+
price_performance.charting.create_bar_chart(
|
|
110
|
+
data=new_data,
|
|
111
|
+
x="symbol",
|
|
112
|
+
y="one_month",
|
|
113
|
+
orientation="h",
|
|
114
|
+
title="One Month Price Performance",
|
|
115
|
+
xtitle="Percent (%)",
|
|
116
|
+
)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+

|
|
120
|
+
|
|
121
|
+
## Create Your Own
|
|
122
|
+
|
|
123
|
+
This example analyzes the share volume turnover of the S&P 500 Energy Sector constituents, year-to-date.
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
symbols = [
|
|
127
|
+
"XOM",
|
|
128
|
+
"CVX",
|
|
129
|
+
"COP",
|
|
130
|
+
"WMB",
|
|
131
|
+
"EOG",
|
|
132
|
+
"KMI",
|
|
133
|
+
"OKE",
|
|
134
|
+
"MPC",
|
|
135
|
+
"PSX",
|
|
136
|
+
"SLB",
|
|
137
|
+
"VLO",
|
|
138
|
+
"BKR",
|
|
139
|
+
"HES",
|
|
140
|
+
"TRGP",
|
|
141
|
+
"EQT",
|
|
142
|
+
"OXY",
|
|
143
|
+
"TPL",
|
|
144
|
+
"FANG",
|
|
145
|
+
"EXE",
|
|
146
|
+
"DVN",
|
|
147
|
+
"HAL",
|
|
148
|
+
"CTRA",
|
|
149
|
+
"APA",
|
|
150
|
+
]
|
|
151
|
+
data = obb.equity.price.historical(
|
|
152
|
+
symbols, start_date="2025-01-01", provider="yfinance"
|
|
153
|
+
)
|
|
154
|
+
create_bar_chart = data.charting.create_bar_chart
|
|
155
|
+
volume = data.to_df().groupby("symbol").sum()["volume"]
|
|
156
|
+
shares = (
|
|
157
|
+
obb.equity.profile(symbols, provider="yfinance")
|
|
158
|
+
.to_df()
|
|
159
|
+
.set_index("symbol")["shares_float"]
|
|
160
|
+
)
|
|
161
|
+
df = volume.to_frame().join(shares)
|
|
162
|
+
df["Turnover"] = (df.volume / df.shares_float).round(4)
|
|
163
|
+
df = df.sort_values(by="Turnover", ascending=False).reset_index()
|
|
164
|
+
create_bar_chart(
|
|
165
|
+
data=df,
|
|
166
|
+
x="symbol",
|
|
167
|
+
y="Turnover",
|
|
168
|
+
title="S&P Energy Sector YTD Turnover Rate",
|
|
169
|
+
)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+

|