36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
|
|
from data_analysis_engine.dataset_builder import add_technical_indicators
|
|
from data_analysis_engine.models.xgboost_model import XGBoostModel
|
|
import pandas as pd
|
|
import os
|
|
import glob
|
|
|
|
def analyze_stocks_pipeline(cds_dir, model_path, top_n=10, output_path="prediction_result.csv"):
|
|
model = XGBoostModel()
|
|
model.load_model(model_path)
|
|
|
|
results = []
|
|
|
|
csv_files = glob.glob(os.path.join(cds_dir, "*_ohlcv.csv"))
|
|
for file in csv_files:
|
|
symbol = os.path.basename(file).replace("_ohlcv.csv", "")
|
|
df = pd.read_csv(file)
|
|
df = add_technical_indicators(df)
|
|
|
|
feature_cols = [
|
|
'open', 'high', 'low', 'close', 'volume',
|
|
'sma_5', 'sma_10', 'rsi_14', 'macd',
|
|
'boll_upper', 'boll_lower'
|
|
]
|
|
X = df[feature_cols].dropna()
|
|
if X.empty:
|
|
continue
|
|
|
|
prob = model.predict_proba(X.tail(1)) # 이미 float 값임
|
|
results.append({"symbol": symbol, "predicted_score": prob})
|
|
|
|
result_df = pd.DataFrame(results)
|
|
result_df.sort_values(by="predicted_score", ascending=False, inplace=True)
|
|
result_df.head(top_n).to_csv(output_path, index=False)
|
|
print("✅ 예측 결과 저장 완료:", output_path)
|