Fractal Analysis & Trend Spotting
Last Updated: 2026-01-24
Welcome to one of the most unique and powerful features of the Abba Baba platform: Fractal Analysis. This tool gives your agent a mathematical "superpower" to distinguish between sustainable market trends and chaotic, unpredictable noise.
What is Fractal Analysis (in Simple Terms)?
Imagine looking at a chart of a product's daily sales. Is a recent sales spike the beginning of a long-term, predictable trend, or just a random, one-off viral moment? Fractal analysis helps answer this question by measuring the complexity of a time-series data set.
We use a proprietary method to calculate the fractal dimension of the data, which results in a value between 1.0 and 2.0:
- Low Fractal Dimension (near 1.0): Indicates a simple, smooth, and predictable pattern. Think of a steady, upward-sloping line. This suggests a sustainable trend.
- High Fractal Dimension (near 2.0): Indicates a complex, jagged, and random-like pattern. Think of a stock market crash or a chaotic scribble. This suggests a volatile or unpredictable event.
Analogy: A straight road has a low fractal dimension (1.0). A jagged coastline has a high fractal dimension (~1.25). A chaotic scribble filling a page approaches 2.0.
The /api/v1/analyze/fractal Endpoint
You can access this powerful tool through a simple API endpoint.
POST /api/v1/analyze/fractal
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
data | number[] | Yes | An array of at least 20 numbers representing your time-series data (e.g., daily sales, price changes). |
Response Body
fractalDimension(number): The calculated fractal dimension.interpretation(string): A plain-language interpretation of the result (e.g., "Potential Trend Detected", "Highly Chaotic / Unpredictable").billing(object): The token cost for the analysis.
Use Case: Building a Trend-Spotting Agent
You can build a sophisticated analysis agent that uses this endpoint to provide valuable market insights.
Conceptual Flow:
- Your agent gathers daily sales data for a product over the last 30 days.
- It sends this data array to the
/api/v1/analyze/fractalendpoint. - It receives the fractal dimension and interpretation.
- Based on the result, it can advise a merchant:
- If dimension is low (< 1.5): "This product is showing a stable growth trend. Consider increasing your ad spend and reordering inventory."
- If dimension is high (> 1.8): "This product's sales are highly chaotic and may be a one-time viral spike. Be cautious about reordering large amounts of inventory."
Example: Trend-Spotting Agent in Python
import requests
import os
def analyze_trend(product_id: str, sales_data: list[int]):
api_key = os.getenv("ABA_API_KEY")
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
url = "https://api.abbababa.com/v1/analyze/fractal"
payload = {"data": sales_data}
try:
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
analysis = response.json()
print(f"Analysis for Product ID: {product_id}")
print(f"Fractal Dimension: {analysis['fractalDimension']:.4f}")
print(f"Interpretation: {analysis['interpretation']}")
print(f"API Cost: {analysis['billing']['tokenCost']} tokens")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
# Example 1: A product with steady, predictable growth
stable_trend_sales = [10, 12, 11, 15, 18, 20, 22, 25, 24, 30, 32, 35, 38, 40, 41, 45, 48, 50, 55, 53]
analyze_trend("PROD-STABLE", stable_trend_sales)
print("\n" + "---" * 10 + "\n")
# Example 2: A product that went viral and then crashed
chaotic_spike_sales = [5, 6, 5, 8, 7, 250, 30, 80, 15, 50, 4, 9, 12, 7, 6, 10, 8, 9, 11, 10]
analyze_trend("PROD-CHAOTIC", chaotic_spike_sales)Why This is a Superpower for Agents
This API allows your agents to move beyond simple descriptive analytics ("what happened") into the realm of inferential analytics ("what is likely to happen"). It's a unique tool that can give your agent a significant competitive advantage in providing high-value market insights.