Jitendra12421 commited on
Commit
a3b7b62
·
verified ·
1 Parent(s): 3f45c8a

Upload 20 files

Browse files
Files changed (1) hide show
  1. forecaster_cli.py +25 -24
forecaster_cli.py CHANGED
@@ -135,16 +135,11 @@ def generate_reasoning(features, tier, prob):
135
 
136
  return " ".join(reasons)
137
 
138
- def run_inference(ticker):
139
  tier = get_market_cap_tier(ticker)
140
- print(f"[{ticker}] Classified as: {tier} Cap")
141
-
142
- print(f"[{ticker}] Extracting live fundamental data...")
143
  features = fetch_live_features(ticker)
144
-
145
  if not features:
146
- print(f"[{ticker}] Error: Could not extract live data.")
147
- return
148
 
149
  df = pd.DataFrame([features])
150
  model_features = ['Sales_Growth', 'OPM', 'ROCE', 'ROE', 'Debt_to_Equity', 'PE_Ratio']
@@ -155,32 +150,38 @@ def run_inference(ticker):
155
  imputer = joblib.load(f'imputer_{tier.lower()}.pkl')
156
  scaler = joblib.load(f'scaler_{tier.lower()}.pkl')
157
  except Exception as e:
158
- print(f"Error loading models: {e}")
159
- return
160
 
161
  X_imputed = imputer.transform(X)
162
  X_scaled = scaler.transform(X_imputed)
163
 
164
- prob = model.predict_proba(X_scaled)[0][1]
165
-
166
- if prob > 0.65:
167
- decision = "BUY"
168
- else:
169
- decision = "PASS"
170
-
171
  reasoning = generate_reasoning(features, tier, prob)
172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  print("\n" + "="*50)
174
- print(f" FORECAST FOR {ticker} ({tier} Cap Model)")
175
  print("="*50)
176
- print(f" Decision: {decision} (Confidence: {prob*100:.1f}%)")
177
- print(f" Reasoning: {reasoning}")
178
  print("-" * 50)
179
- print(f" Sales Growth: {features['Sales_Growth']:.2f}%")
180
- print(f" ROE: {features['ROE']:.2f}%")
181
- print(f" ROCE: {features['ROCE']:.2f}%")
182
- print(f" Debt/Equity: {features['Debt_to_Equity']:.2f}")
183
- print(f" OPM: {features['OPM']:.2f}%")
184
  print("="*50 + "\n")
185
  return {"Ticker": ticker, "Tier": tier, "Decision": decision, **features}
186
 
 
135
 
136
  return " ".join(reasons)
137
 
138
+ def get_prediction(ticker):
139
  tier = get_market_cap_tier(ticker)
 
 
 
140
  features = fetch_live_features(ticker)
 
141
  if not features:
142
+ return {"error": "Could not extract live data."}
 
143
 
144
  df = pd.DataFrame([features])
145
  model_features = ['Sales_Growth', 'OPM', 'ROCE', 'ROE', 'Debt_to_Equity', 'PE_Ratio']
 
150
  imputer = joblib.load(f'imputer_{tier.lower()}.pkl')
151
  scaler = joblib.load(f'scaler_{tier.lower()}.pkl')
152
  except Exception as e:
153
+ return {"error": f"Error loading models: {e}"}
 
154
 
155
  X_imputed = imputer.transform(X)
156
  X_scaled = scaler.transform(X_imputed)
157
 
158
+ prob = float(model.predict_proba(X_scaled)[0][1])
159
+ decision = "BUY" if prob > 0.65 else "PASS"
 
 
 
 
 
160
  reasoning = generate_reasoning(features, tier, prob)
161
 
162
+ return {
163
+ "Ticker": ticker,
164
+ "Tier": tier,
165
+ "Decision": decision,
166
+ "Confidence": prob,
167
+ "Reasoning": reasoning,
168
+ "Features": features
169
+ }
170
+
171
+ def run_inference(ticker):
172
+ res = get_prediction(ticker)
173
+ if "error" in res:
174
+ print(f"[{ticker}] {res['error']}")
175
+ return
176
+
177
  print("\n" + "="*50)
178
+ print(f" FORECAST FOR {ticker} ({res['Tier']} Cap Model)")
179
  print("="*50)
180
+ print(f" Decision: {res['Decision']} (Confidence: {res['Confidence']*100:.1f}%)")
181
+ print(f" Reasoning: {res['Reasoning']}")
182
  print("-" * 50)
183
+ for k, v in res['Features'].items():
184
+ print(f" {k}: {v}")
 
 
 
185
  print("="*50 + "\n")
186
  return {"Ticker": ticker, "Tier": tier, "Decision": decision, **features}
187