Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SorrTask1038_Test_get_range_filter #1066

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ def test_get_wave_quantities4(self) -> None:
{1: 1.0, 2: 0.3, 3: 1.0},
)

def test_get_range_filter(self) -> None:
"""
Check that the correct range of expected child orders is returned.
"""
# Set inputs.
bar_duration = "5T"
exec_freq = "2T"
# Test.
range_filter = self._get_range_filter(bar_duration, exec_freq)
actual = str(range_filter)
expected = r"""
[0, 2]
"""
# Check outputs.
self.assert_equal(actual, expected, fuzzy_match=True)

def _get_wave_quantities(
self, num_waves: int, target_wave_id: int, diff_num_shares: List[float]
) -> Dict[int, float]:
Expand All @@ -89,7 +105,8 @@ def _get_wave_quantities(

:param num_waves: number of waves
:param target_wave_id: id of the wave to test
:param diff_num_shares: list of number of shares for each parent order
:param diff_num_shares: list of number of shares for each parent
order
"""
# Define parent orders with different number of shares.
parent_orders = _get_parent_orders(diff_num_shares)
Expand All @@ -113,6 +130,27 @@ def _get_wave_quantities(
)
return wave_quantities

def _get_range_filter(
self,
bar_duration: str,
exec_freq: str,
) -> List[int]:
"""
Get the range of expected number of child orders.

:param bar_duration: bar duration
:param exec_freq: execution frequency
"""
# Initializing the scheduler.
child_order_quantity_computer = (
ocoqcsscoqc.StaticSchedulingChildOrderQuantityComputer()
)
# Call the function to get the range of filter.
range_filter = child_order_quantity_computer.get_range_filter(
bar_duration, exec_freq
)
return range_filter


class TestDynamicSchedulingChildOrderQuantityComputer(hunitest.TestCase):
def test_get_wave_quantities1(self) -> None:
Expand Down Expand Up @@ -194,6 +232,22 @@ def test_get_wave_quantities4(self) -> None:
{1: 4.0, 2: 1.0, 3: 3.0},
)

def test_get_range_filter(self) -> None:
"""
Check that the correct range of expected child orders is returned.
"""
# Set inputs.
bar_duration = "5T"
exec_freq = "2T"
# Test.
range_filter = self._get_range_filter(bar_duration, exec_freq)
actual = str(range_filter)
expected = r"""
[0, 1, 2]
"""
# Check outputs.
self.assert_equal(actual, expected, fuzzy_match=True)

def _get_wave_quantities(
self,
num_waves: int,
Expand All @@ -206,7 +260,8 @@ def _get_wave_quantities(

:param num_waves: number of waves
:param wave_id: id of the wave to test
:param diff_num_shares: list of number of shares for each parent order
:param diff_num_shares: list of number of shares for each parent
order
:param open_positions: dict of open positions
"""
# Define parent orders with different number of shares.
Expand All @@ -232,13 +287,35 @@ def _get_wave_quantities(
)
return wave_quantities

def _get_range_filter(
self,
bar_duration: str,
exec_freq: str,
) -> List[int]:
"""
Get the range of expected number of child orders.

:param bar_duration: bar duration
:param exec_freq: execution frequency
"""
# Initializing the scheduler.
child_order_quantity_computer = (
ocoqcdscoqc.DynamicSchedulingChildOrderQuantityComputer()
)
# Call the function to get the range of filter.
range_filter = child_order_quantity_computer.get_range_filter(
bar_duration, exec_freq
)
return range_filter


def _get_parent_orders(diff_num_shares: List[int]) -> List[oordorde.Order]:
"""
Generate parent orders.

:param diff_num_shares: list of number of shares for each parent order, e.g.
`[1, 2, 3]` for 3 parent orders, 1 share for the first, 2 for the second, 3 for the third.
:param diff_num_shares: list of number of shares for each parent
order, e.g. `[1, 2, 3]` for 3 parent orders, 1 share for the
first, 2 for the second, 3 for the third.
"""
# Create a parent order with 2 assets and 2 waves.
creation_timestamp = pd.Timestamp("2022-08-05 09:30:55+00:00")
Expand Down
Loading