@gbozee/ultimate 0.0.2-next.4 → 0.0.2-next.41
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/dist/frontend-index.d.ts +3 -2
- package/dist/frontend-index.js +47 -14
- package/dist/index.cjs +18207 -5659
- package/dist/index.d.ts +4377 -25
- package/dist/index.js +18519 -5971
- package/dist/mcp-server.cjs +1972 -114
- package/dist/mcp-server.js +1972 -114
- package/package.json +15 -12
package/dist/frontend-index.d.ts
CHANGED
|
@@ -120,7 +120,7 @@ export declare function determineTPSl(payload: {
|
|
|
120
120
|
};
|
|
121
121
|
export interface GetEntriesParams {
|
|
122
122
|
kind: "long" | "short";
|
|
123
|
-
distribution: "arithmetic" | "geometric" | "normal" | "exponential" | "inverse-exponential";
|
|
123
|
+
distribution: "arithmetic" | "geometric" | "normal" | "exponential" | "lognormal" | "inverse-exponential";
|
|
124
124
|
margin_range: [
|
|
125
125
|
number,
|
|
126
126
|
number
|
|
@@ -1494,7 +1494,8 @@ declare function constructAppConfig$1({ config, global_config, }: {
|
|
|
1494
1494
|
lambda?: number;
|
|
1495
1495
|
};
|
|
1496
1496
|
};
|
|
1497
|
-
declare function buildWithOptimumReward({ config, settings, global_config, force_exact, }: {
|
|
1497
|
+
declare function buildWithOptimumReward({ config, settings, global_config, force_exact, use_default, }: {
|
|
1498
|
+
use_default?: boolean;
|
|
1498
1499
|
config: TradeConfig;
|
|
1499
1500
|
global_config: GlobalConfig;
|
|
1500
1501
|
settings: {
|
package/dist/frontend-index.js
CHANGED
|
@@ -91,8 +91,7 @@ function getEntries(params) {
|
|
|
91
91
|
margin_range,
|
|
92
92
|
risk_reward,
|
|
93
93
|
kind,
|
|
94
|
-
price_places
|
|
95
|
-
percent_change: distribution_params?.curveFactor
|
|
94
|
+
price_places
|
|
96
95
|
});
|
|
97
96
|
break;
|
|
98
97
|
case "normal":
|
|
@@ -122,12 +121,37 @@ function getEntries(params) {
|
|
|
122
121
|
curveFactor: distribution_params?.curveFactor
|
|
123
122
|
});
|
|
124
123
|
break;
|
|
124
|
+
case "lognormal":
|
|
125
|
+
entries = generateLognormal({
|
|
126
|
+
margin_range,
|
|
127
|
+
risk_reward,
|
|
128
|
+
kind,
|
|
129
|
+
price_places,
|
|
130
|
+
stdDevFactor: distribution_params?.stdDevFactor
|
|
131
|
+
});
|
|
132
|
+
break;
|
|
125
133
|
default:
|
|
126
134
|
throw new Error(`Unknown distribution type: ${distribution}`);
|
|
127
135
|
}
|
|
128
136
|
return entries.sort((a, b) => a - b);
|
|
129
137
|
}
|
|
130
138
|
var distributions_default = getEntries;
|
|
139
|
+
function generateLognormal(payload) {
|
|
140
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f", stdDevFactor = 6 } = payload;
|
|
141
|
+
const logMin = Math.log(margin_range[0]);
|
|
142
|
+
const logMax = Math.log(margin_range[1]);
|
|
143
|
+
const mean = (logMin + logMax) / 2;
|
|
144
|
+
const stdDev = Math.abs(logMax - logMin) / stdDevFactor;
|
|
145
|
+
const entries = Array.from({ length: risk_reward + 1 }, (_, i) => {
|
|
146
|
+
const p = (i + 0.5) / (risk_reward + 1);
|
|
147
|
+
const z = approximateInverseNormal(p);
|
|
148
|
+
let logPrice = mean + stdDev * z;
|
|
149
|
+
logPrice = Math.max(logMin, Math.min(logMax, logPrice));
|
|
150
|
+
const price = Math.exp(logPrice);
|
|
151
|
+
return to_f(kind === "long" ? Math.min(price, margin_range[1]) : Math.max(price, margin_range[0]), price_places);
|
|
152
|
+
});
|
|
153
|
+
return entries.sort((a, b) => a - b);
|
|
154
|
+
}
|
|
131
155
|
|
|
132
156
|
// src/helpers/optimizations.ts
|
|
133
157
|
function calculateTheoreticalKelly({
|
|
@@ -501,7 +525,7 @@ class Signal {
|
|
|
501
525
|
const simple_support = Math.min(current_price, stop_loss);
|
|
502
526
|
const simple_resistance = Math.max(current_price, stop_loss);
|
|
503
527
|
const risk_per_trade = risk / this.risk_reward;
|
|
504
|
-
const use_progressive = distribution_params
|
|
528
|
+
const use_progressive = distribution_params?.use_progressive || this.use_progressive_risk;
|
|
505
529
|
const risk_distribution = use_progressive ? {
|
|
506
530
|
enabled: true,
|
|
507
531
|
total_risk_budget: risk,
|
|
@@ -970,7 +994,6 @@ class Signal {
|
|
|
970
994
|
const defaultStopLoss = i === 0 ? stop_loss : _base;
|
|
971
995
|
const new_stop = kind === "long" ? this.support : stop_loss;
|
|
972
996
|
let risk_to_use = this.getZoneRisk(i, limit_orders.length, this);
|
|
973
|
-
console.log("index: ", i, " risk: ", risk_to_use);
|
|
974
997
|
if (this.use_kelly) {
|
|
975
998
|
const func = this.kelly_func === "theoretical" ? calculateTheoreticalKelly : this.kelly_func === "position_based" ? calculatePositionBasedKelly : calculateTheoreticalKellyFixed;
|
|
976
999
|
const theoretical_kelly = func({
|
|
@@ -1297,6 +1320,9 @@ function formatPrice(value2, opts = {}) {
|
|
|
1297
1320
|
return formatter.format(value2);
|
|
1298
1321
|
}
|
|
1299
1322
|
function to_f(value2, places = "%.1f") {
|
|
1323
|
+
if (!value2) {
|
|
1324
|
+
return null;
|
|
1325
|
+
}
|
|
1300
1326
|
let v = typeof value2 === "string" ? parseFloat(value2) : value2;
|
|
1301
1327
|
const formattedValue = places.replace("%.", "").replace("f", "");
|
|
1302
1328
|
return parseFloat(v.toFixed(parseInt(formattedValue)));
|
|
@@ -1655,7 +1681,7 @@ function buildConfig(app_config, {
|
|
|
1655
1681
|
min_avg_size = 0,
|
|
1656
1682
|
distribution,
|
|
1657
1683
|
distribution_params,
|
|
1658
|
-
use_progressive_risk
|
|
1684
|
+
use_progressive_risk = false
|
|
1659
1685
|
}) {
|
|
1660
1686
|
let fee = app_config.fee / 100;
|
|
1661
1687
|
let working_risk = risk || app_config.risk_per_trade;
|
|
@@ -1697,7 +1723,7 @@ function buildConfig(app_config, {
|
|
|
1697
1723
|
if (!stop) {
|
|
1698
1724
|
return [];
|
|
1699
1725
|
}
|
|
1700
|
-
const condition =
|
|
1726
|
+
const condition = true;
|
|
1701
1727
|
if (kind === "short") {}
|
|
1702
1728
|
const result = entry === stop ? [] : condition ? instance.build_entry({
|
|
1703
1729
|
current_price: entry,
|
|
@@ -2180,7 +2206,7 @@ function determineOptimumReward(payload) {
|
|
|
2180
2206
|
const criterion = app_config.strategy || "quantity";
|
|
2181
2207
|
const risk_rewards = createArray(low_range, high_range, 1);
|
|
2182
2208
|
let func = risk_rewards.map((trade_no) => {
|
|
2183
|
-
|
|
2209
|
+
const pp = {
|
|
2184
2210
|
take_profit: app_config.take_profit,
|
|
2185
2211
|
entry: app_config.entry,
|
|
2186
2212
|
stop: app_config.stop,
|
|
@@ -2192,7 +2218,8 @@ function determineOptimumReward(payload) {
|
|
|
2192
2218
|
decimal_places: app_config.decimal_places,
|
|
2193
2219
|
distribution,
|
|
2194
2220
|
distribution_params: payload.distribution_params
|
|
2195
|
-
}
|
|
2221
|
+
};
|
|
2222
|
+
let trades = sortedBuildConfig(app_config, pp);
|
|
2196
2223
|
let total = 0;
|
|
2197
2224
|
let max = -Infinity;
|
|
2198
2225
|
let min = Infinity;
|
|
@@ -2283,7 +2310,6 @@ function findIndexByCondition(lst, kind, condition, defaultKey = "neg_pnl") {
|
|
|
2283
2310
|
return b.net_diff - a.net_diff;
|
|
2284
2311
|
}
|
|
2285
2312
|
});
|
|
2286
|
-
console.log("found", sortedFound);
|
|
2287
2313
|
if (defaultKey === "quantity") {
|
|
2288
2314
|
return sortedFound[0].index;
|
|
2289
2315
|
}
|
|
@@ -3488,10 +3514,14 @@ function helperFuncToBuildTrades({
|
|
|
3488
3514
|
symbol_config,
|
|
3489
3515
|
app_config_kind,
|
|
3490
3516
|
appConfig,
|
|
3491
|
-
force_exact_risk = true
|
|
3517
|
+
force_exact_risk = true,
|
|
3518
|
+
use_default = false
|
|
3492
3519
|
}) {
|
|
3493
3520
|
const risk = custom_b_config.risk * (custom_b_config.risk_factor || 1);
|
|
3494
|
-
let result =
|
|
3521
|
+
let result = use_default ? {
|
|
3522
|
+
risk,
|
|
3523
|
+
risk_reward: custom_b_config.risk_reward
|
|
3524
|
+
} : getRiskReward({
|
|
3495
3525
|
entry: custom_b_config.entry,
|
|
3496
3526
|
stop: custom_b_config.stop,
|
|
3497
3527
|
risk,
|
|
@@ -3540,7 +3570,8 @@ function buildWithOptimumReward({
|
|
|
3540
3570
|
config,
|
|
3541
3571
|
settings,
|
|
3542
3572
|
global_config,
|
|
3543
|
-
force_exact
|
|
3573
|
+
force_exact,
|
|
3574
|
+
use_default = false
|
|
3544
3575
|
}) {
|
|
3545
3576
|
const kind = config.entry > config.stop ? "long" : "short";
|
|
3546
3577
|
let stop = settings.stop;
|
|
@@ -3554,7 +3585,8 @@ function buildWithOptimumReward({
|
|
|
3554
3585
|
stop,
|
|
3555
3586
|
risk,
|
|
3556
3587
|
distribution,
|
|
3557
|
-
distribution_params
|
|
3588
|
+
distribution_params,
|
|
3589
|
+
risk_reward: settings.risk_reward || config?.risk_reward
|
|
3558
3590
|
};
|
|
3559
3591
|
const appConfig = constructAppConfig2({
|
|
3560
3592
|
config,
|
|
@@ -3565,7 +3597,8 @@ function buildWithOptimumReward({
|
|
|
3565
3597
|
app_config_kind: kind,
|
|
3566
3598
|
appConfig,
|
|
3567
3599
|
symbol_config: global_config,
|
|
3568
|
-
force_exact_risk: force_exact
|
|
3600
|
+
force_exact_risk: force_exact,
|
|
3601
|
+
use_default
|
|
3569
3602
|
});
|
|
3570
3603
|
const adjusted_size = summary.quantity;
|
|
3571
3604
|
const symbol_config = global_config;
|