mirror of
https://github.com/d0zingcat/deploy.git
synced 2026-05-16 23:16:47 +00:00
(feat) update pages
This commit is contained in:
132
pages/backtesting/optimize/README.md
Normal file
132
pages/backtesting/optimize/README.md
Normal file
@@ -0,0 +1,132 @@
|
||||
# Backtesting Optimization
|
||||
|
||||
The Backtesting Optimization page provides powerful tools to find optimal trading strategy parameters through systematic testing and analysis.
|
||||
|
||||
## Features
|
||||
|
||||
### 🔧 Parameter Optimization
|
||||
- **Grid Search**: Test all combinations of parameter values systematically
|
||||
- **Random Search**: Efficiently explore large parameter spaces
|
||||
- **Genetic Algorithms**: Evolve parameters using natural selection principles
|
||||
- **Bayesian Optimization**: Smart parameter search using probabilistic models
|
||||
|
||||
### 📊 Optimization Targets
|
||||
- **Maximize Sharpe Ratio**: Optimize for risk-adjusted returns
|
||||
- **Maximize Total P&L**: Focus on absolute profit maximization
|
||||
- **Minimize Drawdown**: Prioritize capital preservation
|
||||
- **Custom Objectives**: Define multi-objective optimization functions
|
||||
|
||||
### 🎯 Parameter Configuration
|
||||
- **Range Definition**: Set min/max values for each parameter
|
||||
- **Step Sizes**: Define granularity of parameter search
|
||||
- **Constraints**: Apply realistic bounds and relationships
|
||||
- **Parameter Groups**: Test correlated parameters together
|
||||
|
||||
### 📈 Results Analysis
|
||||
- **3D Surface Plots**: Visualize parameter interactions
|
||||
- **Heatmaps**: Identify optimal parameter regions
|
||||
- **Parallel Coordinates**: Explore high-dimensional results
|
||||
- **Performance Rankings**: Compare top parameter combinations
|
||||
|
||||
## Usage Instructions
|
||||
|
||||
### 1. Select Base Strategy
|
||||
- Choose the strategy to optimize from available backtests
|
||||
- Load the baseline configuration as starting point
|
||||
- Review historical performance metrics
|
||||
|
||||
### 2. Define Parameter Space
|
||||
- **Select Parameters**: Choose which parameters to optimize
|
||||
- **Set Ranges**: Define minimum and maximum values
|
||||
- Spreads: 0.1% - 5.0%
|
||||
- Order amounts: 10% - 100%
|
||||
- Risk limits: 0.5% - 10%
|
||||
- **Configure Steps**: Set increment sizes for each parameter
|
||||
|
||||
### 3. Configure Optimization
|
||||
- **Algorithm**: Select optimization method
|
||||
- Grid Search: Complete but computationally intensive
|
||||
- Random Search: Good for initial exploration
|
||||
- Bayesian: Efficient for expensive evaluations
|
||||
- **Objective Function**: Choose what to optimize
|
||||
- **Constraints**: Set practical limitations
|
||||
- **Iterations**: Define search budget
|
||||
|
||||
### 4. Run Optimization
|
||||
- Review estimated runtime and resource usage
|
||||
- Start optimization process
|
||||
- Monitor real-time progress and intermediate results
|
||||
- Pause/resume long-running optimizations
|
||||
|
||||
### 5. Analyze Results
|
||||
- View top performing parameter sets
|
||||
- Explore parameter sensitivity analysis
|
||||
- Export optimal configurations
|
||||
- Create ensemble strategies from top performers
|
||||
|
||||
## Technical Notes
|
||||
|
||||
### Optimization Engine
|
||||
- **Parallel Processing**: Multiple backtests run simultaneously
|
||||
- **Distributed Computing**: Leverage multiple CPU cores
|
||||
- **Memory Management**: Efficient handling of large result sets
|
||||
- **Checkpointing**: Save progress for long optimizations
|
||||
|
||||
### Search Algorithms
|
||||
- **Grid Search**: Exhaustive search with deterministic coverage
|
||||
- **Random Search**: Monte Carlo sampling with proven efficiency
|
||||
- **Bayesian Optimization**: Gaussian Process regression for smart search
|
||||
- **Genetic Algorithms**: Population-based evolutionary optimization
|
||||
|
||||
### Performance Metrics
|
||||
- **Primary Metrics**: Sharpe ratio, total return, maximum drawdown
|
||||
- **Risk Metrics**: VaR, CVaR, Sortino ratio, Calmar ratio
|
||||
- **Trade Metrics**: Win rate, profit factor, average trade P&L
|
||||
- **Stability Metrics**: Return consistency, strategy robustness
|
||||
|
||||
## Component Structure
|
||||
|
||||
```
|
||||
optimize/
|
||||
├── optimize.py # Main optimization interface
|
||||
├── engines/
|
||||
│ ├── grid_search.py # Grid search implementation
|
||||
│ ├── random_search.py # Random search algorithm
|
||||
│ ├── bayesian.py # Bayesian optimization
|
||||
│ └── genetic.py # Genetic algorithm
|
||||
├── objectives/
|
||||
│ ├── metrics.py # Objective function definitions
|
||||
│ └── constraints.py # Constraint handling
|
||||
└── visualization/
|
||||
├── surfaces.py # 3D parameter surfaces
|
||||
├── heatmaps.py # 2D optimization heatmaps
|
||||
└── parallel_coords.py # Multi-dimensional plots
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Parameter Selection
|
||||
- Start with 2-3 most impactful parameters
|
||||
- Use domain knowledge to set reasonable ranges
|
||||
- Consider parameter interactions and dependencies
|
||||
- Validate results with out-of-sample data
|
||||
|
||||
### Optimization Strategy
|
||||
- Begin with coarse grid search for exploration
|
||||
- Refine with Bayesian optimization
|
||||
- Validate top results with extended backtests
|
||||
- Test robustness with walk-forward analysis
|
||||
|
||||
### Resource Management
|
||||
- Estimate computational requirements upfront
|
||||
- Use random search for high-dimensional spaces
|
||||
- Implement early stopping for poor performers
|
||||
- Save intermediate results frequently
|
||||
|
||||
## Error Handling
|
||||
|
||||
The optimization page includes comprehensive error handling:
|
||||
- **Parameter Validation**: Ensures valid parameter ranges and relationships
|
||||
- **Resource Limits**: Prevents system overload with job queuing
|
||||
- **Convergence Detection**: Identifies when optimization plateaus
|
||||
- **Result Validation**: Checks for numerical stability and outliers
|
||||
0
pages/backtesting/optimize/__init__.py
Normal file
0
pages/backtesting/optimize/__init__.py
Normal file
62
pages/backtesting/optimize/optimize.py
Normal file
62
pages/backtesting/optimize/optimize.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import time
|
||||
import webbrowser
|
||||
from types import SimpleNamespace
|
||||
|
||||
import streamlit as st
|
||||
from streamlit_elements import elements, mui
|
||||
|
||||
from backend.utils import os_utils
|
||||
from frontend.components.dashboard import Dashboard
|
||||
from frontend.components.editor import Editor
|
||||
from frontend.components.optimization_creation_card import OptimizationCreationCard
|
||||
from frontend.components.optimization_run_card import OptimizationRunCard
|
||||
from frontend.components.optimizations_file_explorer import OptimizationsStrategiesFileExplorer
|
||||
from frontend.st_utils import initialize_st_page
|
||||
|
||||
initialize_st_page(title="Optimize", icon="🧪")
|
||||
|
||||
|
||||
def run_optuna_dashboard():
|
||||
os_utils.execute_bash_command("optuna-dashboard sqlite:///data/backtesting/backtesting_report.db")
|
||||
time.sleep(5)
|
||||
webbrowser.open("http://127.0.0.1:8080/dashboard", new=2)
|
||||
|
||||
|
||||
if "op_board" not in st.session_state:
|
||||
board = Dashboard()
|
||||
op_board = SimpleNamespace(
|
||||
dashboard=board,
|
||||
create_optimization_card=OptimizationCreationCard(board, 0, 0, 6, 1),
|
||||
run_optimization_card=OptimizationRunCard(board, 6, 0, 6, 1),
|
||||
file_explorer=OptimizationsStrategiesFileExplorer(board, 0, 2, 3, 7),
|
||||
editor=Editor(board, 4, 2, 9, 7),
|
||||
)
|
||||
st.session_state.op_board = op_board
|
||||
|
||||
else:
|
||||
op_board = st.session_state.op_board
|
||||
|
||||
# Add new tabs
|
||||
for tab_name, content in op_board.file_explorer.tabs.items():
|
||||
if tab_name not in op_board.editor.tabs:
|
||||
op_board.editor.add_tab(tab_name, content["content"], content["language"])
|
||||
|
||||
# Remove deleted tabs
|
||||
for tab_name in list(op_board.editor.tabs.keys()):
|
||||
if tab_name not in op_board.file_explorer.tabs:
|
||||
op_board.editor.remove_tab(tab_name)
|
||||
|
||||
with elements("optimizations"):
|
||||
with mui.Paper(elevation=3, style={"padding": "2rem"}, spacing=[2, 2], container=True):
|
||||
with mui.Grid(container=True, spacing=2):
|
||||
with mui.Grid(item=True, xs=10):
|
||||
pass
|
||||
with mui.Grid(item=True, xs=2):
|
||||
with mui.Fab(variant="extended", color="primary", size="large", onClick=run_optuna_dashboard):
|
||||
mui.Typography("Open Optuna Dashboard", variant="body1")
|
||||
|
||||
with op_board.dashboard():
|
||||
op_board.create_optimization_card()
|
||||
op_board.run_optimization_card()
|
||||
op_board.file_explorer()
|
||||
op_board.editor()
|
||||
Reference in New Issue
Block a user