# Analytic functions

## Objective

Analytic functions are used when calculations over an event window is required. These functions are executed on each window generation trigger, windows are generated when the window policy is satisfied.&#x20;

Joule is shipped with a starter pack of stateful and stateless functions to support initial use cases. The platform can be extended using the [Analytics API](/joule/developer-guides/builder-sdk/analytics-api.md) to build custom functions.

## Example

This code defines a **sliding time window** for calculating and emitting additional attributes. On `emit` of data, `EMA` is appended on the property name automatically.

1. <mark style="color:green;">**window functions**</mark>
   1. <mark style="color:green;">**ema rates**</mark>\
      Calculates the exponential moving average (EMA) for `ask` and `bid` with a smoothing factor of 0.001996007984032.
   2. <mark style="color:green;">**ranges**</mark>\
      Calculates the min-max range for `ask` and `bid`.
   3. <mark style="color:green;">**norms**</mark>\
      Computes the Z-score for `ask` and `bid`.
2. <mark style="color:green;">**policy**</mark>
   1. <mark style="color:green;">**slidingTime**</mark>\
      The window slides every 500 milliseconds.
   2. <mark style="color:green;">**window size**</mark>\
      The window covers 2500 milliseconds (2.5 seconds).

This configuration calculates attributes like `ask_EMA`, `bid_EMA`, `ask_MINMAX_NORM`, `bid_MINMAX_NORM`, `ask_ZSCORE`, and `bid_ZSCORE` over a sliding time window.

```yaml
time window:
  emitting type: slidingQuoteAnalytics
  window functions:
    ema rates:
      function:
        exponential moving average:
          parameters:
            smoothing factor: 0.001996007984032
      attributes: [ ask,bid ]

    ranges:
      function:
        minmax: {}
      attributes: [ ask,bid ]

    norms:
      function:
        zscore: {}
      attributes: [ ask,bid ]
  policy:
    type: slidingTime
    slide: 500
    window size: 2500
```

## Available options

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th><th></th><th><select></select></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><mark style="color:orange;"><strong>Stateful analytics</strong></mark></td><td>Stateless based analytics over a grouped set of events</td><td></td><td></td><td><a href="/pages/BWhyNAuE86yMdBHoQlBD">/pages/BWhyNAuE86yMdBHoQlBD</a></td></tr><tr><td><mark style="color:orange;"><strong>Stateless analytics</strong></mark></td><td>Stateful based analytics over a grouped set of events</td><td></td><td></td><td><a href="/pages/BWhyNAuE86yMdBHoQlBD">/pages/BWhyNAuE86yMdBHoQlBD</a></td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fractalworks.io/joule/components/analytics/analytic-tools/analytic-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
