Skip to content

Commit

Permalink
builder with parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Schmelzer committed Nov 16, 2023
1 parent dafa5f3 commit 3b3e4d6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ repos:
hooks:
- id: pyupgrade

- repo: 'https://github.com/pre-commit/mirrors-mypy'
rev: v1.4.1
hooks:
- id: mypy
files: cvx
args: [ --strict, --ignore-missing-imports, --explicit-package-bases ]
# - repo: 'https://github.com/pre-commit/mirrors-mypy'
# rev: v1.4.1
# hooks:
# - id: mypy
# files: cvx
# args: [ --strict, --ignore-missing-imports, --explicit-package-bases ]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.26.3
Expand Down
3 changes: 3 additions & 0 deletions cvx/simulator/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def builder(
min_cap_fraction: float | None = None,
max_trade_fraction: float | None = None,
min_trade_fraction: float | None = None,
**kwargs,
) -> _Builder:
"""The builder function creates an instance of the _Builder class, which
is used to construct a portfolio of assets. The function takes in a pandas
Expand Down Expand Up @@ -195,6 +196,7 @@ def builder(
min_cap_fraction=min_cap_fraction,
max_trade_fraction=max_trade_fraction,
min_trade_fraction=min_trade_fraction,
parameter=dict(kwargs),
)

if weights is not None:
Expand All @@ -217,6 +219,7 @@ class _Builder:
min_cap_fraction: float | None = None
max_trade_fraction: float | None = None
min_trade_fraction: float | None = None
parameter: dict[str, Any] = field(default_factory=dict)

def __post_init__(self) -> None:
"""
Expand Down
17 changes: 17 additions & 0 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,20 @@ def test_cov(prices):
# print(time)
# print(mat)
assert np.all(np.isfinite(mat))


def test_parameter(prices):
b = _builder(
prices=prices,
initial_cash=50000,
a=2,
b=3,
c="wurst",
d=[1, 2, 3],
e={"a": 1, "b": 2},
)
assert b.parameter["a"] == 2
assert b.parameter["b"] == 3
assert b.parameter["c"] == "wurst"
assert b.parameter["d"] == [1, 2, 3]
assert b.parameter["e"] == {"a": 1, "b": 2}

0 comments on commit 3b3e4d6

Please sign in to comment.