# Generated by Django 5.2.9 on 2025-12-31 02:08

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("backtest", "0001_initial"),
    ]

    operations = [
        # 先删除旧模型（同时删除表）
        migrations.DeleteModel(
            name="BacktestResult",
        ),
        # 然后创建新模型
        migrations.CreateModel(
            name="BacktestResultModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("name", models.CharField(max_length=200)),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("pending", "Pending"),
                            ("running", "Running"),
                            ("completed", "Completed"),
                            ("failed", "Failed"),
                        ],
                        default="pending",
                        max_length=20,
                    ),
                ),
                ("error_message", models.TextField(blank=True, null=True)),
                ("start_date", models.DateField()),
                ("end_date", models.DateField()),
                ("initial_capital", models.DecimalField(decimal_places=2, max_digits=20)),
                ("rebalance_frequency", models.CharField(max_length=20)),
                ("use_pit_data", models.BooleanField(default=False)),
                ("transaction_cost_bps", models.FloatField(default=10.0)),
                (
                    "final_capital",
                    models.DecimalField(blank=True, decimal_places=2, max_digits=20, null=True),
                ),
                ("total_return", models.FloatField(blank=True, null=True)),
                ("annualized_return", models.FloatField(blank=True, null=True)),
                ("max_drawdown", models.FloatField(blank=True, null=True)),
                ("sharpe_ratio", models.FloatField(blank=True, null=True)),
                ("equity_curve", models.JSONField(blank=True, default=list)),
                ("regime_history", models.JSONField(blank=True, default=list)),
                ("trades", models.JSONField(blank=True, default=list)),
                ("warnings", models.JSONField(blank=True, default=list)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("completed_at", models.DateTimeField(blank=True, null=True)),
            ],
            options={
                "db_table": "backtest_result",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="BacktestTradeModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("trade_date", models.DateField()),
                ("asset_class", models.CharField(max_length=50)),
                (
                    "action",
                    models.CharField(choices=[("buy", "Buy"), ("sell", "Sell")], max_length=10),
                ),
                ("shares", models.FloatField()),
                ("price", models.DecimalField(decimal_places=4, max_digits=20)),
                ("notional", models.DecimalField(decimal_places=2, max_digits=20)),
                ("cost", models.DecimalField(decimal_places=2, max_digits=20)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
            ],
            options={
                "db_table": "backtest_trade",
                "ordering": ["trade_date", "asset_class"],
            },
        ),
        migrations.AddIndex(
            model_name="backtestresultmodel",
            index=models.Index(fields=["-created_at"], name="backtest_re_created_809dec_idx"),
        ),
        migrations.AddIndex(
            model_name="backtestresultmodel",
            index=models.Index(fields=["status"], name="backtest_re_status_f6ae92_idx"),
        ),
        migrations.AddIndex(
            model_name="backtestresultmodel",
            index=models.Index(
                fields=["start_date", "end_date"], name="backtest_re_start_d_86c202_idx"
            ),
        ),
        migrations.AddField(
            model_name="backtesttrademodel",
            name="backtest",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="trade_records",
                to="backtest.backtestresultmodel",
            ),
        ),
        migrations.AddIndex(
            model_name="backtesttrademodel",
            index=models.Index(
                fields=["backtest", "trade_date"], name="backtest_tr_backtes_7cd206_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="backtesttrademodel",
            index=models.Index(fields=["asset_class"], name="backtest_tr_asset_c_f4c022_idx"),
        ),
    ]
