autonome-markets
v0.1.0
Published
The Script language behind autonome — a versioned schema for portfolio rules, a deterministic plain-English compiler, and a rule evaluator for cross-asset strategies.
Maintainers
Readme
autonome-markets
The Script language behind autonome.
A versioned schema for portfolio rules, a deterministic plain-English compiler that produces them, and an evaluator that decides whether one fires.
Pure functions only — no network, no execution, no side effects. Runs in the browser, Node, edge runtimes and workers.
npm install autonome-markets zodzod is a peer dependency, so your application controls the version.
The shape of a Script
WHEN → CONDITIONS → ACTIONS → GUARDSA trigger says when to evaluate. Conditions narrow it. Actions describe the capital movement. Guards describe what the runtime may never do.
Compile plain English
import { compileIntent } from 'autonome-markets'
const result = compileIntent(
'If BTC falls 15% from its 30-day high, allocate $1,000 from my Treasury ' +
'reserve, but keep at least 20% of my portfolio in stable assets.',
)
if (result.ok) {
console.log(result.definition)
console.log(result.confidence) // 0.99
console.log(result.assumptions) // defaults it applied, stated plainly
}The compiler is deterministic and runs entirely locally — there is no model call and nothing leaves the process. When it is unsure it says so rather than inventing a rule:
const vague = compileIntent('make me money somehow')
vague.ok // false
vague.errors // ['Could not determine when this Script should run.']Produced definition:
{
"version": 1,
"trigger": { "type": "drawdown", "asset": "BTC", "value": 15, "window": "30d" },
"conditions": [],
"actions": [
{ "type": "allocate", "source": "UST", "destination": "BTC", "amount": 1000, "unit": "usd" }
],
"guards": [{ "type": "min_stable_reserve", "value": 20, "unit": "percent" }],
"metadata": { "compiler": "local-v1", "confidence": 0.99, "benchmark": "BTC" }
}Validate a definition
Only definitions that satisfy the schema should ever be persisted.
import { validateScriptDefinition, SCRIPT_SCHEMA_VERSION } from 'autonome-markets'
const { ok, definition, errors } = validateScriptDefinition(input)
if (!ok) console.error(errors) // ['actions: Too small: expected array to have >=1 items']The schema is versioned (SCRIPT_SCHEMA_VERSION) so future runtimes can be
introduced without invalidating Scripts that already exist.
Evaluate a rule
evaluateScript is the single implementation of the WHEN → GUARD logic. Point
it at whatever market and portfolio data you have.
import { evaluateScript } from 'autonome-markets'
const outcome = evaluateScript(
definition,
{
now: Date.now(),
price: (symbol) => prices[symbol] ?? null,
changePct: (symbol, window) => changes[`${symbol}:${window}`] ?? null,
rollingHigh: (symbol) => highs[symbol] ?? null,
},
{
totalValue: 100_000,
weights: { BTC: 22, UST: 38, USDC: 20, SPY: 20 },
stableReservePct: 58,
lastExecutionAt: null,
allocatedTodayUsd: 0,
},
)
outcome.triggered // true
outcome.guardsPassed // false
outcome.reason // 'Maximum BTC allocation reached (31.2%)'
outcome.guardResults // per-guard pass/fail with a readable detailMissing data is reported, never assumed: if a price is unavailable the outcome
is triggered: false with a reason saying so.
Describe a Script to a human
import { describeTrigger, describeAction, summariseScript } from 'autonome-markets'
describeTrigger(definition.trigger)
// 'BTC falls 15% from its 30D high'
summariseScript(definition)
// 'BTC falls 15% from its 30D high → Allocate $1,000 from UST to BTC'triggerParts() and actionParts() return label/value pairs if you are
rendering the rule as a diagram rather than a sentence.
Statistics
The same functions the autonome backtest report is built from.
import { maxDrawdown, sharpeRatio, annualisedVolatility, periodReturns } from 'autonome-markets'
const returns = periodReturns(equityCurve)
maxDrawdown(equityCurve) // -42.04 (negative percent)
annualisedVolatility(returns, 252) // 33.14
sharpeRatio(returns, 252) // -0.68Asset registry
29 assets across equities, crypto, RWAs, commodities and stablecoins, with the provider, chain and contract metadata the compiler resolves symbols against.
import { ASSETS, getAsset } from 'autonome-markets'
getAsset('BTC')?.assetClass // 'crypto'
getAsset('UST')?.market // 'Treasuries'
ASSETS.length // 29API surface
| Group | Exports |
| --- | --- |
| Schema | scriptDefinitionSchema, validateScriptDefinition, SCRIPT_SCHEMA_VERSION, and the trigger/action/guard schemas |
| Compiler | compileIntent, LocalScriptCompiler, ASSET_ALIASES |
| Runtime | evaluateScript, evaluateTrigger, evaluateGuard, windowDays |
| Describe | describeTrigger, describeAction, describeGuard, summariseScript, monitoredAssets |
| Registry | ASSETS, getAsset, requireAsset, PRICED_SYMBOLS |
| Statistics | maxDrawdown, sharpeRatio, annualisedVolatility, totalReturnPct, and friends |
| Formatting | formatCurrency, formatPct, shortenAddress |
Full TypeScript types ship with the package.
What this package does not do
It is a language and a rule engine, not a trading system.
- No network access, no market data fetching, no API keys.
- No order placement, venue connection or custody. Execution adapters live in the application, not here.
- No investment advice. Simulated behaviour is hypothetical and no return is guaranteed.
Links
- Product — https://autonomemarkets.com
- Documentation — https://autonomemarkets.com/docs
- X — @autonomemarkets
MIT © autonome
