stock_system/src/screener/c_canslim.py
2025-02-03 21:53:26 -08:00

76 lines
2.1 KiB
Python

def check_quarterly_earnings(quarterly_eps):
"""
Checks 25%+ growth in the most recent quarter and, if possible,
accelerating growth quarter over quarter.
Returns:
float: Score (1 pass, 0 fail, 0.25 insufficient data).
"""
if not quarterly_eps or len(quarterly_eps) < 2:
return 0.25 # not enough data
old_eps = quarterly_eps[-2]
new_eps = quarterly_eps[-1]
if old_eps <= 0:
return 0.25 # can't compute growth properly
growth = (new_eps - old_eps) / abs(old_eps) * 100
if growth < 25:
return 0 # fails the 25% growth condition
# Check acceleration if we have at least 3 quarters
if len(quarterly_eps) >= 3:
older_eps = quarterly_eps[-3]
if older_eps <= 0:
# can't compare properly, but the 25% is met
return 1
prev_growth = (old_eps - older_eps) / abs(older_eps) * 100
if growth >= prev_growth:
# accelerating
return 1
else:
# not accelerating but still >=25% for last quarter
return 1
return 1 # only 2 quarters, meets 25% condition
def check_sales_growth(quarterly_sales):
"""
Checks for 20%-25% or higher sales growth in the most recent quarter.
Returns:
float: 1 (Pass), 0 (Fail), 0.25 (Insufficient data).
"""
if not quarterly_sales or len(quarterly_sales) < 2:
return 0.25 # Not enough data
old_sales = quarterly_sales[-2]
new_sales = quarterly_sales[-1]
# Handle None values before making calculations
if old_sales is None or new_sales is None:
return 0.25
if old_sales <= 0:
return 0.25 # Can't compute growth properly
growth = (new_sales - old_sales) / abs(old_sales) * 100
return 1 if growth >= 20 else 0 # Pass if growth is 20%+
def check_return_on_equity(roe):
"""
Checks for >=17% ROE.
Returns:
float: Score (1 pass, 0 fail, 0.25 insufficient data).
"""
if roe is None:
return 0.25
if roe >= 17:
return 1
return 0