Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/694a9127-1940-8001-9b22-f125f741a780
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== 🧮 MODULE 20 — KELLY-FRACTION ADAPTIVE RISK (INSTITUTIONAL SAFE) === ==== 🎯 Objective ==== Continuously size risk based on edge strength, but: * Cap aggression * Respect drawdown * Respect regime & correlation filters * Never go full Kelly (too volatile) ==== 1️⃣ Kelly Math (R-Based, Robust) ==== Classic Kelly: f∗=bp−qbf^* = \frac{bp - q}{b}f∗=bbp−q Where: * bbb = reward-to-risk (RR) * ppp = win probability * q=1−pq = 1 - pq=1−p We derive p and b from live trade history, not assumptions. ==== 2️⃣ Data Buckets (Context-Aware Kelly) ==== We reuse expectancy context, because Kelly must be conditional. <syntaxhighlight lang="pinescript">var array<string> k_keys = array.new_string() var array<int> k_wins = array.new_int() var array<int> k_losses = array.new_int() var array<float> k_rsum = array.new_float() </syntaxhighlight> ==== 3️⃣ Kelly Key (Same Context as Expectancy) ==== <syntaxhighlight lang="pinescript">kelly_key(string session, string regime, string htf_bias, string side) => session + "|" + regime + "|" + htf_bias + "|" + side </syntaxhighlight> ==== 4️⃣ Update Kelly Stats (After Trade Close) ==== Call once per closed trade: <syntaxhighlight lang="pinescript">update_kelly(string key, float trade_r) => idx = array.indexof(k_keys, key) if idx == -1 array.push(k_keys, key) array.push(k_wins, trade_r > 0 ? 1 : 0) array.push(k_losses, trade_r <= 0 ? 1 : 0) array.push(k_rsum, trade_r) else array.set(k_wins, idx, array.get(k_wins, idx) + (trade_r > 0 ? 1 : 0)) array.set(k_losses, idx, array.get(k_losses, idx) + (trade_r <= 0 ? 1 : 0)) array.set(k_rsum, idx, array.get(k_rsum, idx) + trade_r) </syntaxhighlight> ==== 5️⃣ Kelly Fraction Calculation (CAPPED & SAFE) ==== <syntaxhighlight lang="pinescript">calc_kelly_fraction(string key) => idx = array.indexof(k_keys, key) if idx == -1 0.0 else wins = array.get(k_wins, idx) losses = array.get(k_losses, idx) total = wins + losses if total < 20 0.0 else p = wins / total avg_r = array.get(k_rsum, idx) / total b = math.max(avg_r, 0.1) raw_kelly = (b * p - (1 - p)) / b // HARD SAFETY CAPS math.clamp(raw_kelly, 0.0, 0.25) </syntaxhighlight> 🔒 Important * Minimum sample size * Kelly ≤ 25% * Negative edge → zero risk ==== 6️⃣ Fractional Kelly (Prop-Safe) ==== Never use full Kelly. <syntaxhighlight lang="pinescript">KELLY_FRACTION = 0.30 // 30% Kelly (recommended) </syntaxhighlight> <syntaxhighlight lang="pinescript">kelly_mult = calc_kelly_fraction(k_key) * KELLY_FRACTION </syntaxhighlight> ==== 7️⃣ Final Risk Composition (CRITICAL) ==== Your final risk per trade becomes: <syntaxhighlight lang="pinescript">base_risk = get_risk_pct(regime) // Apply system modifiers risk_pct = base_risk * equity_risk_mult * corr_risk_mult * htf_risk_mult(htf_bias, side) // Apply Kelly LAST risk_pct := risk_pct * (1 + kelly_mult) // Absolute hard cap (prop-safe) risk_pct := math.min(risk_pct, 1.0) </syntaxhighlight> ✔ Kelly only amplifies edge ✔ Never increases risk during drawdown ✔ Automatically shrinks to zero when edge disappears ==== 8️⃣ Master Safety Override ==== If any of these are true → Kelly ignored: <syntaxhighlight lang="pinescript">if trading_paused or equity_regime() == "cold" or corr_regime == "high" kelly_mult := 0.0 </syntaxhighlight> ==== 9️⃣ Where to Call Updates (Summary) ==== After each closed trade: <syntaxhighlight lang="pinescript">k_key = kelly_key(session, regime, htf_bias, side) update_kelly(k_key, trade_r) update_expectancy(exp_key, trade_r) update_regime_stats(regime, trade_r) update_equity(trade_r) update_drawdown() </syntaxhighlight>
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)