alphax/tests/test_vp_fly_recency.py
2026-05-13 22:49:47 +08:00

51 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import sys
import pandas as pd
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from app.services.altcoin_screener import detect_volume_price_fly
from app.services.altcoin_confirm import detect_volume_price_fly_1h
def _sample_df(stale_age_hours=9):
rows = []
base_time = pd.Timestamp('2026-05-10 00:00:00')
# 12根 recent + 前20均量所需历史默认低量小阳/小阴
for i in range(32):
rows.append({
'time': base_time + pd.Timedelta(hours=i),
'open': 1.0,
'high': 1.01,
'low': 0.99,
'close': 1.002,
'volume': 100.0,
})
# recent 中距离最新 stale_age_hours 的那根制造放量大阳线
target_idx = len(rows) - 1 - stale_age_hours
rows[target_idx].update({'open': 1.0, 'high': 1.3, 'low': 0.99, 'close': 1.25, 'volume': 2000.0})
return pd.DataFrame(rows)
def test_stale_1h_volume_price_fly_not_counted_as_current_signal():
df = _sample_df(stale_age_hours=9)
result = detect_volume_price_fly(df)
assert result['vp_fly_count'] == 0
assert result['stale_vp_fly_count'] >= 1
assert result['stale_vp_fly_details'][0]['age_hours'] == 9
def test_confirm_layer_stale_volume_price_fly_not_confirmed():
df = _sample_df(stale_age_hours=9)
result = detect_volume_price_fly_1h(df)
assert result['vp_fly_count'] == 0
assert result['stale_vp_fly_count'] >= 1
def test_recent_1h_volume_price_fly_is_counted():
df = _sample_df(stale_age_hours=1)
result = detect_volume_price_fly(df)
assert result['vp_fly_count'] == 1
assert result['vp_fly_details'][0]['age_hours'] == 1