polymarket-risk-manager 3.1.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -12
- package/index.js +2 -26
- package/kelly.js +56 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
# polymarket-risk-manager
|
|
2
2
|
|
|
3
|
-
Kelly-criterion
|
|
3
|
+
Kelly-criterion helpers for Polymarket **Up/Down** binary markets.
|
|
4
|
+
|
|
5
|
+
## Changelog
|
|
6
|
+
|
|
7
|
+
### 3.3.0
|
|
8
|
+
|
|
9
|
+
- Added `roundStake()` for 2dp stake rounding
|
|
10
|
+
|
|
11
|
+
### 3.2.0
|
|
12
|
+
|
|
13
|
+
- Added `formatStakeUsd()`
|
|
14
|
+
|
|
15
|
+
### 3.1.0
|
|
16
|
+
|
|
17
|
+
- Initial Kelly stake release
|
|
4
18
|
|
|
5
19
|
## Install
|
|
6
20
|
|
|
@@ -8,19 +22,10 @@ Kelly-criterion stake sizing for Polymarket-style binary markets.
|
|
|
8
22
|
npm install polymarket-risk-manager
|
|
9
23
|
```
|
|
10
24
|
|
|
11
|
-
## API
|
|
25
|
+
## API
|
|
12
26
|
|
|
13
27
|
```javascript
|
|
14
|
-
const { computeKellyStake } = require('polymarket-risk-manager');
|
|
15
|
-
|
|
16
|
-
computeKellyStake({
|
|
17
|
-
probability: 0.58,
|
|
18
|
-
allInPrice: 0.52,
|
|
19
|
-
bankroll: 500,
|
|
20
|
-
maxStake: 25,
|
|
21
|
-
minStake: 5,
|
|
22
|
-
kellyFraction: 0.5,
|
|
23
|
-
});
|
|
28
|
+
const { computeKellyStake, formatStakeUsd, roundStake } = require('polymarket-risk-manager');
|
|
24
29
|
```
|
|
25
30
|
|
|
26
31
|
## Licence
|
package/index.js
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
function computeKellyStake({
|
|
5
|
-
probability,
|
|
6
|
-
allInPrice,
|
|
7
|
-
bankroll,
|
|
8
|
-
maxStake,
|
|
9
|
-
minStake = 0,
|
|
10
|
-
kellyFraction = 0.5,
|
|
11
|
-
}) {
|
|
12
|
-
if (
|
|
13
|
-
!Number.isFinite(probability) ||
|
|
14
|
-
!Number.isFinite(allInPrice) ||
|
|
15
|
-
!Number.isFinite(bankroll) ||
|
|
16
|
-
allInPrice <= 0 ||
|
|
17
|
-
allInPrice >= 1
|
|
18
|
-
) {
|
|
19
|
-
return minStake;
|
|
20
|
-
}
|
|
3
|
+
const { computeKellyStake, formatStakeUsd, roundStake } = require('./kelly.js');
|
|
21
4
|
|
|
22
|
-
|
|
23
|
-
if (rawKelly <= 0) return minStake;
|
|
24
|
-
|
|
25
|
-
const stake = bankroll * rawKelly * kellyFraction;
|
|
26
|
-
return Math.min(maxStake, Math.max(minStake, stake));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = { computeKellyStake };
|
|
5
|
+
module.exports = { computeKellyStake, formatStakeUsd, roundStake };
|
package/kelly.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function round(value, dp) {
|
|
4
|
+
const n = Number(value);
|
|
5
|
+
const places = Number(dp) || 0;
|
|
6
|
+
if (!Number.isFinite(n)) return NaN;
|
|
7
|
+
const p = 10 ** places;
|
|
8
|
+
return Math.round(n * p) / p;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function format(value, dp) {
|
|
12
|
+
const n = round(value, dp);
|
|
13
|
+
if (!Number.isFinite(n)) return String(value);
|
|
14
|
+
return n.toFixed(dp == null ? 0 : dp);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function computeKellyStake({
|
|
18
|
+
probability,
|
|
19
|
+
allInPrice,
|
|
20
|
+
bankroll,
|
|
21
|
+
maxStake,
|
|
22
|
+
minStake = 0,
|
|
23
|
+
kellyFraction = 0.5,
|
|
24
|
+
}) {
|
|
25
|
+
if (
|
|
26
|
+
!Number.isFinite(probability) ||
|
|
27
|
+
!Number.isFinite(allInPrice) ||
|
|
28
|
+
!Number.isFinite(bankroll) ||
|
|
29
|
+
allInPrice <= 0 ||
|
|
30
|
+
allInPrice >= 1
|
|
31
|
+
) {
|
|
32
|
+
return minStake;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const rawKelly = (probability - allInPrice) / (1 - allInPrice);
|
|
36
|
+
if (rawKelly <= 0) return minStake;
|
|
37
|
+
|
|
38
|
+
const stake = bankroll * rawKelly * kellyFraction;
|
|
39
|
+
return round(Math.min(maxStake, Math.max(minStake, stake)), 2);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function formatStakeUsd(value) {
|
|
43
|
+
return format(value, 2);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function roundStake(value) {
|
|
47
|
+
return round(value, 2);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = {
|
|
51
|
+
computeKellyStake,
|
|
52
|
+
formatStakeUsd,
|
|
53
|
+
roundStake,
|
|
54
|
+
round,
|
|
55
|
+
format,
|
|
56
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polymarket-risk-manager",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.3.0",
|
|
4
|
+
"description": "Kelly stake sizing and decimal-safe rounding for Polymarket binary markets",
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"files": ["index.js", "README.md"],
|
|
7
|
-
"keywords": ["polymarket", "kelly", "prediction-markets", "stake"],
|
|
6
|
+
"files": ["index.js", "kelly.js", "README.md"],
|
|
7
|
+
"keywords": ["polymarket", "kelly", "prediction-markets", "stake", "binary"],
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "commonjs"
|
|
10
10
|
}
|