> ## 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.

# Nonlinear Least Squares Fitting

> Fit a nonlinear parametric model to data by minimizing the sum of squared residuals. Supports exponential_fit (y = a·e^(bx) + c, useful for decay processes and yield curves) and polynomial_fit (y = p0 + p1·x + p2·x^2 + ..., general curve fitting). Uses iterative optimization to find parameters that best fit the observed data. Essential for curve calibration, term structure fitting, volatility smile modeling, and empirical model estimation. [Tier: BASIC, Credits: 1]



## OpenAPI

````yaml api-specs/numerical.json post /quantlib/numerical/least-squares/fit
openapi: 3.1.0
info:
  title: FinceptQuantLib API - Numerical
  description: >-
    Numerical module endpoints for FinceptQuantLib API. The Numerical module
    (Basic Tier, 1 credit per request) provides comprehensive numerical methods
    including finite difference differentiation, Fast Fourier Transform (FFT),
    numerical integration (quadrature and Monte Carlo), interpolation methods
    (linear, cubic, spline), linear algebra operations (matrix decomposition,
    solving systems), ODE solvers, root finding algorithms, optimization
    methods, and nonlinear least squares fitting. Essential for quantitative
    analysis, scientific computing, and numerical model implementation.
  version: 3.0.0
  contact:
    name: Fincept API Support
    url: https://fincept.in
servers:
  - url: https://api.fincept.in
    description: Fincept API Production Server
security:
  - APIKeyHeader: []
tags:
  - name: quantlib-numerical
    description: >-
      Numerical methods including differentiation, FFT, integration,
      interpolation, linear algebra, ODE solvers, root finding, and optimization
    x-displayName: Numerical
paths:
  /quantlib/numerical/least-squares/fit:
    post:
      tags:
        - quantlib-numerical
      summary: Nonlinear Least Squares Fitting
      description: >-
        Fit a nonlinear parametric model to data by minimizing the sum of
        squared residuals. Supports exponential_fit (y = a·e^(bx) + c, useful
        for decay processes and yield curves) and polynomial_fit (y = p0 + p1·x
        + p2·x^2 + ..., general curve fitting). Uses iterative optimization to
        find parameters that best fit the observed data. Essential for curve
        calibration, term structure fitting, volatility smile modeling, and
        empirical model estimation. [Tier: BASIC, Credits: 1]
      operationId: nonlinear_least_squares
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - x_data
                - y_data
                - x0
              properties:
                model:
                  type: string
                  description: Model type to fit
                  enum:
                    - exponential_fit
                    - polynomial_fit
                  example: exponential_fit
                x_data:
                  type: array
                  items:
                    type: number
                  description: X coordinates of data points
                  example:
                    - 0
                    - 1
                    - 2
                    - 3
                    - 4
                y_data:
                  type: array
                  items:
                    type: number
                  description: Y coordinates of data points (observations to fit)
                  example:
                    - 5.1
                    - 3.8
                    - 2.9
                    - 2.3
                    - 2
                x0:
                  type: array
                  items:
                    type: number
                  description: >-
                    Initial guess for model parameters (exponential: [a,b,c],
                    polynomial: [p0,p1,p2,...])
                  example:
                    - 5
                    - -0.5
                    - 1.5
            example:
              model: exponential_fit
              x_data:
                - 0
                - 1
                - 2
                - 3
                - 4
              y_data:
                - 5.1
                - 3.8
                - 2.9
                - 2.3
                - 2
              x0:
                - 5
                - -0.5
                - 1.5
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      parameters:
                        type: array
                        items:
                          type: number
                        description: >-
                          Fitted model parameters (e.g., [a, b, c] for
                          exponential)
                        example:
                          - 3.52
                          - -0.48
                          - 1.62
                      cost:
                        type: number
                        description: Final cost (sum of squared residuals)
                        example: 0.0234
                      iterations:
                        type: integer
                        description: Number of iterations required
                        example: 12
                      converged:
                        type: boolean
                        description: Whether the fitting converged
                        example: true
              example:
                success: true
                data:
                  parameters:
                    - 3.52
                    - -0.48
                    - 1.62
                  cost: 0.0234
                  iterations: 12
                  converged: true
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '402':
          $ref: '#/components/responses/InsufficientTierError'
        '422':
          description: Validation Error
      security:
        - APIKeyHeader: []
components:
  responses:
    UnauthorizedError:
      description: Authentication information is missing or invalid
      content:
        application/json:
          schema:
            type: object
            properties:
              detail:
                type: string
                example: Invalid API key
    InsufficientTierError:
      description: API tier insufficient for this endpoint
      content:
        application/json:
          schema:
            type: object
            properties:
              detail:
                type: string
                example: Endpoint requires Basic tier or higher
  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

````