投資組合大擂台 Ver. 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Eric0801 cbd580bb12 feat: V2 prompt system with benchmarks and CoT for Demo Day 1 month ago
data_init feat: V2 prompt system with benchmarks and CoT for Demo Day 1 month ago
prompts feat: V2 prompt system with benchmarks and CoT for Demo Day 1 month ago
sql_script set db postgresql version as 15 1 year ago
static change only backtesting>=1 2 years ago
templates feat: V2 prompt system with benchmarks and CoT for Demo Day 1 month ago
.gitignore feat: V2 prompt system with benchmarks and CoT for Demo Day 1 month ago
Dockerfile add new assets list and add competitions 2 years ago
LLM_DEMO.py Fix unhashable type error in prompt templates\n\n- Fixed syntax error in prompts/investment_advice.py: {{}} -> {}\n- Cleaned up duplicate imports in llm_service.py\n- Removed unused lru_cache import\n- All prompt templates now work correctly\n- Demo script runs successfully 2 months ago
LLM_SETUP.md Add LLM investment advice feature with OpenAI integration\n\n- Created llm_service.py with comprehensive LLM advisor\n- Added config_openai.py for API configuration\n- Created prompts/investment_advice.py with prompt templates\n- Updated requirements.txt with OpenAI dependency\n- Modified main.py with /api/llm_advice endpoint\n- Enhanced result_view.html with LLM advice section\n- Added CSS styling for better UI\n- Created LLM_SETUP.md setup guide\n- Added test_llm_service.py for testing\n- Implemented caching, retry logic, and error handling\n- Features: strategy analysis, risk assessment, market insights 2 months ago
Procfile init 2 years ago
README.md feat: V2 prompt system with benchmarks and CoT for Demo Day 1 month ago
assets_tw.json 20230721 Finished auto deploy 2 years ago
assets_us.json update new password setting 1 year ago
config.py update new password setting 1 year ago
config_openai.py Add LLM investment advice feature with OpenAI integration\n\n- Created llm_service.py with comprehensive LLM advisor\n- Added config_openai.py for API configuration\n- Created prompts/investment_advice.py with prompt templates\n- Updated requirements.txt with OpenAI dependency\n- Modified main.py with /api/llm_advice endpoint\n- Enhanced result_view.html with LLM advice section\n- Added CSS styling for better UI\n- Created LLM_SETUP.md setup guide\n- Added test_llm_service.py for testing\n- Implemented caching, retry logic, and error handling\n- Features: strategy analysis, risk assessment, market insights 2 months ago
cursor.md feat: V2 prompt system with benchmarks and CoT for Demo Day 1 month ago
docker-compose.yml feat: V2 prompt system with benchmarks and CoT for Demo Day 1 month ago
llm_service.py feat: V2 prompt system with benchmarks and CoT for Demo Day 1 month ago
main.py feat: V2 prompt system with benchmarks and CoT for Demo Day 1 month ago
market_benchmark.py feat: V2 prompt system with benchmarks and CoT for Demo Day 1 month ago
portfolio_builder.py change only backtesting>=1 2 years ago
render.yaml feat: V2 prompt system with benchmarks and CoT for Demo Day 1 month ago
requirements.txt Add LLM investment advice feature with OpenAI integration\n\n- Created llm_service.py with comprehensive LLM advisor\n- Added config_openai.py for API configuration\n- Created prompts/investment_advice.py with prompt templates\n- Updated requirements.txt with OpenAI dependency\n- Modified main.py with /api/llm_advice endpoint\n- Enhanced result_view.html with LLM advice section\n- Added CSS styling for better UI\n- Created LLM_SETUP.md setup guide\n- Added test_llm_service.py for testing\n- Implemented caching, retry logic, and error handling\n- Features: strategy analysis, risk assessment, market insights 2 months ago
sql_command.py init 2 years ago
test_llm_service.py Fix syntax error in test script\n\n- Corrected missing parenthesis in test_llm_service.py\n- All tests now pass successfully 2 months ago
update_assets_us.py add new assets list and add competitions 2 years ago

README.md

TPM – 投資組合大擂台

1) 內容概要

  • Flask + PostgreSQL + Redis 的投資策略平台,內含回測、圖表與 LLM 投資建議。
  • 前端採 Jinja SSR + Bootstrap;LLM 透過 llm_service.py 封裝,可切換 OpenAI/OpenRouter/Mock。

2) 技術棧(現況,請勿任意更換)

  • Backend: Flask 2.2, psycopg2, Flask-Caching, Plotly
  • DB/Cache: PostgreSQL, Redis
  • Frontend: Jinja, Bootstrap 5, Bootstrap Icons(避免新增其他 CSS 框架)
  • LLM: OpenAI SDK(可接 OpenRouter),支援 Mock
  • Container: Docker, docker-compose

3) 目錄重點

  • main.py: 路由與頁面組裝;禁止塞商業邏輯
  • llm_service.py: LLM 供應商、Prompt、重試、快取
  • portfolio_builder.py: 投組演算法
  • templates/: Jinja 模板(僅結構與少量初始化)
  • static/js/{components,pages}/: 前端 JS 組件與頁面邏輯
  • sql_script/: DB 初始化
  • data_init/: 資料初始化與更新腳本

4) 快速開始

  1. 準備 .env(置於專案根目錄)
LLM_PROVIDER=openrouter
OPENROUTER_API_KEY=your_key
OPENROUTER_MODEL=google/gemini-2.0-flash-exp:free
LLM_TIMEOUT=60
LLM_MAX_TOKENS=1500
LLM_TEMPERATURE=0.6
MOCK_LLM=false
  1. 啟動容器
docker compose up -d --build --force-recreate
  1. 服務連線

5) 開發規範(避免技術債)

  • 不動既有架構、Docker 設定與不相關功能。
  • 僅在確定「已使用」時才把套件寫入 requirements.txt;未用到的要移除。
  • 完成一個環節、測試通過才 commit;不要在同一個 commit 混雜多項變更。
  • 前端:避免大型 inline JS;新邏輯放 static/js/pages/*.jsstatic/js/components/*.js
  • 後端:商業邏輯放在服務檔案(如 llm_service.py),main.py 保持輕薄。
  • LLM:僅經 get_llm_advisor().generate_advice(strategy_id, strategy_dict);參數由 .env 控制。

6) 測試

  • 後端:可使用離線腳本(MOCK_LLM=true)進行測試。
  • 任何變更建議附最小可重現測試或腳本(避免手動點擊測試)。

7) 常見問題

  • 500 + LLM 失敗:確認 .env 已注入容器;離線測試可先設 MOCK_LLM=true
  • DB 連線錯誤:程式內部連線 host 應為 db
  • KeyError(TSLA/AAPL):確認 data_init 成功寫入對應市場資料

8) Git / PR 規範

  • 分支命名:feature/<area>-<short>fix/<area>-<short>
  • PR 標題:[TPM] <Title>;內容包含「動機 / 變更 / 風險 / 測試方式」
  • 小步提交、保持向後相容;前端改動請將 JS 抽出至 static/js/

9) 設計原則

  • 關注點分離:路由薄、服務厚;模板薄、JS 組件化
  • 僅在既有層擴展功能;避免跨層耦合
  • 可回退:大改以 feature flag 包裝,保持 simple 模式可用

更詳細的協作規範請見 cursor.md