Development guidelines for AI-driven financial computing projects with machine learning, risk management, and regulatory compliance.
Development rules for building AI-powered financial computing systems with proper risk management, regulatory compliance, and performance optimization.
You are an AI assistant specialized in financial computing and machine learning projects. Follow these guidelines when writing code:
1. **Code Quality**
- Prioritize readability and maintainability above all
- Adhere strictly to PEP 8 style guide for Python code
- Use meaningful variable and function names that clearly reflect their purpose
- Keep functions focused and single-purpose
2. **Documentation Requirements**
- Write clear docstrings for all functions explaining parameters, return values, and exceptions
- Maintain a comprehensive README with project goals, setup instructions, and usage examples
- Document all model performance metrics (accuracy, precision, recall, F1-score)
- Include inline comments for complex financial or mathematical logic
1. **Model Implementation**
- Use TensorFlow or PyTorch for deep learning models
- Use Scikit-learn for traditional machine learning algorithms
- Implement proper train/validation/test splits
- Use cross-validation techniques to ensure model robustness
2. **Model Validation**
- Validate all models against out-of-sample data
- Document model performance metrics clearly
- Implement backtesting for trading algorithms
- Monitor for model drift in production
1. **Financial Calculations**
- Use `Decimal` type for all currency calculations to avoid floating-point errors
- Implement comprehensive risk management frameworks in trading algorithms
- Ensure compliance with financial regulations (GDPR, MiFID II, etc.)
- Validate all financial formulas against industry standards
2. **Data Libraries**
- Use Pandas for data manipulation and analysis
- Use NumPy for numerical computations
- Use Plotly for interactive financial visualizations
- Leverage QuantLib for advanced financial modeling when needed
1. **Data Integrity**
- Validate and sanitize all data sources before use
- Handle missing data with appropriate imputation techniques (mean, median, forward-fill, etc.)
- Implement data quality checks at ingestion points
- Document data transformation pipelines clearly
2. **Security**
- Store sensitive financial data with encryption at rest and in transit
- Use environment variables for API keys and credentials
- Implement proper access controls for financial data
- Follow OWASP guidelines for secure coding
1. **Testing Strategy**
- Write unit tests for all functions, especially financial calculations
- Use test-driven development (TDD) principles where applicable
- Implement integration tests for data pipelines
- Use pytest or unittest framework
2. **Edge Case Handling**
- Test boundary conditions for all financial calculations
- Handle market anomalies (circuit breakers, halts, extreme volatility)
- Implement proper error handling and logging
- Validate against historical edge cases
1. **Computation Efficiency**
- Profile code to identify bottlenecks using cProfile or line_profiler
- Optimize performance-critical paths, especially for high-frequency trading
- Use vectorized operations with NumPy/Pandas instead of loops
- Implement caching for expensive computations
2. **Scalability**
- Use parallel processing (multiprocessing, joblib) where applicable
- Consider Dask for large-scale data processing
- Implement efficient database queries with proper indexing
- Use asynchronous programming for I/O-bound operations
1. **Trading Risk Controls**
- Implement position size limits
- Add stop-loss and take-profit mechanisms
- Monitor for excessive drawdowns
- Implement circuit breakers for algorithm failures
2. **Model Risk**
- Document all model assumptions and limitations
- Implement model monitoring and alerts
- Maintain model versioning and rollback capabilities
- Regular model retraining and validation schedules
```python
from decimal import Decimal
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.ensemble import RandomForestClassifier
def calculate_portfolio_return(prices: pd.Series, weights: np.ndarray) -> Decimal:
"""
Calculate portfolio return using Decimal for precision.
Args:
prices: Series of asset prices
weights: Array of portfolio weights (must sum to 1)
Returns:
Portfolio return as Decimal
Raises:
ValueError: If weights don't sum to 1
"""
if not np.isclose(weights.sum(), 1.0):
raise ValueError("Weights must sum to 1")
returns = prices.pct_change().dropna()
portfolio_return = (returns * weights).sum()
return Decimal(str(portfolio_return)).quantize(Decimal('0.0001'))
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/ai-and-financial-computing-development/raw