Statistics Utilities

Calculate Covariance

Calculates covariance between two numerical datasets to measure their linear relationship. Access via MCP in Cursor or Windsurf, or REST at `/v1/stats/covariance`. Pass two arrays of equal length — returns precise covariance value showing how variables change together. Essential for correlation analysis and portfolio risk assessment.

API Endpoint

GET /v1/stats/covariance

Code Examples

curl "https://tinyfn.io/v1/stats/covariance" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/stats/covariance', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/stats/covariance',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's statistics tools:

{
  "mcpServers": {
    "tinyfn-stats": {
      "url": "https://tinyfn.io/mcp/stats",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How do I calculate covariance between two datasets using MCP?

Pass two equal-length arrays to the covariance tool in your MCP-enabled editor. The tool returns the exact covariance value showing linear relationship strength.

What does a positive vs negative covariance mean?

Positive covariance means variables tend to increase together, negative means one increases as the other decreases. Zero indicates no linear relationship.

Do the datasets need to be the same length for covariance calculation?

Yes, both datasets must have identical length. Mismatched arrays will return an error since covariance requires paired observations.

How is this different from correlation coefficient?

Covariance shows direction of relationship but not strength (units matter). Correlation normalizes this to -1 to +1 range for easier interpretation.

Can I use this for financial portfolio analysis?

Absolutely. Covariance between asset returns helps assess diversification benefits and portfolio risk in quantitative finance models.

Try Calculate Covariance Now

Get your free API key and start using Calculate Covariance in seconds.

Get Free API Key