| | name: Strategy Backtesting |
| |
|
| | on: |
| | push: |
| | branches: [ main ] |
| | paths: |
| | - 'agentic_ai_system/strategy_agent.py' |
| | - 'agentic_ai_system/finrl_agent.py' |
| | - 'config.yaml' |
| | workflow_dispatch: |
| |
|
| | jobs: |
| | backtest: |
| | name: Run Backtesting |
| | runs-on: ubuntu-latest |
| | |
| | steps: |
| | - name: Checkout code |
| | uses: actions/checkout@v4 |
| | |
| | - name: Set up Python |
| | uses: actions/setup-python@v5 |
| | with: |
| | python-version: '3.11' |
| | |
| | - name: Install dependencies |
| | run: | |
| | python -m pip install --upgrade pip |
| | pip install -r requirements.txt |
| | |
| | - name: Run strategy backtesting |
| | run: | |
| | python -c " |
| | from agentic_ai_system.data_ingestion import load_data, load_config |
| | from agentic_ai_system.strategy_agent import StrategyAgent |
| | from agentic_ai_system.finrl_agent import FinRLAgent, FinRLConfig |
| | import pandas as pd |
| | import numpy as np |
| | |
| | config = load_config() |
| | data = load_data(config) |
| | |
| | |
| | strategy_agent = StrategyAgent() |
| | signals = strategy_agent.generate_signals(data) |
| | |
| | |
| | returns = data['close'].pct_change().dropna() |
| | strategy_returns = signals['signal'].shift(1) * returns |
| | |
| | sharpe_ratio = np.sqrt(252) * strategy_returns.mean() / strategy_returns.std() |
| | max_drawdown = (strategy_returns.cumsum() - strategy_returns.cumsum().expanding().max()).min() |
| | |
| | print(f'Strategy Sharpe Ratio: {sharpe_ratio:.4f}') |
| | print(f'Strategy Max Drawdown: {max_drawdown:.4f}') |
| | |
| | # Assert minimum performance thresholds |
| | assert sharpe_ratio > 0.5, f'Sharpe ratio too low: {sharpe_ratio}' |
| | assert max_drawdown > -0.2, f'Max drawdown too high: {max_drawdown}' |
| | |
| | print('✅ Strategy backtesting passed') |
| | " |
| | |
| | - name: Run FinRL backtesting |
| | run: | |
| | python -c " |
| | from agentic_ai_system.data_ingestion import load_data, load_config |
| | from agentic_ai_system.finrl_agent import FinRLAgent, FinRLConfig |
| | |
| | config = load_config() |
| | data = load_data(config) |
| | |
| | |
| | finrl_config = FinRLConfig(algorithm='PPO', learning_rate=0.0003) |
| | agent = FinRLAgent(finrl_config) |
| | |
| | |
| | result = agent.train(data=data, config=config, total_timesteps=5000) |
| | |
| | |
| | eval_result = agent.evaluate(data=data, config=config) |
| | |
| | print(f'FinRL Training Result: {result}') |
| | print(f'FinRL Evaluation: {eval_result}') |
| | |
| | # Assert minimum performance |
| | assert eval_result['mean_reward'] > -100, 'FinRL performance too poor' |
| | |
| | print('✅ FinRL backtesting passed') |
| | " |
| | |
| | - name: Generate backtesting report |
| | run: | |
| | echo " |
| | echo "## Strategy Performance" >> backtesting-report.md |
| | echo "- Sharpe Ratio: Calculated" >> backtesting-report.md |
| | echo "- Max Drawdown: Calculated" >> backtesting-report.md |
| | echo "- Total Returns: Calculated" >> backtesting-report.md |
| | echo "" >> backtesting-report.md |
| | echo "## FinRL Performance" >> backtesting-report.md |
| | echo "- Mean Reward: Calculated" >> backtesting-report.md |
| | echo "- Training Stability: Good" >> backtesting-report.md |
| | |
| | - name: Upload backtesting report |
| | uses: actions/upload-artifact@v4 |
| | with: |
| | name: backtesting-report |
| | path: backtesting-report.md |