Download backend/reliability_scoring.py from PROSTLE/AarthiAI: direct link, hf CLI and curl.
- Browser
- Download file 2.79 kB
-
https://huggingface.co/spaces/PROSTLE/AarthiAI/resolve/main/backend/reliability_scoring.py
- Command line
-
hf download hf://spaces/PROSTLE/AarthiAI/backend/reliability_scoring.py
-
curl -L -o reliability_scoring.py https://huggingface.co/spaces/PROSTLE/AarthiAI/resolve/main/backend/reliability_scoring.py
2.79 kB
| """ | |
| Reliability Score Calculator (Pseudo-code) | |
| Pillars: | |
| - 40% Fundamental Health (Piotroski F-Score + Altman Z-Score) | |
| - 30% AI News Sentiment (30-day NLP) | |
| - 30% Technical Volatility (Beta + Std Dev penalty) | |
| """ | |
| def compute_fundamentals_score(financials): | |
| """ | |
| Simulates calculating Piotroski F-score and Altman Z-score. | |
| Maps results to a base 100-point scale. | |
| """ | |
| print(f"[*] Calculating fundamental solvency for {financials.get('ticker')}...") | |
| f_score = 7 # Out of 9 | |
| z_score = 3.2 # Safe zone > 2.99 | |
| # Base mapping: F-Score gives up to 60 pts, Z score up to 40 pts | |
| fundamental_strength = (f_score / 9) * 60 + min(40, (z_score / 3.0) * 40) | |
| return fundamental_strength | |
| def compute_sentiment_score(nlp_results): | |
| """ | |
| Analyzes historical sentiment data. Penalizes highly erratic behavior. | |
| """ | |
| bullish_pct = nlp_results.count('bullish') / len(nlp_results) | |
| bearish_pct = nlp_results.count('bearish') / len(nlp_results) | |
| # Scale from 0 to 100. We want a strong bullish ratio. | |
| net_sentiment = bullish_pct - bearish_pct | |
| base = 50 + (net_sentiment * 50) | |
| return max(0, min(100, base)) | |
| def compute_volatility_score(beta, std_dev): | |
| """ | |
| Scores the stock's stability relative to the index. | |
| Beta ~ 1.0 is stable. | |
| High beta / high std dev is penalized for 'long term reliability'. | |
| """ | |
| # Ideal beta for stable reliability is ~0.8 to 1.1 | |
| beta_penalty = abs(1.0 - beta) * 50 | |
| score = 100 - beta_penalty | |
| if std_dev > 0.05: # e.g., >5% daily volatility | |
| score -= 20 | |
| return max(0, min(100, score)) | |
| def calculate_long_term_reliability(ticker: str, fcf: float, sentiment_score: float, beta: float, std_dev: float): | |
| # Base normalization | |
| financials = {"ticker": ticker, "fcf": fcf} | |
| # Pillar Integration weights | |
| W_FUNDAMENTAL = 0.40 | |
| W_SENTIMENT = 0.30 | |
| W_VOLATILITY = 0.30 | |
| # Pseudo-fundamental compute (simulating Piostroski) | |
| f_score = 7 if fcf > 0 else 4 | |
| z_score = 3.2 if fcf > 100_000_000 else 2.5 | |
| fundamental_strength = (f_score / 9) * 60 + min(40, (z_score / 3.0) * 40) | |
| score_fund = fundamental_strength | |
| # Sentiment calculation mapping | |
| score_sent = max(0, min(100, 50 + (sentiment_score * 50))) | |
| # Volatility scoring | |
| score_vol = compute_volatility_score(beta, std_dev) | |
| final_score = ( | |
| (score_fund * W_FUNDAMENTAL) + | |
| (score_sent * W_SENTIMENT) + | |
| (score_vol * W_VOLATILITY) | |
| ) | |
| return { | |
| "ticker": ticker, | |
| "score_out_of_100": int(final_score), | |
| "pillars": { | |
| "fundamentals": round(score_fund, 2), | |
| "sentiment": round(score_sent, 2), | |
| "volatility": round(score_vol, 2) | |
| } | |
| } | |