Writing and using a library

Functions and constants you reuse.

AlgoBarsX
library "Quant Toolkit"
const TRADING_DAYS = 252
fn kelly_fraction(win_rate: number, payoff: number) -> number:
return win_rate - (1 - win_rate) / payoff
fn annualized_volatility(source: series<number> = close, length: int = 20) -> number:
return stdev(returns(source), length) * sqrt(TRADING_DAYS)
fn position_heat(risks: list<percent>) -> percent:
total = 0%
for r in risks:
total += r
return total

A library holds functions, constants and types. It cannot place orders or draw (AS0405). Import it with use library "Quant Toolkit" v2 as qt and call qt.kelly_fraction(0.55, 1.8).

Examples: Quant Toolkit, Risk Parity, Ranking Tools, and a strategy that uses one: Kelly Sized Breakout.

Try this in the Terminal. AlgoBars is free: $0 a month, no card needed.

Create my free account