> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fincept.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Expected Shortfall Portfolio Optimization

> Calculates Conditional Value at Risk (CVaR / Expected Shortfall) for each asset in a portfolio. CVaR measures the expected loss given that losses exceed VaR - it captures tail risk better than VaR alone. Used for portfolio optimization under tail risk constraints and risk budgeting. [Tier: PRO, Credits: 5]



## OpenAPI

````yaml api-specs/risk.json post /quantlib/risk/var/es-optimization
openapi: 3.1.0
info:
  title: FinceptQuantLib API - Risk Module
  description: >-
    Professional-grade risk management endpoints including Value at Risk (VaR),
    stress testing, copulas, extreme value theory (EVT), XVA calculations,
    sensitivities, and portfolio hedging. Part of the Pro Tier (5 credits per
    request).
  version: 3.0.0
  contact:
    name: Fincept API Support
    url: https://fincept.in
    email: support@fincept.in
servers:
  - url: https://api.fincept.in
    description: Fincept API Production Server
security:
  - APIKeyHeader: []
tags:
  - name: quantlib-risk
    description: Risk Management Module - Pro Tier (5 credits/request)
    x-displayName: Risk
paths:
  /quantlib/risk/var/es-optimization:
    post:
      tags:
        - quantlib-risk
      summary: Expected Shortfall Portfolio Optimization
      description: >-
        Calculates Conditional Value at Risk (CVaR / Expected Shortfall) for
        each asset in a portfolio. CVaR measures the expected loss given that
        losses exceed VaR - it captures tail risk better than VaR alone. Used
        for portfolio optimization under tail risk constraints and risk
        budgeting. [Tier: PRO, Credits: 5]
      operationId: es_optimization
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - returns
              properties:
                returns:
                  type: array
                  description: Array of return series, one for each asset
                  items:
                    type: array
                    items:
                      type: number
                  example:
                    - - 0.01
                      - -0.02
                      - 0.015
                    - - 0.005
                      - -0.015
                      - 0.012
                confidence:
                  type: number
                  description: Confidence level for CVaR calculation
                  example: 0.95
                  default: 0.95
                target_return:
                  type: number
                  description: Target portfolio return for optimization (optional)
                  example: 0.08
                  nullable: true
            example:
              returns:
                - - 0.012
                  - -0.025
                  - 0.018
                  - -0.015
                  - 0.022
                - - 0.008
                  - -0.018
                  - 0.015
                  - -0.012
                  - 0.019
                - - 0.015
                  - -0.032
                  - 0.022
                  - -0.02
                  - 0.025
              confidence: 0.95
              target_return: 0.1
      responses:
        '200':
          description: CVaR per asset
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      cvar_per_asset:
                        type: array
                        description: Conditional VaR for each asset
                        items:
                          type: number
                        example:
                          - 0.0245
                          - 0.0182
                          - 0.0315
                      confidence:
                        type: number
                        example: 0.95
              example:
                success: true
                data:
                  cvar_per_asset:
                    - 0.0245
                    - 0.0182
                    - 0.0315
                  confidence: 0.95
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '402':
          $ref: '#/components/responses/InsufficientCreditsError'
        '422':
          $ref: '#/components/responses/ValidationError'
components:
  responses:
    UnauthorizedError:
      description: Authentication information is missing or invalid
      content:
        application/json:
          schema:
            type: object
            properties:
              detail:
                type: string
                example: Invalid API key
    InsufficientCreditsError:
      description: Insufficient API credits for this request
      content:
        application/json:
          schema:
            type: object
            properties:
              detail:
                type: string
                example: Insufficient credits. This endpoint requires 5 credits.
    ValidationError:
      description: Request validation error
      content:
        application/json:
          schema:
            type: object
            properties:
              detail:
                type: array
                items:
                  type: object
                  properties:
                    loc:
                      type: array
                      items:
                        type: string
                    msg:
                      type: string
                    type:
                      type: string
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: X-API-Key
      description: >-
        API key for authentication. Get your key at
        https://api.fincept.in/auth/register

````