@gbozee/ultimate 0.0.2-next.0 → 0.0.2-next.14
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 +41 -2
- package/dist/frontend-index.js +56 -10
- package/dist/index.cjs +1878 -6049
- package/dist/index.d.ts +53 -9
- package/dist/index.js +1875 -6046
- package/dist/mcp-client.cjs +6802 -479
- package/dist/mcp-client.js +6811 -479
- package/dist/mcp-server.cjs +19429 -17195
- package/dist/mcp-server.js +19426 -17192
- package/package.json +11 -3
package/dist/frontend-index.d.ts
CHANGED
|
@@ -170,6 +170,16 @@ export type SignalConfigType = {
|
|
|
170
170
|
stdDevFactor?: number;
|
|
171
171
|
lambda?: number;
|
|
172
172
|
};
|
|
173
|
+
use_progressive_risk?: boolean;
|
|
174
|
+
risk_distribution?: {
|
|
175
|
+
enabled: boolean;
|
|
176
|
+
total_risk_budget: number;
|
|
177
|
+
risk_reward: number;
|
|
178
|
+
buckets: Array<{
|
|
179
|
+
zone_percentage: number;
|
|
180
|
+
risk_percentage: number;
|
|
181
|
+
}>;
|
|
182
|
+
};
|
|
173
183
|
};
|
|
174
184
|
declare class Signal {
|
|
175
185
|
focus: number;
|
|
@@ -207,8 +217,18 @@ declare class Signal {
|
|
|
207
217
|
long: GetEntriesParams["distribution"];
|
|
208
218
|
short: GetEntriesParams["distribution"];
|
|
209
219
|
};
|
|
220
|
+
use_progressive_risk?: boolean;
|
|
221
|
+
risk_distribution?: {
|
|
222
|
+
enabled: boolean;
|
|
223
|
+
total_risk_budget: number;
|
|
224
|
+
risk_reward: number;
|
|
225
|
+
buckets: Array<{
|
|
226
|
+
zone_percentage: number;
|
|
227
|
+
risk_percentage: number;
|
|
228
|
+
}>;
|
|
229
|
+
};
|
|
210
230
|
max_quantity: number;
|
|
211
|
-
constructor({ focus, symbol, budget, percent_change, price_places, decimal_places, zone_risk, fee, support, risk_reward, resistance, risk_per_trade, increase_size, additional_increase, minimum_pnl, take_profit, increase_position, minimum_size, first_order_size, gap, max_size, use_kelly, kelly_prediction_model, kelly_confidence_factor, kelly_minimum_risk, kelly_func, full_distribution, max_quantity, distribution_params, }: SignalConfigType);
|
|
231
|
+
constructor({ focus, symbol, budget, percent_change, price_places, decimal_places, zone_risk, fee, support, risk_reward, resistance, risk_per_trade, increase_size, additional_increase, minimum_pnl, take_profit, increase_position, minimum_size, first_order_size, gap, max_size, use_kelly, kelly_prediction_model, kelly_confidence_factor, kelly_minimum_risk, kelly_func, full_distribution, max_quantity, distribution_params, use_progressive_risk, risk_distribution, }: SignalConfigType);
|
|
212
232
|
build_entry({ current_price, stop_loss, pnl, stop_percent, kind, risk, no_of_trades, take_profit, distribution, distribution_params, }: {
|
|
213
233
|
take_profit?: number;
|
|
214
234
|
no_of_trades?: number;
|
|
@@ -223,6 +243,11 @@ declare class Signal {
|
|
|
223
243
|
curveFactor?: number;
|
|
224
244
|
stdDevFactor?: number;
|
|
225
245
|
lambda?: number;
|
|
246
|
+
use_progressive?: boolean;
|
|
247
|
+
buckets?: Array<{
|
|
248
|
+
zone_percentage: number;
|
|
249
|
+
risk_percentage: number;
|
|
250
|
+
}>;
|
|
226
251
|
};
|
|
227
252
|
}): any;
|
|
228
253
|
get risk(): number;
|
|
@@ -273,6 +298,14 @@ declare class Signal {
|
|
|
273
298
|
kind?: "long" | "short";
|
|
274
299
|
}): number[][];
|
|
275
300
|
get_margin_range(current_price: number, kind?: string): number[];
|
|
301
|
+
/**
|
|
302
|
+
* Helper function to calculate zone-specific risk based on progressive risk distribution
|
|
303
|
+
* @param index - The index of the current zone
|
|
304
|
+
* @param totalZones - Total number of zones
|
|
305
|
+
* @param account - Account configuration with risk settings
|
|
306
|
+
* @returns The risk amount for the specific zone
|
|
307
|
+
*/
|
|
308
|
+
private getZoneRisk;
|
|
276
309
|
process_orders({ current_price, stop_loss, trade_zones, kind, }: {
|
|
277
310
|
current_price: number;
|
|
278
311
|
stop_loss: number;
|
|
@@ -572,9 +605,15 @@ export type ExtendConfigType = {
|
|
|
572
605
|
curveFactor?: number;
|
|
573
606
|
stdDevFactor?: number;
|
|
574
607
|
lambda?: number;
|
|
608
|
+
buckets?: Array<{
|
|
609
|
+
zone_percentage: number;
|
|
610
|
+
risk_percentage: number;
|
|
611
|
+
}>;
|
|
612
|
+
use_progressive?: boolean;
|
|
575
613
|
};
|
|
614
|
+
use_progressive_risk?: boolean;
|
|
576
615
|
};
|
|
577
|
-
export declare function buildConfig(app_config: AppConfig, { take_profit, entry, stop, raw_instance, risk, no_of_trades, min_profit, risk_reward, kind, increase, gap, rr, price_places, decimal_places, use_kelly, kelly_confidence_factor, kelly_minimum_risk, kelly_prediction_model, kelly_func, min_avg_size, distribution, distribution_params, }: ExtendConfigType): any[] | Signal;
|
|
616
|
+
export declare function buildConfig(app_config: AppConfig, { take_profit, entry, stop, raw_instance, risk, no_of_trades, min_profit, risk_reward, kind, increase, gap, rr, price_places, decimal_places, use_kelly, kelly_confidence_factor, kelly_minimum_risk, kelly_prediction_model, kelly_func, min_avg_size, distribution, distribution_params, use_progressive_risk, }: ExtendConfigType): any[] | Signal;
|
|
578
617
|
export declare function buildAvg({ _trades, kind, }: {
|
|
579
618
|
_trades: any[];
|
|
580
619
|
kind: "long" | "short";
|
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":
|
|
@@ -403,6 +402,8 @@ class Signal {
|
|
|
403
402
|
long: "arithmetic",
|
|
404
403
|
short: "geometric"
|
|
405
404
|
};
|
|
405
|
+
use_progressive_risk;
|
|
406
|
+
risk_distribution;
|
|
406
407
|
max_quantity = 0.03;
|
|
407
408
|
constructor({
|
|
408
409
|
focus,
|
|
@@ -433,12 +434,16 @@ class Signal {
|
|
|
433
434
|
kelly_func = "theoretical",
|
|
434
435
|
full_distribution,
|
|
435
436
|
max_quantity = 0.03,
|
|
436
|
-
distribution_params = {}
|
|
437
|
+
distribution_params = {},
|
|
438
|
+
use_progressive_risk,
|
|
439
|
+
risk_distribution
|
|
437
440
|
}) {
|
|
438
441
|
if (full_distribution) {
|
|
439
442
|
this.distribution = full_distribution;
|
|
440
443
|
}
|
|
441
444
|
this.distribution_params = distribution_params;
|
|
445
|
+
this.use_progressive_risk = use_progressive_risk;
|
|
446
|
+
this.risk_distribution = risk_distribution;
|
|
442
447
|
this.symbol = symbol;
|
|
443
448
|
this.minimum_size = minimum_size;
|
|
444
449
|
this.first_order_size = first_order_size;
|
|
@@ -477,7 +482,13 @@ class Signal {
|
|
|
477
482
|
no_of_trades = 1,
|
|
478
483
|
take_profit,
|
|
479
484
|
distribution,
|
|
480
|
-
distribution_params = {
|
|
485
|
+
distribution_params = {
|
|
486
|
+
buckets: [
|
|
487
|
+
{ zone_percentage: 0.25, risk_percentage: 0.1 },
|
|
488
|
+
{ zone_percentage: 0.5, risk_percentage: 0.4 },
|
|
489
|
+
{ zone_percentage: 0.25, risk_percentage: 0.5 }
|
|
490
|
+
]
|
|
491
|
+
}
|
|
481
492
|
}) {
|
|
482
493
|
let _stop_loss = stop_loss;
|
|
483
494
|
if (!_stop_loss && stop_percent) {
|
|
@@ -488,12 +499,20 @@ class Signal {
|
|
|
488
499
|
let _resistance = current_price * Math.pow(1 + percent_change, 1);
|
|
489
500
|
const simple_support = Math.min(current_price, stop_loss);
|
|
490
501
|
const simple_resistance = Math.max(current_price, stop_loss);
|
|
502
|
+
const risk_per_trade = risk / this.risk_reward;
|
|
503
|
+
const use_progressive = distribution_params?.use_progressive || this.use_progressive_risk;
|
|
504
|
+
const risk_distribution = use_progressive ? {
|
|
505
|
+
enabled: true,
|
|
506
|
+
total_risk_budget: risk,
|
|
507
|
+
risk_reward: this.risk_reward,
|
|
508
|
+
buckets: distribution_params.buckets || []
|
|
509
|
+
} : undefined;
|
|
491
510
|
const derivedConfig = {
|
|
492
511
|
...this,
|
|
493
512
|
percent_change,
|
|
494
513
|
focus: current_price,
|
|
495
514
|
resistance: distribution ? simple_resistance : _resistance,
|
|
496
|
-
risk_per_trade
|
|
515
|
+
risk_per_trade,
|
|
497
516
|
minimum_pnl: pnl,
|
|
498
517
|
risk_reward: _no_of_trades,
|
|
499
518
|
take_profit: take_profit || this.take_profit,
|
|
@@ -502,7 +521,9 @@ class Signal {
|
|
|
502
521
|
...this.distribution,
|
|
503
522
|
[kind]: distribution
|
|
504
523
|
} : undefined,
|
|
505
|
-
|
|
524
|
+
use_progressive_risk: use_progressive,
|
|
525
|
+
distribution_params,
|
|
526
|
+
risk_distribution
|
|
506
527
|
};
|
|
507
528
|
const instance = new Signal(derivedConfig);
|
|
508
529
|
if (kind === "short") {}
|
|
@@ -867,6 +888,24 @@ class Signal {
|
|
|
867
888
|
}
|
|
868
889
|
return null;
|
|
869
890
|
}
|
|
891
|
+
getZoneRisk(index, totalZones, account) {
|
|
892
|
+
if (!account.risk_distribution?.enabled) {
|
|
893
|
+
return account.risk_per_trade;
|
|
894
|
+
}
|
|
895
|
+
const { buckets, total_risk_budget } = account.risk_distribution;
|
|
896
|
+
const reversedBuckets = [...buckets].reverse();
|
|
897
|
+
let zoneStart = 0;
|
|
898
|
+
for (const bucket of reversedBuckets) {
|
|
899
|
+
const zoneEnd = zoneStart + Math.floor(totalZones * bucket.zone_percentage);
|
|
900
|
+
if (index < zoneEnd) {
|
|
901
|
+
const zonesInBucket = zoneEnd - zoneStart;
|
|
902
|
+
const bucket_total = total_risk_budget * bucket.risk_percentage;
|
|
903
|
+
return bucket_total / zonesInBucket;
|
|
904
|
+
}
|
|
905
|
+
zoneStart = zoneEnd;
|
|
906
|
+
}
|
|
907
|
+
return account.risk_per_trade;
|
|
908
|
+
}
|
|
870
909
|
process_orders({
|
|
871
910
|
current_price,
|
|
872
911
|
stop_loss,
|
|
@@ -929,7 +968,7 @@ class Signal {
|
|
|
929
968
|
}
|
|
930
969
|
const defaultStopLoss = i === 0 ? stop_loss : _base;
|
|
931
970
|
const new_stop = kind === "long" ? this.support : stop_loss;
|
|
932
|
-
let risk_to_use =
|
|
971
|
+
let risk_to_use = this.getZoneRisk(i, limit_orders.length, this);
|
|
933
972
|
if (this.use_kelly) {
|
|
934
973
|
const func = this.kelly_func === "theoretical" ? calculateTheoreticalKelly : this.kelly_func === "position_based" ? calculatePositionBasedKelly : calculateTheoreticalKellyFixed;
|
|
935
974
|
const theoretical_kelly = func({
|
|
@@ -1613,7 +1652,8 @@ function buildConfig(app_config, {
|
|
|
1613
1652
|
kelly_func = "theoretical",
|
|
1614
1653
|
min_avg_size = 0,
|
|
1615
1654
|
distribution,
|
|
1616
|
-
distribution_params
|
|
1655
|
+
distribution_params,
|
|
1656
|
+
use_progressive_risk = false
|
|
1617
1657
|
}) {
|
|
1618
1658
|
let fee = app_config.fee / 100;
|
|
1619
1659
|
let working_risk = risk || app_config.risk_per_trade;
|
|
@@ -1645,7 +1685,8 @@ function buildConfig(app_config, {
|
|
|
1645
1685
|
kelly_func: kelly_func || app_config.kelly?.kelly_func,
|
|
1646
1686
|
symbol: app_config.symbol,
|
|
1647
1687
|
max_quantity: app_config.max_quantity,
|
|
1648
|
-
distribution_params: distribution_params || app_config.distribution_params
|
|
1688
|
+
distribution_params: distribution_params || app_config.distribution_params,
|
|
1689
|
+
use_progressive_risk
|
|
1649
1690
|
};
|
|
1650
1691
|
const instance = new Signal(config);
|
|
1651
1692
|
if (raw_instance) {
|
|
@@ -1793,7 +1834,12 @@ function buildAppConfig(config, payload) {
|
|
|
1793
1834
|
return app_config;
|
|
1794
1835
|
}
|
|
1795
1836
|
function getOptimumStopAndRisk(app_config, params) {
|
|
1796
|
-
const {
|
|
1837
|
+
const {
|
|
1838
|
+
max_size,
|
|
1839
|
+
target_stop,
|
|
1840
|
+
distribution,
|
|
1841
|
+
distribution_params: _distribution_params
|
|
1842
|
+
} = params;
|
|
1797
1843
|
const isLong = app_config.kind === "long";
|
|
1798
1844
|
const stopRange = Math.abs(app_config.entry - target_stop) * 0.5;
|
|
1799
1845
|
let low_stop = isLong ? target_stop - stopRange : Math.max(target_stop - stopRange, app_config.entry);
|