# Generated by Django 5.2.9 on 2026-01-01 14:57

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


class Migration(migrations.Migration):

    dependencies = [
        ("account", "0010_transactionmodel_cost_variance_and_more"),
        ("policy", "0003_policyauditqueue_policylog_ai_confidence_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="HedgePositionModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("instrument_code", models.CharField(max_length=50, verbose_name="对冲工具代码")),
                ("instrument_type", models.CharField(max_length=20, verbose_name="工具类型")),
                ("hedge_ratio", models.FloatField(verbose_name="对冲比例")),
                (
                    "hedge_value",
                    models.DecimalField(decimal_places=2, max_digits=20, verbose_name="对冲金额"),
                ),
                ("policy_level", models.CharField(max_length=10, verbose_name="触发政策档位")),
                (
                    "execution_price",
                    models.DecimalField(
                        blank=True,
                        decimal_places=4,
                        max_digits=20,
                        null=True,
                        verbose_name="执行价格",
                    ),
                ),
                (
                    "executed_at",
                    models.DateTimeField(blank=True, null=True, verbose_name="执行时间"),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("pending", "待执行"),
                            ("executed", "已执行"),
                            ("closed", "已平仓"),
                            ("expired", "已过期"),
                            ("failed", "执行失败"),
                        ],
                        default="pending",
                        max_length=20,
                        verbose_name="状态",
                    ),
                ),
                (
                    "opening_cost",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        max_digits=10,
                        null=True,
                        verbose_name="开仓成本",
                    ),
                ),
                (
                    "closing_cost",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        max_digits=10,
                        null=True,
                        verbose_name="平仓成本",
                    ),
                ),
                (
                    "total_cost",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        max_digits=10,
                        null=True,
                        verbose_name="总成本",
                    ),
                ),
                (
                    "beta_before",
                    models.FloatField(blank=True, null=True, verbose_name="对冲前Beta"),
                ),
                ("beta_after", models.FloatField(blank=True, null=True, verbose_name="对冲后Beta")),
                (
                    "hedge_profit",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        max_digits=20,
                        null=True,
                        verbose_name="对冲盈亏",
                    ),
                ),
                ("notes", models.TextField(blank=True, verbose_name="备注")),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="更新时间")),
                (
                    "portfolio",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="hedge_positions",
                        to="account.portfoliomodel",
                        verbose_name="投资组合",
                    ),
                ),
            ],
            options={
                "verbose_name": "对冲持仓记录",
                "verbose_name_plural": "对冲持仓记录",
                "db_table": "hedge_position",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(
                        fields=["portfolio", "-created_at"], name="hedge_posit_portfol_2fafd4_idx"
                    ),
                    models.Index(fields=["status"], name="hedge_posit_status_fe7c61_idx"),
                    models.Index(fields=["policy_level"], name="hedge_posit_policy__7a95af_idx"),
                ],
            },
        ),
    ]
