# Generated by Django 5.2.10 on 2026-02-05 07:29

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


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="AssetClassModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "code",
                    models.CharField(
                        db_index=True, max_length=20, unique=True, verbose_name="资产代码"
                    ),
                ),
                ("name", models.CharField(max_length=100, verbose_name="资产名称")),
                (
                    "category",
                    models.CharField(
                        choices=[
                            ("equity", "股票"),
                            ("bond", "债券"),
                            ("commodity", "商品"),
                            ("currency", "货币"),
                            ("alternative", "另类"),
                        ],
                        max_length=20,
                        verbose_name="资产类别",
                    ),
                ),
                ("description", models.TextField(blank=True, verbose_name="资产描述")),
                (
                    "underlying_index",
                    models.CharField(blank=True, max_length=50, verbose_name="标的指数"),
                ),
                (
                    "currency",
                    models.CharField(default="CNY", max_length=10, verbose_name="计价货币"),
                ),
                ("is_active", models.BooleanField(default=True, verbose_name="是否启用")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "资产类别",
                "verbose_name_plural": "资产类别",
                "db_table": "rotation_asset_class",
                "ordering": ["category", "code"],
            },
        ),
        migrations.CreateModel(
            name="RotationConfigModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("name", models.CharField(max_length=100, unique=True, verbose_name="配置名称")),
                ("description", models.TextField(blank=True, verbose_name="配置描述")),
                (
                    "strategy_type",
                    models.CharField(
                        choices=[
                            ("regime_based", "基于象限"),
                            ("momentum", "动量轮动"),
                            ("risk_parity", "风险平价"),
                            ("mean_reversion", "均值回归"),
                            ("custom", "自定义"),
                        ],
                        default="momentum",
                        max_length=50,
                        verbose_name="策略类型",
                    ),
                ),
                ("asset_universe", models.JSONField(default=list, verbose_name="资产池")),
                ("params", models.JSONField(default=dict, verbose_name="策略参数")),
                (
                    "rebalance_frequency",
                    models.CharField(default="monthly", max_length=20, verbose_name="调仓频率"),
                ),
                ("min_weight", models.FloatField(default=0.0, verbose_name="最小权重")),
                ("max_weight", models.FloatField(default=1.0, verbose_name="最大权重")),
                ("max_turnover", models.FloatField(default=1.0, verbose_name="最大换手率")),
                (
                    "lookback_period",
                    models.IntegerField(default=252, verbose_name="回溯周期（天）"),
                ),
                (
                    "regime_allocations",
                    models.JSONField(blank=True, default=dict, verbose_name="象限配置"),
                ),
                ("momentum_periods", models.JSONField(default=list, verbose_name="动量周期")),
                ("top_n", models.IntegerField(default=3, verbose_name="选资产数量")),
                ("is_active", models.BooleanField(default=True, verbose_name="是否启用")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "轮动配置",
                "verbose_name_plural": "轮动配置",
                "db_table": "rotation_config",
                "ordering": ["-is_active", "-created_at"],
            },
        ),
        migrations.CreateModel(
            name="MomentumScoreModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "asset_code",
                    models.CharField(db_index=True, max_length=20, verbose_name="资产代码"),
                ),
                ("calc_date", models.DateField(db_index=True, verbose_name="计算日期")),
                ("momentum_1m", models.FloatField(default=0.0, verbose_name="1月动量")),
                ("momentum_3m", models.FloatField(default=0.0, verbose_name="3月动量")),
                ("momentum_6m", models.FloatField(default=0.0, verbose_name="6月动量")),
                ("momentum_12m", models.FloatField(default=0.0, verbose_name="12月动量")),
                ("composite_score", models.FloatField(default=0.0, verbose_name="综合得分")),
                ("rank", models.IntegerField(default=0, verbose_name="排名")),
                ("sharpe_1m", models.FloatField(default=0.0, verbose_name="1月夏普")),
                ("sharpe_3m", models.FloatField(default=0.0, verbose_name="3月夏普")),
                (
                    "ma_signal",
                    models.CharField(default="neutral", max_length=20, verbose_name="均线信号"),
                ),
                ("trend_strength", models.FloatField(default=0.0, verbose_name="趋势强度")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
            ],
            options={
                "verbose_name": "动量得分",
                "verbose_name_plural": "动量得分",
                "db_table": "rotation_momentum_score",
                "ordering": ["-calc_date", "-composite_score"],
                "indexes": [
                    models.Index(
                        fields=["calc_date", "rank"], name="rotation_mo_calc_da_b6a7b9_idx"
                    ),
                    models.Index(
                        fields=["calc_date", "composite_score"],
                        name="rotation_mo_calc_da_3c1baa_idx",
                    ),
                ],
                "unique_together": {("asset_code", "calc_date")},
            },
        ),
        migrations.CreateModel(
            name="RotationPortfolioModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("trade_date", models.DateField(db_index=True, verbose_name="交易日期")),
                ("current_allocation", models.JSONField(verbose_name="当前配置")),
                ("daily_return", models.FloatField(default=0.0, verbose_name="日收益率")),
                ("cumulative_return", models.FloatField(default=0.0, verbose_name="累计收益率")),
                ("portfolio_volatility", models.FloatField(default=0.0, verbose_name="组合波动率")),
                ("max_drawdown", models.FloatField(default=0.0, verbose_name="最大回撤")),
                ("turnover_since_last", models.FloatField(default=0.0, verbose_name="换手率")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "config",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="portfolios",
                        to="rotation.rotationconfigmodel",
                        verbose_name="配置",
                    ),
                ),
            ],
            options={
                "verbose_name": "轮动组合",
                "verbose_name_plural": "轮动组合",
                "db_table": "rotation_portfolio",
                "ordering": ["-trade_date"],
                "indexes": [
                    models.Index(
                        fields=["config", "trade_date"], name="rotation_po_config__314fe2_idx"
                    )
                ],
                "unique_together": {("config", "trade_date")},
            },
        ),
        migrations.CreateModel(
            name="RotationSignalModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("signal_date", models.DateField(db_index=True, verbose_name="信号日期")),
                ("target_allocation", models.JSONField(verbose_name="目标配置")),
                (
                    "current_regime",
                    models.CharField(blank=True, max_length=30, verbose_name="当前象限"),
                ),
                (
                    "momentum_ranking",
                    models.JSONField(blank=True, default=list, verbose_name="动量排名"),
                ),
                ("expected_volatility", models.FloatField(default=0.0, verbose_name="预期波动率")),
                ("expected_return", models.FloatField(default=0.0, verbose_name="预期收益")),
                (
                    "action_required",
                    models.CharField(default="hold", max_length=50, verbose_name="建议操作"),
                ),
                ("reason", models.TextField(blank=True, verbose_name="原因说明")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "config",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="signals",
                        to="rotation.rotationconfigmodel",
                        verbose_name="配置",
                    ),
                ),
            ],
            options={
                "verbose_name": "轮动信号",
                "verbose_name_plural": "轮动信号",
                "db_table": "rotation_signal",
                "ordering": ["-signal_date"],
                "indexes": [
                    models.Index(fields=["signal_date"], name="rotation_si_signal__cc8460_idx"),
                    models.Index(
                        fields=["config", "signal_date"], name="rotation_si_config__bb4ae5_idx"
                    ),
                ],
                "unique_together": {("config", "signal_date")},
            },
        ),
    ]
