# ET-PFM-005: Historial y Reportes

**Épica:** OQI-008 - Portfolio Manager
**Versión:** 1.0
**Fecha:** 2025-12-05
**Estado:** Planificado

---

## Modelo de Datos de Transacción

```typescript
@Entity('transactions')
export class Transaction {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'user_id' })
  userId: string;

  @Column({
    type: 'enum',
    enum: ['BUY', 'SELL', 'DEPOSIT', 'WITHDRAWAL', 'DIVIDEND', 'FEE'],
  })
  type: TransactionType;

  @Column({ nullable: true })
  symbol: string;

  @Column('decimal', { precision: 18, scale: 8, nullable: true })
  quantity: number;

  @Column('decimal', { precision: 18, scale: 2 })
  price: number;

  @Column('decimal', { precision: 18, scale: 2 })
  total: number;

  @Column('decimal', { precision: 18, scale: 2, default: 0 })
  fees: number;

  @Column('decimal', { precision: 18, scale: 2, nullable: true, name: 'realized_pnl' })
  realizedPnl: number;

  @Column({ name: 'executed_at' })
  executedAt: Date;

  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;
}
```

---

## API Endpoints

| Method | Endpoint | Descripción |
|--------|----------|-------------|
| GET | `/api/transactions` | Lista de transacciones |
| GET | `/api/transactions/:id` | Detalle de transacción |
| GET | `/api/transactions/stats` | Estadísticas de trading |
| GET | `/api/transactions/export` | Exportar CSV/PDF |

---

## Estadísticas de Trading

```typescript
interface TradingStats {
  totalTrades: number;
  winningTrades: number;
  losingTrades: number;
  winRate: number;
  totalPnL: number;
  avgPnLPerTrade: number;
  bestTrade: {
    symbol: string;
    pnl: number;
    date: string;
  };
  worstTrade: {
    symbol: string;
    pnl: number;
    date: string;
  };
  pnlBySymbol: Record<string, number>;
  pnlByMonth: Record<string, number>;
}
```

---

## Referencias

- [RF-PFM-004: Historial de Transacciones](../requerimientos/RF-PFM-004-historial-transacciones.md)

---

*Especificación técnica - Sistema NEXUS*
