# 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="HedgePairModel",
            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="对冲对名称")),
                ("long_asset", models.CharField(max_length=20, verbose_name="多头资产")),
                ("hedge_asset", models.CharField(max_length=20, verbose_name="对冲资产")),
                (
                    "hedge_method",
                    models.CharField(
                        choices=[
                            ("beta", "Beta对冲"),
                            ("min_variance", "最小方差"),
                            ("equal_risk", "等风险贡献"),
                            ("dollar_neutral", "货币中性"),
                            ("fixed_ratio", "固定比例"),
                        ],
                        default="beta",
                        max_length=30,
                        verbose_name="对冲方法",
                    ),
                ),
                ("target_long_weight", models.FloatField(default=0.7, verbose_name="目标多头权重")),
                (
                    "target_hedge_weight",
                    models.FloatField(default=0.3, verbose_name="目标对冲权重"),
                ),
                ("rebalance_trigger", models.FloatField(default=0.05, verbose_name="调仓触发阈值")),
                (
                    "correlation_window",
                    models.IntegerField(default=60, verbose_name="相关性计算窗口（天）"),
                ),
                ("min_correlation", models.FloatField(default=-0.3, verbose_name="最小相关性")),
                ("max_correlation", models.FloatField(default=-0.9, verbose_name="最大相关性")),
                (
                    "correlation_alert_threshold",
                    models.FloatField(default=0.2, verbose_name="相关性告警阈值"),
                ),
                ("max_hedge_cost", models.FloatField(default=0.05, verbose_name="最大对冲成本")),
                ("beta_target", models.FloatField(blank=True, null=True, verbose_name="目标Beta")),
                ("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": "hedge_pair",
                "ordering": ["-is_active", "name"],
            },
        ),
        migrations.CreateModel(
            name="CorrelationHistoryModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("asset1", models.CharField(db_index=True, max_length=20, verbose_name="资产1")),
                ("asset2", models.CharField(db_index=True, max_length=20, verbose_name="资产2")),
                ("calc_date", models.DateField(db_index=True, verbose_name="计算日期")),
                ("window_days", models.IntegerField(verbose_name="窗口天数")),
                ("correlation", models.FloatField(verbose_name="相关系数")),
                ("covariance", models.FloatField(default=0.0, verbose_name="协方差")),
                ("beta", models.FloatField(default=0.0, verbose_name="Beta")),
                ("p_value", models.FloatField(default=0.0, verbose_name="P值")),
                ("standard_error", models.FloatField(default=0.0, verbose_name="标准误差")),
                (
                    "correlation_trend",
                    models.CharField(default="neutral", max_length=20, verbose_name="相关性趋势"),
                ),
                ("correlation_ma", models.FloatField(default=0.0, verbose_name="相关性均线")),
                ("alert", models.TextField(blank=True, verbose_name="告警信息")),
                (
                    "alert_type",
                    models.CharField(blank=True, max_length=50, verbose_name="告警类型"),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
            ],
            options={
                "verbose_name": "相关性历史",
                "verbose_name_plural": "相关性历史",
                "db_table": "hedge_correlation_history",
                "ordering": ["-calc_date"],
                "indexes": [
                    models.Index(
                        fields=["calc_date", "asset1", "asset2"],
                        name="hedge_corre_calc_da_e86654_idx",
                    ),
                    models.Index(
                        fields=["calc_date", "correlation"], name="hedge_corre_calc_da_5386b7_idx"
                    ),
                ],
                "unique_together": {("asset1", "asset2", "calc_date", "window_days")},
            },
        ),
        migrations.CreateModel(
            name="HedgeAlertModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "pair_name",
                    models.CharField(db_index=True, max_length=100, verbose_name="对冲对名称"),
                ),
                ("alert_date", models.DateField(db_index=True, verbose_name="告警日期")),
                (
                    "alert_type",
                    models.CharField(
                        choices=[
                            ("correlation_breakdown", "相关性失效"),
                            ("hedge_ratio_drift", "对冲比例漂移"),
                            ("beta_change", "Beta变化"),
                            ("liquidity_risk", "流动性风险"),
                        ],
                        max_length=50,
                        verbose_name="告警类型",
                    ),
                ),
                (
                    "severity",
                    models.CharField(
                        choices=[
                            ("low", "低"),
                            ("medium", "中"),
                            ("high", "高"),
                            ("critical", "严重"),
                        ],
                        default="medium",
                        max_length=20,
                        verbose_name="严重程度",
                    ),
                ),
                ("message", models.TextField(verbose_name="告警信息")),
                ("current_value", models.FloatField(default=0.0, verbose_name="当前值")),
                ("threshold_value", models.FloatField(default=0.0, verbose_name="阈值")),
                ("action_required", models.TextField(blank=True, verbose_name="建议操作")),
                ("action_priority", models.IntegerField(default=5, verbose_name="优先级")),
                ("is_resolved", models.BooleanField(default=False, verbose_name="已解决")),
                (
                    "resolved_at",
                    models.DateTimeField(blank=True, null=True, verbose_name="解决时间"),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
            ],
            options={
                "verbose_name": "对冲告警",
                "verbose_name_plural": "对冲告警",
                "db_table": "hedge_alert",
                "ordering": ["-alert_date", "-action_priority"],
                "indexes": [
                    models.Index(
                        fields=["alert_date", "-action_priority"],
                        name="hedge_alert_alert_d_7551a8_idx",
                    ),
                    models.Index(
                        fields=["is_resolved", "alert_date"], name="hedge_alert_is_reso_1d4b3d_idx"
                    ),
                ],
            },
        ),
        migrations.CreateModel(
            name="HedgePerformanceModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "pair_name",
                    models.CharField(db_index=True, max_length=100, verbose_name="对冲对名称"),
                ),
                ("period_start", models.DateField(verbose_name="期间开始")),
                ("period_end", models.DateField(verbose_name="期间结束")),
                ("total_return", models.FloatField(verbose_name="总收益率")),
                ("annual_return", models.FloatField(verbose_name="年化收益率")),
                ("sharpe_ratio", models.FloatField(verbose_name="夏普比率")),
                ("volatility_reduction", models.FloatField(verbose_name="波动率降低（%）")),
                ("drawdown_reduction", models.FloatField(verbose_name="回撤降低（%）")),
                ("hedge_effectiveness", models.FloatField(verbose_name="对冲有效性")),
                ("hedge_cost", models.FloatField(default=0.0, verbose_name="对冲成本")),
                ("cost_benefit_ratio", models.FloatField(default=0.0, verbose_name="成本收益比")),
                ("avg_correlation", models.FloatField(verbose_name="平均相关性")),
                (
                    "correlation_stability",
                    models.FloatField(default=0.0, verbose_name="相关性稳定性"),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
            ],
            options={
                "verbose_name": "对冲表现",
                "verbose_name_plural": "对冲表现",
                "db_table": "hedge_performance",
                "ordering": ["-period_start", "pair_name"],
                "unique_together": {("pair_name", "period_start", "period_end")},
            },
        ),
        migrations.CreateModel(
            name="HedgePortfolioHoldingModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("trade_date", models.DateField(db_index=True, verbose_name="交易日期")),
                ("long_weight", models.FloatField(verbose_name="多头权重")),
                ("hedge_weight", models.FloatField(verbose_name="对冲权重")),
                ("hedge_ratio", models.FloatField(verbose_name="对冲比例")),
                ("target_hedge_ratio", models.FloatField(default=0.0, verbose_name="目标对冲比例")),
                ("current_correlation", models.FloatField(verbose_name="当前相关性")),
                ("correlation_20d", models.FloatField(default=0.0, verbose_name="20日相关性")),
                ("correlation_60d", models.FloatField(default=0.0, verbose_name="60日相关性")),
                ("portfolio_beta", models.FloatField(default=0.0, verbose_name="组合Beta")),
                ("portfolio_volatility", models.FloatField(default=0.0, verbose_name="组合波动率")),
                ("hedge_effectiveness", models.FloatField(default=0.0, verbose_name="对冲有效性")),
                ("daily_return", models.FloatField(default=0.0, verbose_name="日收益率")),
                ("unhedged_return", models.FloatField(default=0.0, verbose_name="未对冲收益")),
                ("hedge_return", models.FloatField(default=0.0, verbose_name="对冲部位收益")),
                ("value_at_risk", models.FloatField(default=0.0, verbose_name="VaR")),
                ("max_drawdown", models.FloatField(default=0.0, verbose_name="最大回撤")),
                ("rebalance_needed", models.BooleanField(default=False, verbose_name="需要调仓")),
                ("rebalance_reason", models.TextField(blank=True, verbose_name="调仓原因")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "pair",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="holdings",
                        to="hedge.hedgepairmodel",
                        verbose_name="对冲对",
                    ),
                ),
            ],
            options={
                "verbose_name": "对冲组合持仓",
                "verbose_name_plural": "对冲组合持仓",
                "db_table": "hedge_portfolio_holdings",
                "ordering": ["-trade_date"],
                "indexes": [
                    models.Index(
                        fields=["pair", "trade_date"], name="hedge_portf_pair_id_e7f44b_idx"
                    ),
                    models.Index(
                        fields=["trade_date", "rebalance_needed"],
                        name="hedge_portf_trade_d_d448c9_idx",
                    ),
                ],
                "unique_together": {("pair", "trade_date")},
            },
        ),
    ]
