@idlekit/core 0.4.0 → 0.5.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 +30 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/ltv/projection.d.ts +10 -0
- package/dist/ltv/projection.js +102 -0
- package/dist/ltv/projection.js.map +1 -0
- package/dist/ltv/public.d.ts +19 -0
- package/dist/ltv/public.js +88 -0
- package/dist/ltv/public.js.map +1 -0
- package/dist/ltv/types.d.ts +49 -0
- package/dist/ltv/types.js +2 -0
- package/dist/ltv/types.js.map +1 -0
- package/dist/ltv/uncertainty.d.ts +15 -0
- package/dist/ltv/uncertainty.js +178 -0
- package/dist/ltv/uncertainty.js.map +1 -0
- package/dist/scenario/scenarioContract.d.ts +2 -2
- package/dist/scenario/scenarioContract.js +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -16,6 +16,36 @@ Use this package when you need:
|
|
|
16
16
|
- simulation loop and `stepOnce`
|
|
17
17
|
- built-in strategies and tuning primitives
|
|
18
18
|
- growth, milestone, session-pattern, and Monte Carlo analysis
|
|
19
|
+
- hypothetical LTV estimates via `deriveMonetizationConfig`, `estimateLtvPerUser` and `estimateLtvDistribution`
|
|
20
|
+
|
|
21
|
+
## LTV estimates
|
|
22
|
+
|
|
23
|
+
Import the three LTV functions and the `MonetizationConfig` / `LtvPointEstimate` types from
|
|
24
|
+
`@idlekit/core`. Pass a `ScenarioV1` to `deriveMonetizationConfig`; pass the returned config,
|
|
25
|
+
`horizonDays` and `progression` to `estimateLtvPerUser`. `estimateLtvDistribution` additionally
|
|
26
|
+
takes `draws`, `quantiles` and `seed`. The CLI uses the same implementation.
|
|
27
|
+
|
|
28
|
+
Inputs are hypothetical assumptions, in one caller-chosen currency per installed user.
|
|
29
|
+
Defaults are not observed retention or measured revenue. Net revenue applies platform fees
|
|
30
|
+
and gross margin; LTV then subtracts CPI, including at a zero-day horizon. Fractional days
|
|
31
|
+
are prorated. Finite progression is clamped to 0..1. Quantile bands describe sensitivity to
|
|
32
|
+
assumptions, not fitted confidence intervals or evidence of enjoyment/retention.
|
|
33
|
+
|
|
34
|
+
Synchronous limits: 0..36500 days, 1..100000 draws and at most 10000000 draw-days (at least
|
|
35
|
+
one work unit per draw). Quantiles must be nonempty values in 0..1 with distinct rounded
|
|
36
|
+
percent keys (`q50`, `q90`). Invalid inputs, colliding keys and numeric overflow throw
|
|
37
|
+
`RangeError`. Sampling shrinks inconsistent correlation matrices toward independence.
|
|
38
|
+
Calibration of a complete observed cohort remains available through the public `idk calibrate` CLI.
|
|
39
|
+
Public estimate configs accept quantile endpoints too. Distribution output keys use its
|
|
40
|
+
explicit `quantiles` argument, not config metadata. `ScenarioV1` authored quantiles retain
|
|
41
|
+
their existing `(0, 1)` schema when passed to `deriveMonetizationConfig`.
|
|
42
|
+
|
|
43
|
+
Partial scenario retention overrides keep the CLI's independent defaults. For example,
|
|
44
|
+
`d1: 0.1` alone retains the default `d7: 0.2`; estimates preserve that existing interpolation.
|
|
45
|
+
Explicit complete scenario curves still follow scenario ordering validation. Direct estimate
|
|
46
|
+
configs validate each rate's range without adding an ordering constraint to completed defaults.
|
|
47
|
+
Sampling retains its existing clamp of later retention anchors to the preceding anchor,
|
|
48
|
+
so this partial-input case can differ from the point projection even with zero uncertainty.
|
|
19
49
|
|
|
20
50
|
## Quick example
|
|
21
51
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,eAAe,CAAC;AAE9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,C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AwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ScenarioV1 } from "../scenario/types";
|
|
2
|
+
import type { LtvPointEstimate, MonetizationConfig } from "./types";
|
|
3
|
+
export declare function deriveMonetizationConfig(scenario: ScenarioV1): MonetizationConfig;
|
|
4
|
+
export declare function retentionAtDay(ret: MonetizationConfig["retention"], day: number): number;
|
|
5
|
+
export declare function progressionFactor(startWorthLog10: number, endWorthLog10: number, span: number): number;
|
|
6
|
+
export declare function estimateLtvPerUser(args: {
|
|
7
|
+
config: MonetizationConfig;
|
|
8
|
+
horizonDays: number;
|
|
9
|
+
progression: number;
|
|
10
|
+
}): LtvPointEstimate;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
function clamp01(v) {
|
|
2
|
+
if (v < 0)
|
|
3
|
+
return 0;
|
|
4
|
+
if (v > 1)
|
|
5
|
+
return 1;
|
|
6
|
+
return v;
|
|
7
|
+
}
|
|
8
|
+
export function deriveMonetizationConfig(scenario) {
|
|
9
|
+
const m = scenario.monetization;
|
|
10
|
+
const q = (m?.uncertainty?.quantiles ?? [0.5, 0.9]).filter((x) => typeof x === "number");
|
|
11
|
+
const quantiles = q.length > 0 ? [...new Set(q)].sort((a, b) => a - b) : [0.5, 0.9];
|
|
12
|
+
return {
|
|
13
|
+
cohorts: {
|
|
14
|
+
baseUsers: m?.cohorts?.baseUsers ?? 1,
|
|
15
|
+
},
|
|
16
|
+
retention: {
|
|
17
|
+
d1: m?.retention?.d1 ?? 0.42,
|
|
18
|
+
d7: m?.retention?.d7 ?? 0.2,
|
|
19
|
+
d30: m?.retention?.d30 ?? 0.09,
|
|
20
|
+
d90: m?.retention?.d90 ?? 0.04,
|
|
21
|
+
longTailDailyDecay: m?.retention?.longTailDailyDecay ?? 0.02,
|
|
22
|
+
},
|
|
23
|
+
revenue: {
|
|
24
|
+
payerConversion: m?.revenue?.payerConversion ?? 0.03,
|
|
25
|
+
arppuDaily: m?.revenue?.arppuDaily ?? 0.7,
|
|
26
|
+
adArpDau: m?.revenue?.adArpDau ?? 0.02,
|
|
27
|
+
platformFeeRate: m?.revenue?.platformFeeRate ?? 0.3,
|
|
28
|
+
grossMarginRate: m?.revenue?.grossMarginRate ?? 0.92,
|
|
29
|
+
progressionRevenueLift: m?.revenue?.progressionRevenueLift ?? 0.4,
|
|
30
|
+
progressionLogSpan: m?.revenue?.progressionLogSpan ?? 6,
|
|
31
|
+
},
|
|
32
|
+
acquisition: {
|
|
33
|
+
cpi: m?.acquisition?.cpi ?? 0,
|
|
34
|
+
},
|
|
35
|
+
uncertainty: {
|
|
36
|
+
enabled: m?.uncertainty?.enabled ?? false,
|
|
37
|
+
draws: m?.uncertainty?.draws ?? 300,
|
|
38
|
+
quantiles,
|
|
39
|
+
seed: m?.uncertainty?.seed,
|
|
40
|
+
sigma: {
|
|
41
|
+
retention: m?.uncertainty?.sigma?.retention ?? 0.08,
|
|
42
|
+
conversion: m?.uncertainty?.sigma?.conversion ?? 0.12,
|
|
43
|
+
arppu: m?.uncertainty?.sigma?.arppu ?? 0.2,
|
|
44
|
+
ad: m?.uncertainty?.sigma?.ad ?? 0.15,
|
|
45
|
+
},
|
|
46
|
+
correlation: {
|
|
47
|
+
retentionConversion: m?.uncertainty?.correlation?.retentionConversion ?? 0,
|
|
48
|
+
retentionArppu: m?.uncertainty?.correlation?.retentionArppu ?? 0,
|
|
49
|
+
retentionAd: m?.uncertainty?.correlation?.retentionAd ?? 0,
|
|
50
|
+
conversionArppu: m?.uncertainty?.correlation?.conversionArppu ?? 0,
|
|
51
|
+
conversionAd: m?.uncertainty?.correlation?.conversionAd ?? 0,
|
|
52
|
+
arppuAd: m?.uncertainty?.correlation?.arppuAd ?? 0,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function retentionAtDay(ret, day) {
|
|
58
|
+
if (day <= 0)
|
|
59
|
+
return 1;
|
|
60
|
+
if (day <= 1)
|
|
61
|
+
return ret.d1;
|
|
62
|
+
if (day <= 7)
|
|
63
|
+
return ret.d1 + ((ret.d7 - ret.d1) * (day - 1)) / 6;
|
|
64
|
+
if (day <= 30)
|
|
65
|
+
return ret.d7 + ((ret.d30 - ret.d7) * (day - 7)) / 23;
|
|
66
|
+
if (day <= 90)
|
|
67
|
+
return ret.d30 + ((ret.d90 - ret.d30) * (day - 30)) / 60;
|
|
68
|
+
const extra = day - 90;
|
|
69
|
+
return clamp01(ret.d90 * Math.exp(-ret.longTailDailyDecay * extra));
|
|
70
|
+
}
|
|
71
|
+
export function progressionFactor(startWorthLog10, endWorthLog10, span) {
|
|
72
|
+
if (!Number.isFinite(startWorthLog10) || !Number.isFinite(endWorthLog10) || !Number.isFinite(span) || span <= 0) {
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
return clamp01((endWorthLog10 - startWorthLog10) / span);
|
|
76
|
+
}
|
|
77
|
+
export function estimateLtvPerUser(args) {
|
|
78
|
+
const { config, horizonDays } = args;
|
|
79
|
+
const progression = clamp01(args.progression);
|
|
80
|
+
const arppuDaily = config.revenue.arppuDaily * (1 + progression * config.revenue.progressionRevenueLift);
|
|
81
|
+
const adArpDau = config.revenue.adArpDau * (1 + progression * config.revenue.progressionRevenueLift * 0.5);
|
|
82
|
+
const payerConversion = config.revenue.payerConversion;
|
|
83
|
+
const fullDays = Math.floor(Math.max(0, horizonDays));
|
|
84
|
+
const remainder = Math.max(0, horizonDays - fullDays);
|
|
85
|
+
let gross = 0;
|
|
86
|
+
for (let day = 1; day <= fullDays; day++) {
|
|
87
|
+
const active = retentionAtDay(config.retention, day);
|
|
88
|
+
gross += active * (payerConversion * arppuDaily + adArpDau);
|
|
89
|
+
}
|
|
90
|
+
if (remainder > 0) {
|
|
91
|
+
const active = retentionAtDay(config.retention, fullDays + 1);
|
|
92
|
+
gross += remainder * active * (payerConversion * arppuDaily + adArpDau);
|
|
93
|
+
}
|
|
94
|
+
const net = gross * (1 - config.revenue.platformFeeRate) * config.revenue.grossMarginRate;
|
|
95
|
+
const ltv = net - config.acquisition.cpi;
|
|
96
|
+
return {
|
|
97
|
+
cumulativeGrossRevenuePerUser: gross,
|
|
98
|
+
cumulativeNetRevenuePerUser: net,
|
|
99
|
+
cumulativeLtvPerUser: ltv,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../../src/ltv/projection.ts"],"names":[],"mappings":"AAGA,SAAS,OAAO,CAAC,CAAS;IACxB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACpB,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,QAAoB;IAC3D,MAAM,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC;IAChC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,EAAE,SAAS,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;IACtG,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE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/types";
|
|
2
|
+
import { estimateLtvPerUser as point } from "./projection";
|
|
3
|
+
import { estimateLtvDistribution as distribution } from "./uncertainty";
|
|
4
|
+
import type { MonetizationConfig } from "./types";
|
|
5
|
+
export type { MonetizationConfig, LtvPointEstimate } from "./types";
|
|
6
|
+
export { progressionFactor, retentionAtDay } from "./projection";
|
|
7
|
+
/** Complete a scenario's hypothetical assumptions; this does not fit observed player data. */
|
|
8
|
+
export declare function deriveMonetizationConfig(scenario: ScenarioV1): MonetizationConfig;
|
|
9
|
+
/** Per-install value in one caller-chosen currency, including acquisition cost. */
|
|
10
|
+
export declare function estimateLtvPerUser(args: Parameters<typeof point>[0]): Readonly<{
|
|
11
|
+
cumulativeGrossRevenuePerUser: number;
|
|
12
|
+
cumulativeNetRevenuePerUser: number;
|
|
13
|
+
cumulativeLtvPerUser: number;
|
|
14
|
+
}>;
|
|
15
|
+
/** Seeded assumption sensitivity, not a confidence interval fitted to a player population. */
|
|
16
|
+
export declare function estimateLtvDistribution(args: Parameters<typeof distribution>[0]): Readonly<{
|
|
17
|
+
mean: import("./types").LtvPointEstimate;
|
|
18
|
+
quantiles: Record<string, number>;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { validateScenarioV1 } from "../scenario/validate";
|
|
2
|
+
import { deriveMonetizationConfig as derive, estimateLtvPerUser as point } from "./projection";
|
|
3
|
+
import { estimateLtvDistribution as distribution } from "./uncertainty";
|
|
4
|
+
export { progressionFactor, retentionAtDay } from "./projection";
|
|
5
|
+
function assertMonetization(monetization) {
|
|
6
|
+
const valid = validateScenarioV1({
|
|
7
|
+
schemaVersion: 1, unit: { code: "LTV" }, policy: { mode: "drop" },
|
|
8
|
+
model: { id: "ltv-input", version: 1 },
|
|
9
|
+
initial: { wallet: { unit: "LTV", amount: "0" } },
|
|
10
|
+
clock: { stepSec: 1, durationSec: 1 }, monetization,
|
|
11
|
+
});
|
|
12
|
+
if (!valid.ok)
|
|
13
|
+
throw new RangeError(valid.issues.map((issue) => issue.message).join("; "));
|
|
14
|
+
}
|
|
15
|
+
function assertQuantileValues(quantiles) {
|
|
16
|
+
if (quantiles.length === 0)
|
|
17
|
+
throw new RangeError("quantiles must be nonempty and in 0..1");
|
|
18
|
+
// Iteration visits sparse slots as undefined, unlike Array.every/map.
|
|
19
|
+
for (const q of quantiles) {
|
|
20
|
+
if (!Number.isFinite(q) || q < 0 || q > 1)
|
|
21
|
+
throw new RangeError("quantiles must be nonempty and in 0..1");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function assertConfig(config) {
|
|
25
|
+
const { retention, ...other } = config;
|
|
26
|
+
// Partial scenario retention has historically used independent defaults. Do not
|
|
27
|
+
// impose a new ordering constraint after filling those defaults in the CLI.
|
|
28
|
+
for (const day of ["d1", "d7", "d30", "d90"]) {
|
|
29
|
+
if (!Number.isFinite(retention[day]) || retention[day] < 0 || retention[day] > 1) {
|
|
30
|
+
throw new RangeError(`retention.${day} must be finite and in 0..1`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (!Number.isFinite(retention.longTailDailyDecay) || retention.longTailDailyDecay < 0) {
|
|
34
|
+
throw new RangeError("retention.longTailDailyDecay must be finite and >= 0");
|
|
35
|
+
}
|
|
36
|
+
const { quantiles, ...uncertainty } = other.uncertainty;
|
|
37
|
+
assertQuantileValues(quantiles);
|
|
38
|
+
// The public estimator permits endpoints; ScenarioV1's authored quantile
|
|
39
|
+
// schema is narrower. Output keys come from the explicit distribution args.
|
|
40
|
+
assertMonetization({ ...other, uncertainty });
|
|
41
|
+
}
|
|
42
|
+
/** Complete a scenario's hypothetical assumptions; this does not fit observed player data. */
|
|
43
|
+
export function deriveMonetizationConfig(scenario) {
|
|
44
|
+
assertMonetization(scenario.monetization ?? {});
|
|
45
|
+
const config = derive(scenario);
|
|
46
|
+
assertConfig(config);
|
|
47
|
+
return config;
|
|
48
|
+
}
|
|
49
|
+
function assertPoint(args) {
|
|
50
|
+
assertConfig(args.config);
|
|
51
|
+
if (!Number.isFinite(args.horizonDays) || args.horizonDays < 0 || args.horizonDays > 36500) {
|
|
52
|
+
throw new RangeError("horizonDays must be finite and in 0..36500");
|
|
53
|
+
}
|
|
54
|
+
if (!Number.isFinite(args.progression))
|
|
55
|
+
throw new RangeError("progression must be finite");
|
|
56
|
+
}
|
|
57
|
+
function finiteResult(result) {
|
|
58
|
+
if (!Object.values(result).every((value) => typeof value === "number" && Number.isFinite(value))) {
|
|
59
|
+
throw new RangeError("LTV calculation overflowed; reduce the input magnitudes");
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
/** Per-install value in one caller-chosen currency, including acquisition cost. */
|
|
64
|
+
export function estimateLtvPerUser(args) {
|
|
65
|
+
assertPoint(args);
|
|
66
|
+
return finiteResult(point(args));
|
|
67
|
+
}
|
|
68
|
+
/** Seeded assumption sensitivity, not a confidence interval fitted to a player population. */
|
|
69
|
+
export function estimateLtvDistribution(args) {
|
|
70
|
+
assertPoint(args);
|
|
71
|
+
if (!Number.isSafeInteger(args.draws) || args.draws < 1 || args.draws > 100000
|
|
72
|
+
|| args.draws * Math.max(1, Math.ceil(args.horizonDays)) > 10000000) {
|
|
73
|
+
throw new RangeError("draws must be 1..100000 and draws × ceil(horizonDays) at most 10000000");
|
|
74
|
+
}
|
|
75
|
+
if (!Number.isFinite(args.seed))
|
|
76
|
+
throw new RangeError("seed must be finite");
|
|
77
|
+
if (args.quantiles.length > 101)
|
|
78
|
+
throw new RangeError("quantiles exceed the 101 distinct percent keys");
|
|
79
|
+
assertQuantileValues(args.quantiles);
|
|
80
|
+
if (new Set(args.quantiles.map((q) => Math.round(q * 100))).size !== args.quantiles.length) {
|
|
81
|
+
throw new RangeError("quantiles must be nonempty, in 0..1 and have distinct rounded percent keys");
|
|
82
|
+
}
|
|
83
|
+
const result = distribution(args);
|
|
84
|
+
finiteResult(result.mean);
|
|
85
|
+
finiteResult(result.quantiles);
|
|
86
|
+
return result;
|
|
87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I,CAAC,KAAK,GAAG,MAAM;WACzE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,QAAQ,EAAE,CAAC;QACtE,MAAM,IAAI,UAAU,CAAC,wEAAwE,CAAC,CAAC;IACjG,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,qBAAqB,CAAC,CAAC;IAC7E,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,GAAG;QAAE,MAAM,IAAI,UAAU,CAAC,gDAAgD,CAAC,CAAC;IACxG,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrC,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;QAC3F,MAAM,IAAI,UAAU,CAAC,4EAA4E,CAAC,CAAC;IACrG,CAAC;IACD,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAClC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1B,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC/B,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export type MonetizationConfig = Readonly<{
|
|
2
|
+
cohorts: Readonly<{
|
|
3
|
+
baseUsers: number;
|
|
4
|
+
}>;
|
|
5
|
+
retention: Readonly<{
|
|
6
|
+
d1: number;
|
|
7
|
+
d7: number;
|
|
8
|
+
d30: number;
|
|
9
|
+
d90: number;
|
|
10
|
+
longTailDailyDecay: number;
|
|
11
|
+
}>;
|
|
12
|
+
revenue: Readonly<{
|
|
13
|
+
payerConversion: number;
|
|
14
|
+
arppuDaily: number;
|
|
15
|
+
adArpDau: number;
|
|
16
|
+
platformFeeRate: number;
|
|
17
|
+
grossMarginRate: number;
|
|
18
|
+
progressionRevenueLift: number;
|
|
19
|
+
progressionLogSpan: number;
|
|
20
|
+
}>;
|
|
21
|
+
acquisition: Readonly<{
|
|
22
|
+
cpi: number;
|
|
23
|
+
}>;
|
|
24
|
+
uncertainty: Readonly<{
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
draws: number;
|
|
27
|
+
quantiles: number[];
|
|
28
|
+
seed?: number;
|
|
29
|
+
sigma: Readonly<{
|
|
30
|
+
retention: number;
|
|
31
|
+
conversion: number;
|
|
32
|
+
arppu: number;
|
|
33
|
+
ad: number;
|
|
34
|
+
}>;
|
|
35
|
+
correlation: Readonly<{
|
|
36
|
+
retentionConversion: number;
|
|
37
|
+
retentionArppu: number;
|
|
38
|
+
retentionAd: number;
|
|
39
|
+
conversionArppu: number;
|
|
40
|
+
conversionAd: number;
|
|
41
|
+
arppuAd: number;
|
|
42
|
+
}>;
|
|
43
|
+
}>;
|
|
44
|
+
}>;
|
|
45
|
+
export type LtvPointEstimate = Readonly<{
|
|
46
|
+
cumulativeGrossRevenuePerUser: number;
|
|
47
|
+
cumulativeNetRevenuePerUser: number;
|
|
48
|
+
cumulativeLtvPerUser: number;
|
|
49
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/ltv/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LtvPointEstimate, MonetizationConfig } from "./types";
|
|
2
|
+
import { type Random } from "../sim/random";
|
|
3
|
+
export declare function makeUncertainConfig(base: MonetizationConfig, rng: Random): MonetizationConfig;
|
|
4
|
+
export declare function quantile(values: number[], q: number): number;
|
|
5
|
+
export declare function estimateLtvDistribution(args: {
|
|
6
|
+
config: MonetizationConfig;
|
|
7
|
+
horizonDays: number;
|
|
8
|
+
progression: number;
|
|
9
|
+
draws: number;
|
|
10
|
+
quantiles: number[];
|
|
11
|
+
seed: number;
|
|
12
|
+
}): Readonly<{
|
|
13
|
+
mean: LtvPointEstimate;
|
|
14
|
+
quantiles: Record<string, number>;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { estimateLtvPerUser } from "./projection";
|
|
2
|
+
function clamp01(v) {
|
|
3
|
+
if (v < 0)
|
|
4
|
+
return 0;
|
|
5
|
+
if (v > 1)
|
|
6
|
+
return 1;
|
|
7
|
+
return v;
|
|
8
|
+
}
|
|
9
|
+
function clampCorrelation(v) {
|
|
10
|
+
if (!Number.isFinite(v))
|
|
11
|
+
return 0;
|
|
12
|
+
if (v < -1)
|
|
13
|
+
return -1;
|
|
14
|
+
if (v > 1)
|
|
15
|
+
return 1;
|
|
16
|
+
return v;
|
|
17
|
+
}
|
|
18
|
+
import { mulberry32 } from "../sim/random";
|
|
19
|
+
function randNormal(rng) {
|
|
20
|
+
const u1 = Math.max(1e-12, rng());
|
|
21
|
+
const u2 = Math.max(1e-12, rng());
|
|
22
|
+
return Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
|
|
23
|
+
}
|
|
24
|
+
function buildCorrelationMatrix(base) {
|
|
25
|
+
const rc = clampCorrelation(base.retentionConversion);
|
|
26
|
+
const ra = clampCorrelation(base.retentionArppu);
|
|
27
|
+
const rd = clampCorrelation(base.retentionAd);
|
|
28
|
+
const ca = clampCorrelation(base.conversionArppu);
|
|
29
|
+
const cd = clampCorrelation(base.conversionAd);
|
|
30
|
+
const ad = clampCorrelation(base.arppuAd);
|
|
31
|
+
return [
|
|
32
|
+
[1, rc, ra, rd],
|
|
33
|
+
[rc, 1, ca, cd],
|
|
34
|
+
[ra, ca, 1, ad],
|
|
35
|
+
[rd, cd, ad, 1],
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
function withOffDiagonalScale(matrix, alpha) {
|
|
39
|
+
return matrix.map((row, i) => row.map((v, j) => {
|
|
40
|
+
if (i === j)
|
|
41
|
+
return 1;
|
|
42
|
+
return v * alpha;
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
function cholesky4(matrix) {
|
|
46
|
+
const n = 4;
|
|
47
|
+
const l = Array.from({ length: n }, () => Array.from({ length: n }, () => 0));
|
|
48
|
+
for (let i = 0; i < n; i++) {
|
|
49
|
+
for (let j = 0; j <= i; j++) {
|
|
50
|
+
let sum = 0;
|
|
51
|
+
for (let k = 0; k < j; k++) {
|
|
52
|
+
sum += (l[i]?.[k] ?? 0) * (l[j]?.[k] ?? 0);
|
|
53
|
+
}
|
|
54
|
+
if (i === j) {
|
|
55
|
+
const val = (matrix[i]?.[i] ?? 0) - sum;
|
|
56
|
+
if (val <= 1e-9)
|
|
57
|
+
return null;
|
|
58
|
+
l[i][j] = Math.sqrt(val);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const denom = l[j]?.[j] ?? 0;
|
|
62
|
+
if (Math.abs(denom) < 1e-9)
|
|
63
|
+
return null;
|
|
64
|
+
l[i][j] = ((matrix[i]?.[j] ?? 0) - sum) / denom;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return l;
|
|
69
|
+
}
|
|
70
|
+
function multiplyLowerTriangular(l, z) {
|
|
71
|
+
const out = [0, 0, 0, 0];
|
|
72
|
+
for (let i = 0; i < 4; i++) {
|
|
73
|
+
let sum = 0;
|
|
74
|
+
for (let j = 0; j <= i; j++) {
|
|
75
|
+
sum += (l[i]?.[j] ?? 0) * (z[j] ?? 0);
|
|
76
|
+
}
|
|
77
|
+
out[i] = sum;
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
function sampleCorrelatedNormals(rng, corr) {
|
|
82
|
+
const z = [randNormal(rng), randNormal(rng), randNormal(rng), randNormal(rng)];
|
|
83
|
+
const matrix = buildCorrelationMatrix(corr);
|
|
84
|
+
let l = cholesky4(matrix);
|
|
85
|
+
// If the provided correlation tuple is not positive-definite, keep shrinking
|
|
86
|
+
// off-diagonal terms toward 0 until Cholesky succeeds.
|
|
87
|
+
let alpha = 0.99;
|
|
88
|
+
while (!l && alpha > 1e-6) {
|
|
89
|
+
l = cholesky4(withOffDiagonalScale(matrix, alpha));
|
|
90
|
+
alpha *= 0.8;
|
|
91
|
+
}
|
|
92
|
+
if (!l) {
|
|
93
|
+
return {
|
|
94
|
+
retention: z[0] ?? 0,
|
|
95
|
+
conversion: z[1] ?? 0,
|
|
96
|
+
arppu: z[2] ?? 0,
|
|
97
|
+
ad: z[3] ?? 0,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const c = multiplyLowerTriangular(l, z);
|
|
101
|
+
return {
|
|
102
|
+
retention: c[0] ?? 0,
|
|
103
|
+
conversion: c[1] ?? 0,
|
|
104
|
+
arppu: c[2] ?? 0,
|
|
105
|
+
ad: c[3] ?? 0,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function applyLogNormalShock(mean, sigma, z) {
|
|
109
|
+
if (sigma <= 0)
|
|
110
|
+
return mean;
|
|
111
|
+
return mean * Math.exp(sigma * z - 0.5 * sigma * sigma);
|
|
112
|
+
}
|
|
113
|
+
export function makeUncertainConfig(base, rng) {
|
|
114
|
+
const shock = sampleCorrelatedNormals(rng, base.uncertainty.correlation);
|
|
115
|
+
const d1 = clamp01(applyLogNormalShock(base.retention.d1, base.uncertainty.sigma.retention, shock.retention));
|
|
116
|
+
const d7 = Math.min(d1, clamp01(applyLogNormalShock(base.retention.d7, base.uncertainty.sigma.retention, shock.retention)));
|
|
117
|
+
const d30 = Math.min(d7, clamp01(applyLogNormalShock(base.retention.d30, base.uncertainty.sigma.retention, shock.retention)));
|
|
118
|
+
const d90 = Math.min(d30, clamp01(applyLogNormalShock(base.retention.d90, base.uncertainty.sigma.retention, shock.retention)));
|
|
119
|
+
return {
|
|
120
|
+
...base,
|
|
121
|
+
retention: {
|
|
122
|
+
...base.retention,
|
|
123
|
+
d1,
|
|
124
|
+
d7,
|
|
125
|
+
d30,
|
|
126
|
+
d90,
|
|
127
|
+
},
|
|
128
|
+
revenue: {
|
|
129
|
+
...base.revenue,
|
|
130
|
+
payerConversion: clamp01(applyLogNormalShock(base.revenue.payerConversion, base.uncertainty.sigma.conversion, shock.conversion)),
|
|
131
|
+
arppuDaily: Math.max(0, applyLogNormalShock(base.revenue.arppuDaily, base.uncertainty.sigma.arppu, shock.arppu)),
|
|
132
|
+
adArpDau: Math.max(0, applyLogNormalShock(base.revenue.adArpDau, base.uncertainty.sigma.ad, shock.ad)),
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export function quantile(values, q) {
|
|
137
|
+
return quantileFromSorted([...values].sort((a, b) => a - b), q);
|
|
138
|
+
}
|
|
139
|
+
function quantileFromSorted(sorted, q) {
|
|
140
|
+
if (sorted.length === 0)
|
|
141
|
+
return 0;
|
|
142
|
+
const idx = Math.max(0, Math.min(sorted.length - 1, Math.floor((sorted.length - 1) * q)));
|
|
143
|
+
return sorted[idx] ?? 0;
|
|
144
|
+
}
|
|
145
|
+
export function estimateLtvDistribution(args) {
|
|
146
|
+
const rng = mulberry32(args.seed);
|
|
147
|
+
const grossSamples = [];
|
|
148
|
+
const netSamples = [];
|
|
149
|
+
const ltvSamples = [];
|
|
150
|
+
const draws = Math.max(1, args.draws);
|
|
151
|
+
for (let i = 0; i < draws; i++) {
|
|
152
|
+
const sampled = makeUncertainConfig(args.config, rng);
|
|
153
|
+
const point = estimateLtvPerUser({
|
|
154
|
+
config: sampled,
|
|
155
|
+
horizonDays: args.horizonDays,
|
|
156
|
+
progression: args.progression,
|
|
157
|
+
});
|
|
158
|
+
grossSamples.push(point.cumulativeGrossRevenuePerUser);
|
|
159
|
+
netSamples.push(point.cumulativeNetRevenuePerUser);
|
|
160
|
+
ltvSamples.push(point.cumulativeLtvPerUser);
|
|
161
|
+
}
|
|
162
|
+
const avg = (arr) => arr.reduce((a, b) => a + b, 0) / Math.max(1, arr.length);
|
|
163
|
+
// Keep the original sample order for the mean's floating-point sum.
|
|
164
|
+
const sortedLtv = [...ltvSamples].sort((a, b) => a - b);
|
|
165
|
+
const byQuantile = {};
|
|
166
|
+
for (const q of args.quantiles) {
|
|
167
|
+
byQuantile[`q${Math.round(q * 100)}`] = quantileFromSorted(sortedLtv, q);
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
mean: {
|
|
171
|
+
cumulativeGrossRevenuePerUser: avg(grossSamples),
|
|
172
|
+
cumulativeNetRevenuePerUser: avg(netSamples),
|
|
173
|
+
cumulativeLtvPerUser: avg(ltvSamples),
|
|
174
|
+
},
|
|
175
|
+
quantiles: byQuantile,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=uncertainty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uncertainty.js","sourceRoot":"","sources":["../../src/ltv/uncertainty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD,SAAS,OAAO,CAAC,CAAS;IACxB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACpB,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,gBAAgB,CAAC,CAAS;IACjC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;IAClC,IAAI,CAAC,GAAG,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC;IACtB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACpB,OAAO,CAAC,CAAC;AACX,CAAC;AAED,OAAO,EAAE,UAAU,EAAe,MAAM,eAAe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C,GAAG,GAAG,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO;QACL,IAAI,EAAE;YACJ,6BAA6B,EAAE,GAAG,CAAC,YAAY,CAAC;YAChD,2BAA2B,EAAE,GAAG,CAAC,UAAU,CAAC;YAC5C,oBAAoB,EAAE,GAAG,CAAC,UAAU,CAAC;SACtC;QACD,SAAS,EAAE,UAAU;KACtB,CAAC;AACJ,CAAC"}
|
|
@@ -19,11 +19,11 @@ declare const CONTRACT_GENERATOR: "idlekit.contract-generator";
|
|
|
19
19
|
declare const CONTRACT_GENERATOR_VERSION: 1;
|
|
20
20
|
declare const JSON_SCHEMA_EXPORT: "typia.json.schema";
|
|
21
21
|
declare const JSON_SCHEMA_DIALECT: "openapi-3.1";
|
|
22
|
-
declare const TYPIA_VERSION: "
|
|
22
|
+
declare const TYPIA_VERSION: "15.1.0";
|
|
23
23
|
declare const SCENARIO_SCHEMA_ID: "https://idlekit.dev/schemas/scenario.v1.schema.json";
|
|
24
24
|
/**
|
|
25
25
|
* @evidence docs/requirements/active/typed-contract-generation.md#req-tc05-typed-contract-single-source ScenarioV1 is the generated structural contract. The registry starts with that id.
|
|
26
|
-
* @evidenceReview docs/requirements/active/typed-contract-generation.md#req-tc05-typed-contract-single-source #
|
|
26
|
+
* @evidenceReview docs/requirements/active/typed-contract-generation.md#req-tc05-typed-contract-single-source #041479e Re-read the section against typia 15.1.0: the id is idlekit.scenario.v1 and the export is typia.json.schema 3.1. Regenerated contracts preserve their structural schemas.
|
|
27
27
|
*/
|
|
28
28
|
export declare const typedContractSingleSource: "idlekit.scenario.v1";
|
|
29
29
|
/**
|
|
@@ -21,11 +21,11 @@ const CONTRACT_GENERATOR = "idlekit.contract-generator";
|
|
|
21
21
|
const CONTRACT_GENERATOR_VERSION = 1;
|
|
22
22
|
const JSON_SCHEMA_EXPORT = "typia.json.schema";
|
|
23
23
|
const JSON_SCHEMA_DIALECT = "openapi-3.1";
|
|
24
|
-
const TYPIA_VERSION = "
|
|
24
|
+
const TYPIA_VERSION = "15.1.0";
|
|
25
25
|
const SCENARIO_SCHEMA_ID = "https://idlekit.dev/schemas/scenario.v1.schema.json";
|
|
26
26
|
/**
|
|
27
27
|
* @evidence docs/requirements/active/typed-contract-generation.md#req-tc05-typed-contract-single-source ScenarioV1 is the generated structural contract. The registry starts with that id.
|
|
28
|
-
* @evidenceReview docs/requirements/active/typed-contract-generation.md#req-tc05-typed-contract-single-source #
|
|
28
|
+
* @evidenceReview docs/requirements/active/typed-contract-generation.md#req-tc05-typed-contract-single-source #041479e Re-read the section against typia 15.1.0: the id is idlekit.scenario.v1 and the export is typia.json.schema 3.1. Regenerated contracts preserve their structural schemas.
|
|
29
29
|
*/
|
|
30
30
|
export const typedContractSingleSource = "idlekit.scenario.v1";
|
|
31
31
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idlekit/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Bun-first scenario compilation, simulation, analysis, and reporting for idle game economies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"postpack": "cd ../.. && bun tools/package-manifest.ts restore packages/core"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@idlekit/money": "0.3.
|
|
57
|
-
"typia": "
|
|
56
|
+
"@idlekit/money": "0.3.2",
|
|
57
|
+
"typia": "15.1.0",
|
|
58
58
|
"zod": "^4.6.5"
|
|
59
59
|
}
|
|
60
60
|
}
|