Ml4t Risk Metrics logo

Ml4t Risk Metrics

Organization
ml4t
ml4t-risk-metrics

Compute portfolio risk measures including drawdown, VaR, CVaR, and tail metrics. Use when assessing portfolio risk beyond simple return statistics.

Overview

Publisherml4t
Repositoryskills
Skill nameml4t-risk-metrics
Stars
45
Forks
13
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by ml4t on GitHub. Read the source before you install it.

Installation

Install the Ml4t Risk Metrics AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/ml4t/skills/tree/main/portfolio/risk-metrics
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ml4t/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/portfolio/risk-metrics .claude/skills/ml4t-risk-metrics
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Ml4t Risk Metrics in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Ml4t Risk Metrics on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Ml4t Risk Metrics is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Risk Metrics

A strategy with Sharpe 1.5 and max drawdown -55% will get shut down before it recovers. Reporting returns without drawdowns, tail risk, and duration metrics hides the path dependency that determines whether a strategy survives.

The Problem

Sharpe ratio is the default performance metric, but it treats upside and downside volatility equally and says nothing about tail losses. A strategy can have a high Sharpe while hiding a -40% drawdown that takes 18 months to recover. Fund managers and allocators care about max drawdown, time underwater, and worst-case losses - because those determine whether the strategy (and the fund) survives. Always report drawdown alongside return metrics.

The Pattern

WRONG

python
import numpy as np

returns = strategy_returns  # daily
sharpe = returns.mean() / returns.std() * np.sqrt(252)
print(f"Sharpe: {sharpe:.2f}")  # Looks great - ships it

CORRECT

python
import numpy as np
from scipy.stats import norm

returns = strategy_returns  # daily, numpy array

# Return metrics
sharpe = returns.mean() / returns.std() * np.sqrt(252)
downside = np.minimum(returns, 0)  # All returns: negative kept, positive → 0
sortino = returns.mean() / np.sqrt((downside ** 2).mean()) * np.sqrt(252)

# Drawdown
cumulative = np.cumprod(1 + returns)
running_max = np.maximum.accumulate(cumulative)
drawdown = (cumulative - running_max) / running_max
max_dd = drawdown.min()
calmar = (returns.mean() * 252) / abs(max_dd)

# Tail risk (95% confidence)
var_95 = np.percentile(returns, 5)
cvar_95 = returns[returns <= var_95].mean()

print(f"Sharpe: {sharpe:.2f} | Sortino: {sortino:.2f} | Calmar: {calmar:.2f}")
print(f"Max DD: {max_dd:.1%} | VaR(95): {var_95:.1%} | CVaR(95): {cvar_95:.1%}")

Metric Reference

MetricFormulaMeasures
Sharpemean(r) / std(r) * sqrt(252)Risk-adjusted return
Sortinomean(r) / sqrt(E[min(r,0)^2]) * sqrt(252)Downside-adjusted return
Max drawdownmax peak-to-trough declineWorst cumulative loss
Calmarann_return / |max_dd|Return per unit of drawdown
VaR(95%)5th percentile of returnsDaily loss threshold
CVaR(95%)mean of returns below VaRExpected loss in tail

Parametric vs Historical VaR

python
# Historical: uses actual distribution (captures fat tails)
var_hist = np.percentile(returns, 5)

# Parametric: assumes normal (underestimates tails)
var_param = returns.mean() + norm.ppf(0.05) * returns.std()

# Always prefer historical unless you need scenario-based VaR

Guardrails

  • Never report Sharpe alone - always include max drawdown and Calmar at minimum
  • VaR underestimates tail risk by design - pair it with CVaR (Expected Shortfall)
  • Historical VaR assumes the past contains the worst case - it does not
  • Annualize consistently: multiply mean by 252, std by sqrt(252) for daily data
  • Monitor current drawdown in real time, not just historical max

Production Implementation

ml4t-diagnostic provides validated risk computation:

python
from ml4t.diagnostic.api import PortfolioAnalysis

pa = PortfolioAnalysis(returns=strategy_returns, benchmark=benchmark_returns)
metrics = pa.compute_summary_stats()
report = metrics.summary()  # Sharpe, Sortino, max_dd, Calmar, VaR, CVaR, etc.

Checklist

  • Sharpe, Sortino, and Calmar all reported (not Sharpe alone)
  • Max drawdown and drawdown duration computed
  • CVaR computed alongside VaR for tail risk
  • Metrics annualized consistently (daily * sqrt(252))
  • Current drawdown monitored in live systems (not just historical max)

Frequently asked questions

What does the Ml4t Risk Metrics AI skill do?

Compute portfolio risk measures including drawdown, VaR, CVaR, and tail metrics. Use when assessing portfolio risk beyond simple return statistics.

Why use Ml4t Risk Metrics on TypingMind?

Because you install it once and use it with any model. Ml4t Risk Metrics is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Ml4t Risk Metrics in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/ml4t/skills/tree/main/portfolio/risk-metrics. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Ml4t Risk Metrics?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Ml4t Risk Metrics?

As many as you like. As long as a model supports skills, you can use Ml4t Risk Metrics with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Ml4t Risk Metrics AI skill free?

Yes. It is published on GitHub by ml4t under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇