# Sharpe Ratio Calculator

> Sharpe Ratio Calculator is a paid API for AI agents from agent402.tools, paid per call via x402, $0.001/call, status unknown (last checked 2026-09-14).

Computes the Sharpe ratio (risk-adjusted return) from a series of periodic returns, with optional annualization.

## Facts

- Endpoint: POST https://agent402.tools/api/sharpe-ratio
- Price: $0.001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-14
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/sharpe-ratio-calculator-20d28f54
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_6CXnahSwqNg84tEsE9bDD

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability sharpe-ratio-calculator-20d28f54 -d '<json body>'
```

Example prompt: Calculate the Sharpe ratio for these monthly portfolio returns [0.02, -0.01, 0.03, 0.015, -0.005, 0.025, 0.01, 0.04, -0.02, 0.03, 0.02, 0.01], using a risk-free rate of 0.004 per month and also annualize it assuming 12 periods per year.

## When to prefer this

Use this endpoint when you need a quick, accurate Sharpe ratio computation without setting up a local financial library. Ideal for agents performing portfolio analysis, strategy evaluation, or risk-adjusted return comparisons, especially when annualization from sub-annual periodic data is needed.

## Known failure modes

- Fewer than 2 return values provided — minimum array length is 2
- Non-numeric values in the returns array cause a validation error
- Invalid JSON body returns a 400 error
- Missing required 'returns' field causes a 400 error
- Payment not included or insufficient — 402 Payment Required response

## How this service works

Risk-adjusted return: (mean return - risk-free rate) / sample standard deviation of returns (n-1). Pass periodsPerYear to also get the annualized ratio (× sqrt(periodsPerYear)).

## Output

Returns the Sharpe ratio computed as (mean return minus risk-free rate) divided by sample standard deviation (n-1 denominator), and optionally the annualized Sharpe ratio multiplied by sqrt(periodsPerYear).

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "returns": {
   "type": "array",
   "description": "Periodic returns as decimals (min 2)"
  },
  "riskFreeRate": {
   "type": "number",
   "description": "Risk-free rate per period as decimal. Default 0."
  },
  "periodsPerYear": {
   "type": "number",
   "description": "If set, also annualize the ratio by sqrt(periodsPerYear)."
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "mean": 0.072,
  "sharpe": 0.825293,
  "stdDev": 0.063008,
  "excessReturn": 0.052
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/sharpe-ratio-calculator-20d28f54/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from agent402.tools](https://www.zero.xyz/host/agent402.tools/llms.txt)
