本地策略可行
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
"""策略2中证 A500 与沪深 300 双轴图测试。"""
|
||||
|
||||
from datetime import date
|
||||
|
||||
from strategy.a500_close_chart import ClosePoint
|
||||
from strategy.a500_hs300_close_chart import DualAxisSeries, _scale_points_by_ratio, align_points_by_date, build_dual_axis_svg_chart
|
||||
|
||||
|
||||
def test_5_1_align_points_by_common_date() -> None:
|
||||
"""
|
||||
功能说明:验证策略2按共同交易日对齐两组收盘价。
|
||||
参数说明:无。
|
||||
返回值说明:无返回值。
|
||||
注意事项:用例编号 5-1。
|
||||
"""
|
||||
left = [ClosePoint(date(2024, 9, 23), 100), ClosePoint(date(2024, 9, 24), 101)]
|
||||
right = [ClosePoint(date(2024, 9, 24), 201), ClosePoint(date(2024, 9, 25), 202)]
|
||||
|
||||
aligned_left, aligned_right = align_points_by_date(left, right)
|
||||
|
||||
assert aligned_left == [ClosePoint(date(2024, 9, 24), 101)]
|
||||
assert aligned_right == [ClosePoint(date(2024, 9, 24), 201)]
|
||||
|
||||
|
||||
def test_5_2_build_dual_axis_svg_chart() -> None:
|
||||
"""
|
||||
功能说明:验证策略2可生成包含双轴和两条折线的 SVG。
|
||||
参数说明:无。
|
||||
返回值说明:无返回值。
|
||||
注意事项:用例编号 5-2。
|
||||
"""
|
||||
left = DualAxisSeries(
|
||||
"中证 A500",
|
||||
"sh000510",
|
||||
"#2563eb",
|
||||
[ClosePoint(date(2024, 9, 23), 3700), ClosePoint(date(2024, 9, 24), 3710)],
|
||||
)
|
||||
right = DualAxisSeries(
|
||||
"沪深 300",
|
||||
"sh000300",
|
||||
"#dc2626",
|
||||
[ClosePoint(date(2024, 9, 23), 3300), ClosePoint(date(2024, 9, 24), 3310)],
|
||||
)
|
||||
|
||||
svg = build_dual_axis_svg_chart(left, right, "中证 A500 与沪深 300 收盘价对比")
|
||||
|
||||
assert svg.startswith("<svg")
|
||||
assert "中证 A500 与沪深 300 收盘价对比" in svg
|
||||
assert "中证 A500(左轴)" in svg
|
||||
assert "沪深 300(右轴)" in svg
|
||||
assert svg.count("<polyline") == 2
|
||||
|
||||
|
||||
def test_5_3_same_return_ratio_maps_to_same_y() -> None:
|
||||
"""
|
||||
功能说明:验证策略2相同涨跌比例会映射到相同 Y 坐标。
|
||||
参数说明:无。
|
||||
返回值说明:无返回值。
|
||||
注意事项:用例编号 5-3,两个指数起点不同但第二天都上涨 10%。
|
||||
"""
|
||||
left = [ClosePoint(date(2024, 9, 23), 1000), ClosePoint(date(2024, 9, 24), 1100)]
|
||||
right = [ClosePoint(date(2024, 9, 23), 3000), ClosePoint(date(2024, 9, 24), 3300)]
|
||||
|
||||
left_coordinates = _scale_points_by_ratio(left, 1000, 0, 0, 100, 100, 0, 0.1)
|
||||
right_coordinates = _scale_points_by_ratio(right, 3000, 0, 0, 100, 100, 0, 0.1)
|
||||
|
||||
assert left_coordinates[0][1] == right_coordinates[0][1]
|
||||
assert left_coordinates[1][1] == right_coordinates[1][1]
|
||||
Reference in New Issue
Block a user