- Create docs/DATA_RETENTION_POLICY.md with authoritative retention windows. - Create scripts/data_cleanup.py (v1.1.0) with safe deletion and archival logic. - Ensure .github/workflows/data-cleanup.yml is correctly configured. - Update README.md documentation index. - Verified via tests/test_data_cleanup.py and tests/test_data_cleanup_system.py. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: andonly1348 <279141437+andonly1348@users.noreply.github.com>
5.3 KiB
Data Retention Policy
1. Overview
This policy defines the retention periods and disposal procedures for operational data generated by the MT5 AI/ML Trading Bot. It ensures compliance with financial regulations (e.g., SEC/FINRA-like standards) while maintaining system performance and storage efficiency.
2. Retention Schedule
| Data Category | Data Type | Retention Period | Disposal Method | Reason |
|---|---|---|---|---|
| Compliance | Trade Records (trades table) |
7 Years | Archival + Purge | Regulatory Requirement |
| Compliance | Execution Quality (execution_qualities) |
7 Years | Archival + Purge | Execution Analytics |
| Audit | Audit Log (audit_log table) |
7 Years | Archival + Purge | Enterprise Traceability |
| Audit | Risk Events (risk_events table) |
2 Years | Archival + Purge | Operational Auditing |
| Audit | Linked Model Signals | 7 Years | Archival + Purge | Trade Traceability |
| Operational | Unlinked Model Signals | 90 Days | Purge | Performance Tuning |
| Operational | Blocked Signal Analysis | 90 Days | Purge | Opportunity Cost |
| Operational | Performance Metrics | 2 Years | Archival + Purge | Trend Analysis |
| Diagnostics | Application Logs (logs/*.log) |
90 Days | Deletion | Troubleshooting |
| Research | Backtest Results | 1 Year | Archival + Deletion | Optimization |
3. Data Classification
3.1 Audit-Critical Data (Preserve)
The following data must be preserved for the full 7-year compliance window:
- Trade Records: All fields in the
tradestable, including tickets, symbols, prices, and PnL. - Execution Quality: High-precision execution analytics linked to each trade record.
- Audit Log: System actions, configuration changes, and operator events in the
audit_logtable. - Linked Signals: Any
model_signalsrecord referenced by atraderecord viasignal_idOR arisk_eventrecord viasignal_id.
3.2 Retention for Linked Data
To maintain referential integrity and auditability:
- A
model_signalsrecord is considered "Linked" if it is associated with at least onetradeorrisk_event. - Linked signals inherit the maximum retention period of their associated records (e.g., 7 years if linked to a trade).
ExecutionQualityrecords are linked toTradeand inherit its 7-year retention.BlockedSignalAnalysisrecords are linked toModelSignaland inherit the signal's retention (typically 90 days unless linked to a risk event).- When a parent record (Trade/RiskEvent) is purged, the cleanup script must verify if the associated signal is still required by another active record before deletion.
3.3 Ephemeral Data (Rotate/Purge)
The following data can be purged more frequently to manage storage:
- Unlinked Signals: AI predictions that did not result in an executed trade.
- Application Logs: Standard output and error logs from the trading engine.
- Temporary Backtest Artifacts: Large CSVs or parquet files generated during model validation.
4. Archival and Purging Rules
4.1 Archival Procedures
Prior to purging, data in the Compliance, Audit, Operational (Performance Metrics), and Research (Backtest Results) categories must be archived:
- Format:
- Database records are exported to compressed CSV format.
- Filesystem-based research data (Backtest Results) is bundled into compressed
.tar.gzarchives.
- Destination: Archives are stored in type-specific subdirectories within the
archives/directory:archives/compliance/: Trade records and execution quality analytics.archives/audit/: Audit logs and risk events.archives/performance/: Performance metrics and snapshots.archives/research/: Backtest results and research artifacts.
- Integrity: SHA256 checksums are generated for each archive file to ensure immutability.
4.2 Archive Lifecycle Management
Archives themselves are subject to a retention policy to prevent indefinite storage growth:
- Compliance Archives: Kept for 7 years from the date of archival.
- Audit/Performance Archives: Kept for 2 years from the date of archival.
- Research Archives: Kept for 1 year from the date of archival.
- Cleanup: The
scripts/data_cleanup.pyscript is responsible for purging expired archives.
4.3 Automated Purging Schedule
The automated cleanup script (scripts/data_cleanup.py) is executed on a regular schedule to ensure continuous compliance and storage hygiene.
- Schedule: Weekly (Sundays at 00:00 UTC).
- Automation: Managed via the
.github/workflows/data-cleanup.ymlGitHub Action.
4.4 Safe Deletion Logic
- Foreign Key Integrity: The cleanup script ensures that
model_signalslinked totradesorrisk_eventsare NOT deleted if the parent record is still within its retention window. - Dry-Run Mode: All cleanup operations must support a
--dry-runflag to verify deletions before execution. - Logging: Every cleanup operation is logged to the system audit trail.
5. Implementation
The primary mechanism for enforcement is the scripts/data_cleanup.py tool. It uses the database_url and logs_dir from the system configuration to target the correct data stores.
Version: 1.4.1 Effective Date: 2024-06-10 Owner: Release Reliability & Governance (Jules03)