Skip to content

kirklin/kelly-criterion

Repository files navigation

kelly-criterion

npm version npm downloads bundle JSDocs License javascript_code style

A Kelly Criterion calculator written in TypeScript

Kelly Criterion Calculator

Introduction

The Kelly Criterion Calculator is a TypeScript class designed for calculating the Kelly Criterion, a formula used in probability theory and investing to determine the optimal size of a series of bets. This class provides methods to compute both the Kelly Criterion fraction and the optimal fraction to bet based on a given win probability and payoff ratio.

Installation

Install the package using pnpm:

npm install kelly-criterion

Example

import { KellyCriterion } from 'kelly-criterion';

// Create an instance of the KellyCriterion class
const kellyCalculator = new KellyCriterion();

// Set the win probability and payoff ratio
const winProbability = 0.6; // 60% chance of winning
const payoffRatio = 2; // 2:1 payoff ratio

// Calculate the Kelly Criterion fraction
const kellyFraction = kellyCalculator.calKellyCriterion(winProbability, payoffRatio);
console.log(`Kelly Criterion Fraction: ${kellyFraction}`);

// Calculate the optimal fraction to bet
const optimalFraction = kellyCalculator.calOptimalFraction(winProbability, payoffRatio);
console.log(`Optimal Fraction to Bet: ${optimalFraction}`);

Methods

calKellyCriterion(winProbability: number, payoffRatio: number): number

Calculates the Kelly Criterion fraction based on the given win probability and payoff ratio.

  • winProbability: The probability of winning (a value between 0 and 1).
  • payoffRatio: The ratio of the payoff (e.g., 2 for 2:1 odds).
  • Returns: The calculated Kelly Criterion fraction.

calOptimalFraction(winProbability: number, payoffRatio: number): number

Calculates the optimal fraction to bet based on the Kelly Criterion.

  • winProbability: The probability of winning (a value between 0 and 1).
  • payoffRatio: The ratio of the payoff (e.g., 2 for 2:1 odds).
  • Returns: The calculated optimal fraction to bet.

License

MIT License © 2023-PRESENT Kirk Lin

About

A Kelly Criterion calculator written in TypeScript

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published