forked from lab/TPM
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.
160 lines
4.9 KiB
160 lines
4.9 KiB
""" |
|
投資建議相關的Prompt模板 |
|
|
|
包含: |
|
- 基本投資建議模板 |
|
- 進階分析模板 |
|
- 不同市場環境的模板 |
|
""" |
|
|
|
from typing import Dict, Any |
|
|
|
|
|
def get_basic_investment_prompt(strategy_data: Dict[str, Any]) -> str: |
|
"""基本投資建議Prompt""" |
|
return f""" |
|
請基於以下投資策略數據,提供專業的投資建議: |
|
|
|
策略概況: |
|
- 年化報酬率:{strategy_data.get('annual_ret', 0):.2%} |
|
- 年化波動率:{strategy_data.get('vol', 0):.2%} |
|
- 夏普比率:{strategy_data.get('annual_sr', 0):.2f} |
|
- 最大回落:{strategy_data.get('mdd', 0):.2%} |
|
- 投資目標:{strategy_data.get('role', 'N/A')} |
|
|
|
投資組合包含:{', '.join(strategy_data.get('assets', []))} |
|
|
|
請提供: |
|
1. 整體表現評估 |
|
2. 風險收益分析 |
|
3. 改進建議 |
|
""" |
|
|
|
|
|
def get_comprehensive_analysis_prompt(strategy_data: Dict[str, Any]) -> str: |
|
"""全面分析Prompt - 現代化結構""" |
|
return f""" |
|
作為專業投資顧問,請對以下投資策略進行全面分析並提供建議: |
|
|
|
【策略基本資訊】 |
|
- 策略名稱:{strategy_data.get('name', 'N/A')} |
|
- 投資目標:{strategy_data.get('role', 'N/A')} |
|
- 市場類型:{'台灣市場' if strategy_data.get('tw', True) else '美國市場'} |
|
|
|
【關鍵績效指標】 |
|
- 年化報酬率:{strategy_data.get('annual_ret', 0):.2%} |
|
- 年化波動率:{strategy_data.get('vol', 0):.2%} |
|
- 年化夏普比率:{strategy_data.get('annual_sr', 0):.2f} |
|
- 最大回落(MDD):{strategy_data.get('mdd', 0):.2%} |
|
- Alpha值:{strategy_data.get('alpha', 0):.4f} |
|
- Beta值:{strategy_data.get('beta', 0):.4f} |
|
- VaR (95%):{strategy_data.get('var10', 0):.2%} |
|
- R-squared:{strategy_data.get('r2', 0):.4f} |
|
|
|
【投資組合配置】 |
|
持有資產:{', '.join(strategy_data.get('assets', []))} |
|
權重配置:{strategy_data.get('weight', {}).get('columns', [])} |
|
|
|
【分析要求】 |
|
請從以下面向提供詳細分析和建議: |
|
|
|
1. **績效評估**: |
|
- 與市場基準比較(台灣加權指數或S&P 500) |
|
- 歷史表現趨勢分析 |
|
- 相對表現評價 |
|
|
|
2. **風險分析**: |
|
- 整體風險水平評估 |
|
- 主要風險來源識別 |
|
- 風險調整後報酬分析 |
|
|
|
3. **市場適配性**: |
|
- 當前市場環境適配程度 |
|
- 經濟週期位置評估 |
|
- 市場波動性影響分析 |
|
|
|
4. **投資建議**: |
|
- 資產配置優化建議 |
|
- 風險管理改進方案 |
|
- 定期調整和再平衡建議 |
|
|
|
5. **未來展望**: |
|
- 未來3-6個月投資展望 |
|
- 潛在風險預警 |
|
- 操作建議和時機點 |
|
|
|
--- |
|
請用繁體中文回答,確保報告結構完整、語氣專業且易於理解。使用和格式化讓內容更生動。 |
|
""" |
|
|
|
|
|
def get_risk_focused_prompt(strategy_data: Dict[str, Any]) -> str: |
|
"""風險導向分析Prompt""" |
|
return f""" |
|
請重點分析以下投資策略的風險特性,並提供風險管理建議: |
|
|
|
【風險指標】 |
|
- 年化波動率:{strategy_data.get('vol', 0):.2%} |
|
- 最大回落:{strategy_data.get('mdd', 0):.2%} |
|
- Beta值:{strategy_data.get('beta', 0):.4f} |
|
- VaR (10%):{strategy_data.get('var10', 0):.2%} |
|
- 夏普比率:{strategy_data.get('annual_sr', 0):.2f} |
|
|
|
【風險分析要求】 |
|
1. 評估當前風險水平(低/中/高) |
|
2. 識別主要風險來源 |
|
3. 分析風險與報酬的配比 |
|
4. 提供風險降低策略 |
|
5. 建議風險監控指標 |
|
|
|
請提供具體、可操作的風險管理建議。 |
|
""" |
|
|
|
|
|
def get_market_context_prompt(strategy_data: Dict[str, Any], market_condition: str = "normal") -> str: |
|
"""市場環境特定Prompt""" |
|
market_contexts = { |
|
"bull": "目前市場處於牛市環境", |
|
"bear": "目前市場處於熊市環境", |
|
"volatile": "目前市場波動劇烈", |
|
"normal": "目前市場環境正常" |
|
} |
|
|
|
context = market_contexts.get(market_condition, market_contexts["normal"]) |
|
|
|
return f""" |
|
{context},請針對以下投資策略提供相應的投資建議: |
|
|
|
【策略資訊】 |
|
- 年化報酬率:{strategy_data.get('annual_ret', 0):.2%} |
|
- 年化波動率:{strategy_data.get('vol', 0):.2%} |
|
- 投資目標:{strategy_data.get('role', 'N/A')} |
|
|
|
【市場適配建議】 |
|
根據當前市場環境,請分析: |
|
1. 該策略在當前環境下的適配程度 |
|
2. 可能的調整建議 |
|
3. 風險控制措施 |
|
4. 時機選擇建議 |
|
|
|
請提供針對當前市場環境的具體操作建議。 |
|
""" |
|
|
|
|
|
def build_custom_prompt(strategy_data: Dict[str, Any], analysis_type: str, **kwargs) -> str: |
|
"""自訂Prompt生成器 |
|
|
|
Args: |
|
strategy_data: 策略資料 |
|
analysis_type: 分析類型 ('basic', 'comprehensive', 'risk', 'market') |
|
**kwargs: 額外參數 |
|
""" |
|
templates = { |
|
'basic': get_basic_investment_prompt, |
|
'comprehensive': get_comprehensive_analysis_prompt, |
|
'risk': get_risk_focused_prompt, |
|
'market': lambda data: get_market_context_prompt(data, kwargs.get('condition', 'normal')) |
|
} |
|
|
|
template_func = templates.get(analysis_type, get_basic_investment_prompt) |
|
return template_func(strategy_data)
|
|
|