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

# Lag and Lead Features

> Generates lagged features, lead features, returns, and log returns for time series modeling. Essential for autoregressive models and capturing temporal dependencies. [Tier: ENTERPRISE, Credits: 10]



## OpenAPI

````yaml api-specs/ml.json post /quantlib/ml/features/lags
openapi: 3.1.0
info:
  title: FinceptQuantLib API - ML
  description: >-
    Machine Learning and Credit Risk module endpoints for FinceptQuantLib API.
    Pro Tier access required (5 credits per request). Covers credit scoring,
    model validation, regression models, clustering, anomaly detection, feature
    engineering, and preprocessing.
  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-ml
    description: Machine Learning and Credit Risk Analytics
    x-displayName: ML
paths:
  /quantlib/ml/features/lags:
    post:
      tags:
        - quantlib-ml
      summary: Lag and Lead Features
      description: >-
        Generates lagged features, lead features, returns, and log returns for
        time series modeling. Essential for autoregressive models and capturing
        temporal dependencies. [Tier: ENTERPRISE, Credits: 10]
      operationId: lag_features
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - data
              properties:
                data:
                  type: array
                  description: Time series data
                  items:
                    type: number
                  example:
                    - 100
                    - 102
                    - 101
                    - 105
                    - 107
                    - 106
                    - 110
                n_lags:
                  type: integer
                  description: Number of lags/leads to create
                  default: 5
                  example: 3
                include_leads:
                  type: boolean
                  description: Include lead features
                  default: false
                  example: false
                include_returns:
                  type: boolean
                  description: Include simple returns
                  default: false
                  example: true
                include_log_returns:
                  type: boolean
                  description: Include log returns
                  default: false
                  example: false
      responses:
        '200':
          description: Lag and return features
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      lags:
                        type: array
                        items:
                          type: array
                          items:
                            type: number
                        description: Lagged feature matrix
                        example:
                          - - 102
                            - 100
                          - - 101
                            - 102
                          - - 105
                            - 101
                      leads:
                        type: array
                        description: Lead features (if requested)
                      returns:
                        type: array
                        items:
                          type: number
                        description: Simple returns (if requested)
                        example:
                          - 0.02
                          - -0.0098
                          - 0.0396
                          - 0.019
                          - -0.0093
                          - 0.0377
                      log_returns:
                        type: array
                        description: Log returns (if requested)
        '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 credits for this operation
      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

````