Skip to content

Commit

Permalink
fix parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
femtotrader committed Jul 28, 2023
1 parent 5cc9af3 commit fe30673
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion parameters_explorer/parameters_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ def __str__(self):
s += "\n\t\t" + repr(constraint)
return s

def add_parameter(self, name, default, values=None, typ=float):
def add_parameter(self, name, default, values=None, typ=None):
assert name not in self._parameters.names, f"parameter '{name}' was ever set"
if values is None:
values = [default]
if typ is None:
typ = type(default)
self._parameters.names.append(name)
self._parameters.default[name] = typ(default)
self._parameters.values[name] = values
Expand Down
14 changes: 14 additions & 0 deletions tests/test_parameters_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ def test_pe_example3_noparameters():
assert explorer.count_runs == 1
parameters = [p for p in explorer.parameters()]
assert parameters[0]._asdict() == {}


def test_pe_example4_noexploration_assert_type():
explorer = ParametersExplorer()
explorer.add_parameter("fast_period", 8)
explorer.add_parameter("slow_period", 12)
explorer.add_parameter("signal_period", 10)
explorer.add_parameter("rogers_satchell_vol_period", 30)
explorer.add_constraint(lambda p: p.fast_period < p.slow_period)
parameters = [p for p in explorer.parameters()]
assert isinstance(parameters[0].fast_period, int)
assert isinstance(parameters[0].slow_period, int)
assert isinstance(parameters[0].signal_period, int)
assert isinstance(parameters[0].rogers_satchell_vol_period, int)

0 comments on commit fe30673

Please sign in to comment.