Skip to content

Commit

Permalink
to_doc and rename speedup to run_unique
Browse files Browse the repository at this point in the history
  • Loading branch information
polakowo committed May 17, 2021
1 parent 305ed9f commit ca680ad
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 124 deletions.
32 changes: 16 additions & 16 deletions tests/test_indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,17 +1516,17 @@ def custom_func_nb(ts):
for i, other in enumerate(others):
np.testing.assert_array_equal(other[0], ts.iloc[:, [i]] + 2)

def test_speedup(self):
def test_run_unique(self):
F = vbt.IndicatorFactory(input_names=['ts'], param_names=['p1', 'p2'], output_names=['out'])

def apply_func(ts, p1, p2):
return ts * (p1 + p2)

pd.testing.assert_series_equal(
F.from_apply_func(apply_func).run(ts['a'], 2, 3, speedup=True).out,
F.from_apply_func(apply_func).run(ts['a'], 2, 3, speedup=False).out
F.from_apply_func(apply_func).run(ts['a'], 2, 3, run_unique=True).out,
F.from_apply_func(apply_func).run(ts['a'], 2, 3, run_unique=False).out
)
raw = F.from_apply_func(apply_func).run(ts['a'], [2, 2, 2], [3, 3, 3], speedup=True, return_raw=True)
raw = F.from_apply_func(apply_func).run(ts['a'], [2, 2, 2], [3, 3, 3], run_unique=True, return_raw=True)
np.testing.assert_array_equal(
raw[0][0],
np.array([[5.], [10.], [15.], [20.], [25.]])
Expand All @@ -1535,20 +1535,20 @@ def apply_func(ts, p1, p2):
assert raw[2] == 1
assert raw[3] == []
pd.testing.assert_frame_equal(
F.from_apply_func(apply_func).run(ts['a'], [2, 2, 2], [3, 3, 3], speedup=True).out,
F.from_apply_func(apply_func).run(ts['a'], [2, 2, 2], [3, 3, 3], speedup=False).out
F.from_apply_func(apply_func).run(ts['a'], [2, 2, 2], [3, 3, 3], run_unique=True).out,
F.from_apply_func(apply_func).run(ts['a'], [2, 2, 2], [3, 3, 3], run_unique=False).out
)
pd.testing.assert_frame_equal(
F.from_apply_func(apply_func).run(ts, 2, 3, speedup=True).out,
F.from_apply_func(apply_func).run(ts, 2, 3, speedup=False).out
F.from_apply_func(apply_func).run(ts, 2, 3, run_unique=True).out,
F.from_apply_func(apply_func).run(ts, 2, 3, run_unique=False).out
)
pd.testing.assert_frame_equal(
F.from_apply_func(apply_func).run(ts, [2, 2, 2], [3, 3, 3], speedup=True).out,
F.from_apply_func(apply_func).run(ts, [2, 2, 2], [3, 3, 3], speedup=False).out
F.from_apply_func(apply_func).run(ts, [2, 2, 2], [3, 3, 3], run_unique=True).out,
F.from_apply_func(apply_func).run(ts, [2, 2, 2], [3, 3, 3], run_unique=False).out
)
pd.testing.assert_frame_equal(
F.from_apply_func(apply_func).run(ts, [2, 3, 4], [4, 3, 2], speedup=True).out,
F.from_apply_func(apply_func).run(ts, [2, 3, 4], [4, 3, 2], speedup=False).out
F.from_apply_func(apply_func).run(ts, [2, 3, 4], [4, 3, 2], run_unique=True).out,
F.from_apply_func(apply_func).run(ts, [2, 3, 4], [4, 3, 2], run_unique=False).out
)

def test_run_combs(self):
Expand All @@ -1560,9 +1560,9 @@ def test_run_combs(self):
ind2 = F.from_apply_func(lambda ts, p1, p2: ts * p1 * p2) \
.run(ts, [3, 4, 4], [11, 12, 12], short_name='custom_2')
ind1_1, ind2_1 = F.from_apply_func(lambda ts, p1, p2: ts * p1 * p2) \
.run_combs(ts, [2, 3, 4], [10, 11, 12], r=2, speedup=False)
.run_combs(ts, [2, 3, 4], [10, 11, 12], r=2, run_unique=False)
ind1_2, ind2_2 = F.from_apply_func(lambda ts, p1, p2: ts * p1 * p2) \
.run_combs(ts, [2, 3, 4], [10, 11, 12], r=2, speedup=True)
.run_combs(ts, [2, 3, 4], [10, 11, 12], r=2, run_unique=True)
pd.testing.assert_frame_equal(
ind1.out,
ind1_1.out
Expand All @@ -1585,9 +1585,9 @@ def test_run_combs(self):
ind4 = F.from_apply_func(lambda ts, p1, p2: ts * p1 * p2) \
.run(ts, [2, 3, 4, 2, 3, 4, 2, 3, 4], [10, 11, 12, 10, 11, 12, 10, 11, 12], short_name='custom_2')
ind3_1, ind4_1 = F.from_apply_func(lambda ts, p1, p2: ts * p1 * p2) \
.run_combs(ts, [2, 3, 4], [10, 11, 12], r=2, comb_func=product, speedup=False)
.run_combs(ts, [2, 3, 4], [10, 11, 12], r=2, comb_func=product, run_unique=False)
ind3_2, ind4_2 = F.from_apply_func(lambda ts, p1, p2: ts * p1 * p2) \
.run_combs(ts, [2, 3, 4], [10, 11, 12], r=2, comb_func=product, speedup=True)
.run_combs(ts, [2, 3, 4], [10, 11, 12], r=2, comb_func=product, run_unique=True)
pd.testing.assert_frame_equal(
ind3.out,
ind3_1.out
Expand Down
37 changes: 17 additions & 20 deletions vectorbt/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
import plotly.io as pio
import plotly.graph_objects as go

from vectorbt.utils.config import Config, collapse_for_pdoc
from vectorbt.utils.docs import to_doc
from vectorbt.utils.config import Config
from vectorbt.utils.datetime import get_local_tz, get_utc_tz
from vectorbt.utils.decorators import CacheCondition
from vectorbt.base.array_wrapper import ArrayWrapper
Expand Down Expand Up @@ -292,22 +293,14 @@ def reset_theme(self) -> None:
settings.make_checkpoint()
settings.register_templates()

_collapse_keys = {
'settings.plotting.themes.light.template': "{ ... templates/light.json ... }",
'settings.plotting.themes.dark.template': "{ ... templates/dark.json ... }",
'settings.plotting.themes.seaborn.template': "{ ... templates/seaborn.json ... }"
}

_settings_for_pdoc = collapse_for_pdoc(settings, _collapse_keys, 'settings')

__pdoc__['settings'] = f"""Global settings config.
## settings.config
Configuration settings applied across `vectorbt.utils.config`.
```json
{json.dumps(_settings_for_pdoc['config'], indent=4, default=str)}
{to_doc(settings['config'])}
```
## settings.caching
Expand All @@ -317,39 +310,39 @@ def reset_theme(self) -> None:
See `vectorbt.utils.decorators.should_cache`.
```json
{json.dumps(_settings_for_pdoc['caching'], indent=4, default=str)}
{to_doc(settings['caching'])}
```
## settings.broadcasting
Settings applied across `vectorbt.base.reshape_fns`.
```json
{json.dumps(_settings_for_pdoc['broadcasting'], indent=4, default=str)}
{to_doc(settings['broadcasting'])}
```
## settings.array_wrapper
Settings applied to `vectorbt.base.array_wrapper.ArrayWrapper`.
```json
{json.dumps(_settings_for_pdoc['array_wrapper'], indent=4, default=str)}
{to_doc(settings['array_wrapper'])}
```
## settings.datetime
Datetime settings applied across `vectorbt.utils.datetime`.
```json
{json.dumps(_settings_for_pdoc['datetime'], indent=4, default=str)}
{to_doc(settings['datetime'])}
```
## settings.data
Data settings applied across `vectorbt.data`.
```json
{json.dumps(_settings_for_pdoc['data'], indent=4, default=str)}
{to_doc(settings['data'])}
```
### settings.data.binance
Expand All @@ -366,39 +359,43 @@ def reset_theme(self) -> None:
Settings applied to plotting Plotly figures.
```json
{json.dumps(_settings_for_pdoc['plotting'], indent=4, default=str)}
{to_doc(settings['plotting'], replace={
'settings.plotting.themes.light.template': "{ ... templates/light.json ... }",
'settings.plotting.themes.dark.template': "{ ... templates/dark.json ... }",
'settings.plotting.themes.seaborn.template': "{ ... templates/seaborn.json ... }"
}, path='settings.plotting')}
```
## settings.ohlcv
OHLCV settings applied across `vectorbt.ohlcv_accessors`.
```json
{json.dumps(_settings_for_pdoc['ohlcv'], indent=4, default=str)}
{to_doc(settings['ohlcv'])}
```
## settings.returns
Returns settings applied across `vectorbt.returns`.
```json
{json.dumps(_settings_for_pdoc['returns'], indent=4, default=str)}
{to_doc(settings['returns'])}
```
## settings.portfolio
Settings applied to `vectorbt.portfolio.base.Portfolio`.
```json
{json.dumps(_settings_for_pdoc['portfolio'], indent=4, default=str)}
{to_doc(settings['portfolio'])}
```
## settings.messaging
Messaging settings applied across `vectorbt.messaging`.
```json
{json.dumps(_settings_for_pdoc['messaging'], indent=4, default=str)}
{to_doc(settings['messaging'])}
```
### settings.messaging.telegram
Expand Down
9 changes: 3 additions & 6 deletions vectorbt/generic/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Defines enums and other schemas for `vectorbt.generic`."""

import numpy as np
import json

from vectorbt import _typing as tp
from vectorbt.utils.docs import to_doc

__all__ = [
'DrawdownStatus',
Expand All @@ -28,7 +28,7 @@ class DrawdownStatusT(tp.NamedTuple):
__pdoc__['DrawdownStatus'] = f"""Drawdown status.
```json
{json.dumps(dict(zip(DrawdownStatus._fields, DrawdownStatus)), indent=4, default=str)}
{to_doc(DrawdownStatus)}
```
"""

Expand All @@ -45,9 +45,6 @@ class DrawdownStatusT(tp.NamedTuple):
__pdoc__['drawdown_dt'] = f"""`np.dtype` of drawdown records.
```json
{json.dumps(dict(zip(
dict(drawdown_dt.fields).keys(),
list(map(lambda x: str(x[0]), dict(drawdown_dt.fields).values()))
)), indent=4, default=str)}
{to_doc(drawdown_dt)}
```
"""
Loading

0 comments on commit ca680ad

Please sign in to comment.