Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
furechan committed Oct 24, 2024
1 parent 55ef85c commit cfc5ba1
Show file tree
Hide file tree
Showing 8 changed files with 307 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ indicators = [
Indicators usually plot in a new axes below, except for a few indicators that plot by default in the main axes. You can change the target axes for any indicator by piping it into an axes primitive as in the example below.

```python
# Plotting two indicators on the same axes with SameAxes
# Plotting two indicators on the same axes with SameAxes primitive

from mplchart.indicators import SMA, EMA, ROC
from mplchart.primitives import Candlesticks, SameAxes
Expand Down
10 changes: 6 additions & 4 deletions examples/bollinger-bands.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/talib-examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
}
],
"source": [
"# Classic Chart with SMA, RSI and MACD\n",
"# Candlesticks chart with SMA, RSI and MACD\n",
"\n",
"title = \"Talib Example\"\n",
"max_bars = 250\n",
Expand Down
45 changes: 16 additions & 29 deletions misc/axes-primitives.ipynb

Large diffs are not rendered by default.

249 changes: 249 additions & 0 deletions misc/mplchart-help.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from mplchart import utils\n",
"\n",
"from mplchart.chart import Chart\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on class Chart in module mplchart.chart:\n",
"\n",
"class Chart(builtins.object)\n",
" | Chart(title=None, max_bars=None, start=None, end=None, figure=None, figsize=None, bgcolor=None, holidays=None, raw_dates=False, color_scheme=())\n",
" | \n",
" | Chart Object\n",
" | \n",
" | Args:\n",
" | title (str) : the chart title\n",
" | max_bars (int) : the maximum number of bars to plot\n",
" | start, end (datetime | str) : the start and end date of the range to plot\n",
" | figsize (tuple) : the size of the figure\n",
" | \n",
" | Example:\n",
" | chart = Chart(title=tiltle, ...)\n",
" | chart.plot(prices, indicators)\n",
" | \n",
" | Methods defined here:\n",
" | \n",
" | __init__(self, title=None, max_bars=None, start=None, end=None, figure=None, figsize=None, bgcolor=None, holidays=None, raw_dates=False, color_scheme=())\n",
" | Initialize self. See help(type(self)) for accurate signature.\n",
" | \n",
" | add_legends(self)\n",
" | adds legends to all axes\n",
" | \n",
" | calc_result(self, prices, indicator)\n",
" | calculates indicator result saving last result\n",
" | \n",
" | config_axes(self, ax, root=False)\n",
" | configures axes\n",
" | \n",
" | count_axes(self, include_root=False, include_twins=False)\n",
" | \" counts axes that are neither root or twinx\n",
" | \n",
" | counter = <functools.cached_property object>\n",
" | dump_axes(self)\n",
" | \n",
" | extract_df(self, data)\n",
" | extract dataframe subset\n",
" | \n",
" | figure = <functools.cached_property object>\n",
" | force_target(self, target)\n",
" | force target for next get_axes\n",
" | \n",
" | get_axes(self, target=None, *, height_ratio=None)\n",
" | selects existing axes or creates new axes depending on target\n",
" | \n",
" | Args:\n",
" | target: one of \"main\", \"same\", twinx\", \"above\", \"below\"\n",
" | \n",
" | get_color(self, name, ax=None, indicator=None, *, fallback=None)\n",
" | Lookup color through indicator and color_scheme\n",
" | \n",
" | get_target(self, indicator)\n",
" | target axes for indicator\n",
" | \n",
" | init_axes(self)\n",
" | create root axes\n",
" | \n",
" | init_mapper(self, data)\n",
" | initalizes chart and mapper with price data\n",
" | \n",
" | main_axes(self)\n",
" | returns main axes, usualy axes[1]\n",
" | \n",
" | map_date(self, date)\n",
" | map date to value\n",
" | \n",
" | next_fill_color(self, ax)\n",
" | Next cycled color for fill\n",
" | \n",
" | next_line_color(self, ax)\n",
" | Next line color either text.color or cycled color\n",
" | \n",
" | plot(self, prices, indicators, *, target=None, rebase=False)\n",
" | plots a list of indicators\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | prices: dataframe\n",
" | the prices data frame\n",
" | indicators: list of indicators\n",
" | list of indciators to plot\n",
" | \n",
" | plot_indicator(self, data, indicator)\n",
" | calculates and plots an indicator\n",
" | \n",
" | plot_result(self, result, indicator, ax=None)\n",
" | last resort plot_result handler\n",
" | \n",
" | plot_vline(self, date)\n",
" | plots a vertical line across all axes\n",
" | \n",
" | rebase_data(self, data)\n",
" | \n",
" | render(self, format='svg')\n",
" | renders the chart to the specific format\n",
" | \n",
" | root_axes(self)\n",
" | returns root axes, usualy axes[0]\n",
" | \n",
" | set_title(self, title)\n",
" | Sets chart title on root axes. Must be called after init_axes!\n",
" | \n",
" | show(self)\n",
" | shows the chart\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Static methods defined here:\n",
" | \n",
" | normalize(prices)\n",
" | \n",
" | valid_target(target)\n",
" | whether the target bname is valid\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data descriptors defined here:\n",
" | \n",
" | __dict__\n",
" | dictionary for instance variables (if defined)\n",
" | \n",
" | __weakref__\n",
" | list of weak references to the object (if defined)\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data and other attributes defined here:\n",
" | \n",
" | DEFAULT_FIGSIZE = (12, 9)\n",
" | \n",
" | last_result = None\n",
" | \n",
" | layout = <class 'mplchart.layout.StandardLayout'>\n",
" | Grispec Baeed Layout\n",
" | \n",
" | \n",
" | mapper = None\n",
" | \n",
" | next_target = None\n",
" | \n",
" | source_data = None\n",
"\n"
]
}
],
"source": [
"help(Chart)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on module mplchart.utils in mplchart:\n",
"\n",
"NAME\n",
" mplchart.utils - mplchart utils\n",
"\n",
"FUNCTIONS\n",
" get_label(indicator)\n",
" indicator label\n",
" \n",
" get_name(indicator)\n",
" indicator name\n",
" \n",
" get_series(prices, item: str = None)\n",
" extract column by name if applicable\n",
" \n",
" same_scale(indicator)\n",
" Whether indicator uses the same scale as inputs\n",
" \n",
" series_data(data, item: str = None, *, default_item: str = None, strict: bool = False)\n",
" \n",
" series_xy(data, item=None, *, dropna=False)\n",
" split data into x, y arrays\n",
" \n",
" short_repr(self)\n",
" short repr based on __init__ signature\n",
"\n",
"DATA\n",
" TALIB_SAME_SCALE = 'Output scale same as input'\n",
"\n",
"FILE\n",
" /Users/frederic/Projects/mplchart/src/mplchart/utils.py\n",
"\n",
"\n"
]
}
],
"source": [
"help(utils)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.19"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ classifiers = [
]

[project.optional-dependencies]
extras = ["yfinance", "pytest", "nbmake", "ipykernel", "ta-lib", "ruff", "jinja2"]

[tool.hatch.version]
path = "src/mplchart/__init__.py"
dev = ["yfinance", "pytest", "nbmake", "ipykernel", "ta-lib", "ruff", "jinja2"]

[tool.hatch.build]
targets.wheel.sources = ["src"]
Expand All @@ -38,3 +35,7 @@ exclude = [".*"]
[tool.pytest.ini_options]
addopts = ["-p no:cacheprovider"]
testpaths = ["tests"]

[tool.hatch.envs.default]
type = "virtual"
path = ".venv"
50 changes: 27 additions & 23 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# noinspection PyUnresolvedReferences

import re

from pathlib import Path
from invoke import task # type: ignore

Expand All @@ -9,54 +10,55 @@


@task
def setup(c):
"""Check package versions"""
c.run("pip install \"numpy<2.0.0\"")
c.run("pip install -e \".[extras]\"")
def setup(ctx):
"""Install package with extras"""
ctx.run('pip install "numpy<2.0.0"')
ctx.run('pip install -e ".[dev]"')


@task
def info(c):
def info(ctx):
"""Check package versions"""
c.run(f"pip index versions {PACKAGE}")
ctx.run(f"pip index versions {PACKAGE}")


@task
def clean(c):
def clean(ctx):
"""Clean project dist"""
c.run("rm -rf dist")
ctx.run("rm -rf dist")


@task
def check(c):
def check(ctx):
"""Check package"""
c.run("pip install -q ruff nbcheck")
c.run("nbcheck examples misc")
c.run("ruff check")
ctx.run("pip install -q ruff nbcheck")
ctx.run("nbcheck examples misc")
ctx.run("ruff check")


@task(clean)
def build(c):
def build(ctx):
"""Build project wheel"""
c.run("pip install -q build")
c.run("python -mbuild --wheel")
ctx.run("pip install -q build")
ctx.run("python -mbuild --wheel")


@task
def dump(c):
def dump(ctx):
"""Dump wheel contents"""
for file in FOLDER.glob("dist/*.whl"):
c.run(f"unzip -l {file}")
ctx.run(f"unzip -l {file}")


@task
def publish(c):
def publish(ctx):
"""Publish to PyPI with twine"""
c.run("pip install -q twine")
c.run("twine upload dist/*.whl")
ctx.run("pip install -q twine")
ctx.run("twine upload dist/*.whl")


@task
def bump(c):
def bump(ctx):
"""Bump patch version in pyproject"""
pyproject = Path(__file__).joinpath("../pyproject.toml").resolve(strict=True)
buffer = pyproject.read_text()
Expand All @@ -65,8 +67,10 @@ def bump(c):
if not match:
raise ValueError("Could not find version setting")
version = tuple(int(i) for i in match.group(1).split("."))
version = version[:-1] + (version[-1]+1, )
version = version[:-1] + (version[-1] + 1,)
version = ".".join(str(v) for v in version)
print(f"Updating version to {version} ...")
output = re.sub(pattern, f"version = \"{version}\"\n", buffer, flags=re.VERBOSE | re.MULTILINE)
output = re.sub(
pattern, f'version = "{version}"\n', buffer, flags=re.VERBOSE | re.MULTILINE
)
pyproject.write_text(output)
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

[tox]
isolated_build = True
toxworkdir={env:TMPDIR}/mplchart.tox
toxworkdir = .venv/tox
envlist = py{39,310,311,312,313}, lint
# toxworkdir={env:TMPDIR}/mplchart.tox

[testenv]
deps = pytest
Expand Down

0 comments on commit cfc5ba1

Please sign in to comment.