@gbozee/ultimate 0.0.2-147 → 0.0.2-149
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 +9 -2
- package/dist/frontend-index.js +111 -7
- package/dist/index.cjs +142 -10
- package/dist/index.d.ts +18 -2
- package/dist/index.js +142 -10
- package/dist/mcp-server.cjs +142 -10
- package/dist/mcp-server.js +142 -10
- package/package.json +1 -1
package/dist/frontend-index.d.ts
CHANGED
|
@@ -143,6 +143,7 @@ export type SignalConfigType = {
|
|
|
143
143
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
144
144
|
kelly_confidence_factor?: number;
|
|
145
145
|
kelly_minimum_risk?: number;
|
|
146
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
146
147
|
};
|
|
147
148
|
declare class Signal {
|
|
148
149
|
focus: number;
|
|
@@ -169,7 +170,8 @@ declare class Signal {
|
|
|
169
170
|
kelly_prediction_model: "exponential" | "normal" | "uniform";
|
|
170
171
|
kelly_confidence_factor: number;
|
|
171
172
|
kelly_minimum_risk: number;
|
|
172
|
-
|
|
173
|
+
kelly_func: "theoretical" | "position_based" | "theoretical_fixed";
|
|
174
|
+
constructor({ focus, 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, }: SignalConfigType);
|
|
173
175
|
build_entry({ current_price, stop_loss, pnl, stop_percent, kind, risk, no_of_trades, take_profit, }: {
|
|
174
176
|
take_profit?: number;
|
|
175
177
|
no_of_trades?: number;
|
|
@@ -309,6 +311,7 @@ export type AppConfig = {
|
|
|
309
311
|
kelly_confidence_factor?: number;
|
|
310
312
|
kelly_minimum_risk?: number;
|
|
311
313
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
314
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
312
315
|
};
|
|
313
316
|
};
|
|
314
317
|
export type ExtendConfigType = {
|
|
@@ -330,8 +333,9 @@ export type ExtendConfigType = {
|
|
|
330
333
|
kelly_confidence_factor?: number;
|
|
331
334
|
kelly_minimum_risk?: number;
|
|
332
335
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
336
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
333
337
|
};
|
|
334
|
-
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, }: ExtendConfigType): any[] | Signal;
|
|
338
|
+
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, }: ExtendConfigType): any[] | Signal;
|
|
335
339
|
export declare function buildAvg({ _trades, kind, }: {
|
|
336
340
|
_trades: any[];
|
|
337
341
|
kind: "long" | "short";
|
|
@@ -345,6 +349,7 @@ export declare function get_app_config_and_max_size(config: GlobalConfig, payloa
|
|
|
345
349
|
kelly_confidence_factor?: number;
|
|
346
350
|
kelly_minimum_risk?: number;
|
|
347
351
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
352
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
348
353
|
}): {
|
|
349
354
|
app_config: AppConfig;
|
|
350
355
|
max_size: any;
|
|
@@ -368,6 +373,7 @@ export declare function buildAppConfig(config: GlobalConfig, payload: {
|
|
|
368
373
|
kelly_confidence_factor?: number;
|
|
369
374
|
kelly_minimum_risk?: number;
|
|
370
375
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
376
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
371
377
|
}): AppConfig;
|
|
372
378
|
export declare function getOptimumStopAndRisk(app_config: AppConfig, params: {
|
|
373
379
|
max_size: number;
|
|
@@ -845,6 +851,7 @@ export declare class Strategy {
|
|
|
845
851
|
kelly_confidence_factor?: number;
|
|
846
852
|
kelly_minimum_risk?: number;
|
|
847
853
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
854
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
848
855
|
};
|
|
849
856
|
};
|
|
850
857
|
identifyGapConfig(payload: {
|
package/dist/frontend-index.js
CHANGED
|
@@ -83,6 +83,101 @@ function calculateZoneVolatility(zone_prices) {
|
|
|
83
83
|
const price_changes = zone_prices.slice(1).map((price, i) => Math.abs(price - zone_prices[i]) / zone_prices[i]);
|
|
84
84
|
return price_changes.reduce((sum, change) => sum + change, 0) / price_changes.length;
|
|
85
85
|
}
|
|
86
|
+
function calculateTheoreticalKellyFixed({
|
|
87
|
+
current_entry,
|
|
88
|
+
zone_prices,
|
|
89
|
+
kind = "long",
|
|
90
|
+
config = {}
|
|
91
|
+
}) {
|
|
92
|
+
const {
|
|
93
|
+
price_prediction_model = "uniform",
|
|
94
|
+
confidence_factor = 0.6,
|
|
95
|
+
volatility_adjustment = true
|
|
96
|
+
} = config;
|
|
97
|
+
const sorted_prices = zone_prices;
|
|
98
|
+
const current_index = sorted_prices.findIndex((price) => price === current_entry);
|
|
99
|
+
if (current_index === -1)
|
|
100
|
+
return 0.02;
|
|
101
|
+
let stop_loss;
|
|
102
|
+
let target_zones;
|
|
103
|
+
if (kind === "long") {
|
|
104
|
+
stop_loss = Math.min(...zone_prices);
|
|
105
|
+
target_zones = zone_prices.filter((price) => price > current_entry);
|
|
106
|
+
} else {
|
|
107
|
+
stop_loss = Math.max(...zone_prices);
|
|
108
|
+
target_zones = zone_prices.filter((price) => price < current_entry);
|
|
109
|
+
}
|
|
110
|
+
const risk_amount = Math.abs(current_entry - stop_loss);
|
|
111
|
+
const avg_reward = target_zones.length > 0 ? target_zones.reduce((sum, price) => sum + Math.abs(price - current_entry), 0) / target_zones.length : risk_amount;
|
|
112
|
+
const risk_reward_ratio = avg_reward / risk_amount;
|
|
113
|
+
let position_quality;
|
|
114
|
+
if (kind === "long") {
|
|
115
|
+
const distance_from_stop = current_entry - stop_loss;
|
|
116
|
+
const max_distance = Math.max(...zone_prices) - stop_loss;
|
|
117
|
+
position_quality = 1 - distance_from_stop / max_distance;
|
|
118
|
+
} else {
|
|
119
|
+
const distance_from_stop = stop_loss - current_entry;
|
|
120
|
+
const max_distance = stop_loss - Math.min(...zone_prices);
|
|
121
|
+
position_quality = 1 - distance_from_stop / max_distance;
|
|
122
|
+
}
|
|
123
|
+
let base_probability = 0.5;
|
|
124
|
+
switch (price_prediction_model) {
|
|
125
|
+
case "uniform":
|
|
126
|
+
base_probability = 0.5;
|
|
127
|
+
break;
|
|
128
|
+
case "normal":
|
|
129
|
+
base_probability = 0.3 + position_quality * 0.4;
|
|
130
|
+
break;
|
|
131
|
+
case "exponential":
|
|
132
|
+
base_probability = 0.2 + Math.pow(position_quality, 0.5) * 0.6;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
const win_probability = base_probability * confidence_factor + (1 - confidence_factor) * 0.5;
|
|
136
|
+
const odds_ratio = Math.max(risk_reward_ratio, 0.5);
|
|
137
|
+
const loss_probability = 1 - win_probability;
|
|
138
|
+
let kelly_fraction = (win_probability * odds_ratio - loss_probability) / odds_ratio;
|
|
139
|
+
if (volatility_adjustment) {
|
|
140
|
+
const zone_volatility = calculateZoneVolatility(sorted_prices);
|
|
141
|
+
const vol_adjustment = 1 / (1 + zone_volatility);
|
|
142
|
+
kelly_fraction *= vol_adjustment;
|
|
143
|
+
}
|
|
144
|
+
kelly_fraction = Math.max(0.005, Math.min(kelly_fraction, 0.5));
|
|
145
|
+
return to_f(kelly_fraction, "%.4f");
|
|
146
|
+
}
|
|
147
|
+
function calculatePositionBasedKelly({
|
|
148
|
+
current_entry,
|
|
149
|
+
zone_prices,
|
|
150
|
+
kind = "long",
|
|
151
|
+
config = {}
|
|
152
|
+
}) {
|
|
153
|
+
const {
|
|
154
|
+
price_prediction_model = "uniform",
|
|
155
|
+
confidence_factor: _confidence_factor = 0.6
|
|
156
|
+
} = config;
|
|
157
|
+
const current_index = zone_prices.findIndex((price) => price === current_entry);
|
|
158
|
+
if (current_index === -1)
|
|
159
|
+
return 0.02;
|
|
160
|
+
const total_zones = zone_prices.length;
|
|
161
|
+
const position_score = (total_zones - current_index) / total_zones;
|
|
162
|
+
let adjusted_score;
|
|
163
|
+
switch (price_prediction_model) {
|
|
164
|
+
case "uniform":
|
|
165
|
+
adjusted_score = 0.5;
|
|
166
|
+
break;
|
|
167
|
+
case "normal":
|
|
168
|
+
adjusted_score = 0.3 + position_score * 0.4;
|
|
169
|
+
break;
|
|
170
|
+
case "exponential":
|
|
171
|
+
adjusted_score = 0.2 + Math.pow(position_score, 0.3) * 0.6;
|
|
172
|
+
break;
|
|
173
|
+
default:
|
|
174
|
+
adjusted_score = 0.5;
|
|
175
|
+
}
|
|
176
|
+
const base_kelly = 0.02;
|
|
177
|
+
const max_kelly = 0.2;
|
|
178
|
+
const kelly_fraction = base_kelly + adjusted_score * (max_kelly - base_kelly);
|
|
179
|
+
return to_f(kelly_fraction, "%.4f");
|
|
180
|
+
}
|
|
86
181
|
|
|
87
182
|
// src/helpers/trade_signal.ts
|
|
88
183
|
function determine_close_price({
|
|
@@ -170,6 +265,7 @@ class Signal {
|
|
|
170
265
|
kelly_prediction_model = "exponential";
|
|
171
266
|
kelly_confidence_factor = 0.6;
|
|
172
267
|
kelly_minimum_risk = 0.2;
|
|
268
|
+
kelly_func = "theoretical";
|
|
173
269
|
constructor({
|
|
174
270
|
focus,
|
|
175
271
|
budget,
|
|
@@ -194,7 +290,8 @@ class Signal {
|
|
|
194
290
|
use_kelly = false,
|
|
195
291
|
kelly_prediction_model = "exponential",
|
|
196
292
|
kelly_confidence_factor = 0.6,
|
|
197
|
-
kelly_minimum_risk = 0.2
|
|
293
|
+
kelly_minimum_risk = 0.2,
|
|
294
|
+
kelly_func = "theoretical"
|
|
198
295
|
}) {
|
|
199
296
|
this.minimum_size = minimum_size;
|
|
200
297
|
this.first_order_size = first_order_size;
|
|
@@ -220,6 +317,7 @@ class Signal {
|
|
|
220
317
|
this.kelly_prediction_model = kelly_prediction_model;
|
|
221
318
|
this.kelly_confidence_factor = kelly_confidence_factor;
|
|
222
319
|
this.kelly_minimum_risk = kelly_minimum_risk;
|
|
320
|
+
this.kelly_func = kelly_func;
|
|
223
321
|
}
|
|
224
322
|
build_entry({
|
|
225
323
|
current_price,
|
|
@@ -660,7 +758,8 @@ class Signal {
|
|
|
660
758
|
const new_stop = kind === "long" ? this.support : stop_loss;
|
|
661
759
|
let risk_to_use = risk_per_trade;
|
|
662
760
|
if (this.use_kelly) {
|
|
663
|
-
const
|
|
761
|
+
const func = this.kelly_func === "theoretical" ? calculateTheoreticalKelly : this.kelly_func === "position_based" ? calculatePositionBasedKelly : calculateTheoreticalKellyFixed;
|
|
762
|
+
const theoretical_kelly = func({
|
|
664
763
|
current_entry: x,
|
|
665
764
|
zone_prices: limit_orders,
|
|
666
765
|
kind,
|
|
@@ -1342,7 +1441,8 @@ function buildConfig(app_config, {
|
|
|
1342
1441
|
use_kelly = false,
|
|
1343
1442
|
kelly_confidence_factor = 0.95,
|
|
1344
1443
|
kelly_minimum_risk = 0.2,
|
|
1345
|
-
kelly_prediction_model = "exponential"
|
|
1444
|
+
kelly_prediction_model = "exponential",
|
|
1445
|
+
kelly_func = "theoretical"
|
|
1346
1446
|
}) {
|
|
1347
1447
|
let fee = app_config.fee / 100;
|
|
1348
1448
|
let working_risk = risk || app_config.risk_per_trade;
|
|
@@ -1370,7 +1470,8 @@ function buildConfig(app_config, {
|
|
|
1370
1470
|
use_kelly: use_kelly || app_config.kelly?.use_kelly,
|
|
1371
1471
|
kelly_confidence_factor: kelly_confidence_factor || app_config.kelly?.kelly_confidence_factor,
|
|
1372
1472
|
kelly_minimum_risk: kelly_minimum_risk || app_config.kelly?.kelly_minimum_risk,
|
|
1373
|
-
kelly_prediction_model: kelly_prediction_model || app_config.kelly?.kelly_prediction_model
|
|
1473
|
+
kelly_prediction_model: kelly_prediction_model || app_config.kelly?.kelly_prediction_model,
|
|
1474
|
+
kelly_func: kelly_func || app_config.kelly?.kelly_func
|
|
1374
1475
|
};
|
|
1375
1476
|
const instance = new Signal(config);
|
|
1376
1477
|
if (raw_instance) {
|
|
@@ -1453,7 +1554,8 @@ function get_app_config_and_max_size(config, payload) {
|
|
|
1453
1554
|
use_kelly: payload.use_kelly,
|
|
1454
1555
|
kelly_confidence_factor: payload.kelly_confidence_factor,
|
|
1455
1556
|
kelly_minimum_risk: payload.kelly_minimum_risk,
|
|
1456
|
-
kelly_prediction_model: payload.kelly_prediction_model
|
|
1557
|
+
kelly_prediction_model: payload.kelly_prediction_model,
|
|
1558
|
+
kelly_func: payload.kelly_func
|
|
1457
1559
|
});
|
|
1458
1560
|
const max_size = initialResult[0]?.avg_size;
|
|
1459
1561
|
const last_value = initialResult[0];
|
|
@@ -1490,7 +1592,8 @@ function buildAppConfig(config, payload) {
|
|
|
1490
1592
|
use_kelly: payload.use_kelly,
|
|
1491
1593
|
kelly_confidence_factor: payload.kelly_confidence_factor,
|
|
1492
1594
|
kelly_minimum_risk: payload.kelly_minimum_risk,
|
|
1493
|
-
kelly_prediction_model: payload.kelly_prediction_model
|
|
1595
|
+
kelly_prediction_model: payload.kelly_prediction_model,
|
|
1596
|
+
kelly_func: payload.kelly_func
|
|
1494
1597
|
});
|
|
1495
1598
|
app_config.max_size = max_size;
|
|
1496
1599
|
app_config.entry = payload.entry || app_config.entry;
|
|
@@ -1501,7 +1604,8 @@ function buildAppConfig(config, payload) {
|
|
|
1501
1604
|
use_kelly: payload.use_kelly,
|
|
1502
1605
|
kelly_confidence_factor: payload.kelly_confidence_factor,
|
|
1503
1606
|
kelly_minimum_risk: payload.kelly_minimum_risk,
|
|
1504
|
-
kelly_prediction_model: payload.kelly_prediction_model
|
|
1607
|
+
kelly_prediction_model: payload.kelly_prediction_model,
|
|
1608
|
+
kelly_func: payload.kelly_func
|
|
1505
1609
|
};
|
|
1506
1610
|
return app_config;
|
|
1507
1611
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -52955,6 +52955,101 @@ function calculateZoneVolatility(zone_prices) {
|
|
|
52955
52955
|
const price_changes = zone_prices.slice(1).map((price, i2) => Math.abs(price - zone_prices[i2]) / zone_prices[i2]);
|
|
52956
52956
|
return price_changes.reduce((sum, change) => sum + change, 0) / price_changes.length;
|
|
52957
52957
|
}
|
|
52958
|
+
function calculateTheoreticalKellyFixed({
|
|
52959
|
+
current_entry,
|
|
52960
|
+
zone_prices,
|
|
52961
|
+
kind = "long",
|
|
52962
|
+
config: config2 = {}
|
|
52963
|
+
}) {
|
|
52964
|
+
const {
|
|
52965
|
+
price_prediction_model = "uniform",
|
|
52966
|
+
confidence_factor = 0.6,
|
|
52967
|
+
volatility_adjustment = true
|
|
52968
|
+
} = config2;
|
|
52969
|
+
const sorted_prices = zone_prices;
|
|
52970
|
+
const current_index = sorted_prices.findIndex((price) => price === current_entry);
|
|
52971
|
+
if (current_index === -1)
|
|
52972
|
+
return 0.02;
|
|
52973
|
+
let stop_loss;
|
|
52974
|
+
let target_zones;
|
|
52975
|
+
if (kind === "long") {
|
|
52976
|
+
stop_loss = Math.min(...zone_prices);
|
|
52977
|
+
target_zones = zone_prices.filter((price) => price > current_entry);
|
|
52978
|
+
} else {
|
|
52979
|
+
stop_loss = Math.max(...zone_prices);
|
|
52980
|
+
target_zones = zone_prices.filter((price) => price < current_entry);
|
|
52981
|
+
}
|
|
52982
|
+
const risk_amount = Math.abs(current_entry - stop_loss);
|
|
52983
|
+
const avg_reward = target_zones.length > 0 ? target_zones.reduce((sum, price) => sum + Math.abs(price - current_entry), 0) / target_zones.length : risk_amount;
|
|
52984
|
+
const risk_reward_ratio = avg_reward / risk_amount;
|
|
52985
|
+
let position_quality;
|
|
52986
|
+
if (kind === "long") {
|
|
52987
|
+
const distance_from_stop = current_entry - stop_loss;
|
|
52988
|
+
const max_distance = Math.max(...zone_prices) - stop_loss;
|
|
52989
|
+
position_quality = 1 - distance_from_stop / max_distance;
|
|
52990
|
+
} else {
|
|
52991
|
+
const distance_from_stop = stop_loss - current_entry;
|
|
52992
|
+
const max_distance = stop_loss - Math.min(...zone_prices);
|
|
52993
|
+
position_quality = 1 - distance_from_stop / max_distance;
|
|
52994
|
+
}
|
|
52995
|
+
let base_probability = 0.5;
|
|
52996
|
+
switch (price_prediction_model) {
|
|
52997
|
+
case "uniform":
|
|
52998
|
+
base_probability = 0.5;
|
|
52999
|
+
break;
|
|
53000
|
+
case "normal":
|
|
53001
|
+
base_probability = 0.3 + position_quality * 0.4;
|
|
53002
|
+
break;
|
|
53003
|
+
case "exponential":
|
|
53004
|
+
base_probability = 0.2 + Math.pow(position_quality, 0.5) * 0.6;
|
|
53005
|
+
break;
|
|
53006
|
+
}
|
|
53007
|
+
const win_probability = base_probability * confidence_factor + (1 - confidence_factor) * 0.5;
|
|
53008
|
+
const odds_ratio = Math.max(risk_reward_ratio, 0.5);
|
|
53009
|
+
const loss_probability = 1 - win_probability;
|
|
53010
|
+
let kelly_fraction = (win_probability * odds_ratio - loss_probability) / odds_ratio;
|
|
53011
|
+
if (volatility_adjustment) {
|
|
53012
|
+
const zone_volatility = calculateZoneVolatility(sorted_prices);
|
|
53013
|
+
const vol_adjustment = 1 / (1 + zone_volatility);
|
|
53014
|
+
kelly_fraction *= vol_adjustment;
|
|
53015
|
+
}
|
|
53016
|
+
kelly_fraction = Math.max(0.005, Math.min(kelly_fraction, 0.5));
|
|
53017
|
+
return to_f2(kelly_fraction, "%.4f");
|
|
53018
|
+
}
|
|
53019
|
+
function calculatePositionBasedKelly({
|
|
53020
|
+
current_entry,
|
|
53021
|
+
zone_prices,
|
|
53022
|
+
kind = "long",
|
|
53023
|
+
config: config2 = {}
|
|
53024
|
+
}) {
|
|
53025
|
+
const {
|
|
53026
|
+
price_prediction_model = "uniform",
|
|
53027
|
+
confidence_factor: _confidence_factor = 0.6
|
|
53028
|
+
} = config2;
|
|
53029
|
+
const current_index = zone_prices.findIndex((price) => price === current_entry);
|
|
53030
|
+
if (current_index === -1)
|
|
53031
|
+
return 0.02;
|
|
53032
|
+
const total_zones = zone_prices.length;
|
|
53033
|
+
const position_score = (total_zones - current_index) / total_zones;
|
|
53034
|
+
let adjusted_score;
|
|
53035
|
+
switch (price_prediction_model) {
|
|
53036
|
+
case "uniform":
|
|
53037
|
+
adjusted_score = 0.5;
|
|
53038
|
+
break;
|
|
53039
|
+
case "normal":
|
|
53040
|
+
adjusted_score = 0.3 + position_score * 0.4;
|
|
53041
|
+
break;
|
|
53042
|
+
case "exponential":
|
|
53043
|
+
adjusted_score = 0.2 + Math.pow(position_score, 0.3) * 0.6;
|
|
53044
|
+
break;
|
|
53045
|
+
default:
|
|
53046
|
+
adjusted_score = 0.5;
|
|
53047
|
+
}
|
|
53048
|
+
const base_kelly = 0.02;
|
|
53049
|
+
const max_kelly = 0.2;
|
|
53050
|
+
const kelly_fraction = base_kelly + adjusted_score * (max_kelly - base_kelly);
|
|
53051
|
+
return to_f2(kelly_fraction, "%.4f");
|
|
53052
|
+
}
|
|
52958
53053
|
|
|
52959
53054
|
// src/helpers/trade_signal.ts
|
|
52960
53055
|
function determine_close_price2({
|
|
@@ -53042,6 +53137,7 @@ class Signal {
|
|
|
53042
53137
|
kelly_prediction_model = "exponential";
|
|
53043
53138
|
kelly_confidence_factor = 0.6;
|
|
53044
53139
|
kelly_minimum_risk = 0.2;
|
|
53140
|
+
kelly_func = "theoretical";
|
|
53045
53141
|
constructor({
|
|
53046
53142
|
focus,
|
|
53047
53143
|
budget,
|
|
@@ -53066,7 +53162,8 @@ class Signal {
|
|
|
53066
53162
|
use_kelly = false,
|
|
53067
53163
|
kelly_prediction_model = "exponential",
|
|
53068
53164
|
kelly_confidence_factor = 0.6,
|
|
53069
|
-
kelly_minimum_risk = 0.2
|
|
53165
|
+
kelly_minimum_risk = 0.2,
|
|
53166
|
+
kelly_func = "theoretical"
|
|
53070
53167
|
}) {
|
|
53071
53168
|
this.minimum_size = minimum_size;
|
|
53072
53169
|
this.first_order_size = first_order_size;
|
|
@@ -53092,6 +53189,7 @@ class Signal {
|
|
|
53092
53189
|
this.kelly_prediction_model = kelly_prediction_model;
|
|
53093
53190
|
this.kelly_confidence_factor = kelly_confidence_factor;
|
|
53094
53191
|
this.kelly_minimum_risk = kelly_minimum_risk;
|
|
53192
|
+
this.kelly_func = kelly_func;
|
|
53095
53193
|
}
|
|
53096
53194
|
build_entry({
|
|
53097
53195
|
current_price,
|
|
@@ -53532,7 +53630,8 @@ class Signal {
|
|
|
53532
53630
|
const new_stop = kind === "long" ? this.support : stop_loss;
|
|
53533
53631
|
let risk_to_use = risk_per_trade;
|
|
53534
53632
|
if (this.use_kelly) {
|
|
53535
|
-
const
|
|
53633
|
+
const func = this.kelly_func === "theoretical" ? calculateTheoreticalKelly : this.kelly_func === "position_based" ? calculatePositionBasedKelly : calculateTheoreticalKellyFixed;
|
|
53634
|
+
const theoretical_kelly = func({
|
|
53536
53635
|
current_entry: x,
|
|
53537
53636
|
zone_prices: limit_orders,
|
|
53538
53637
|
kind,
|
|
@@ -53740,7 +53839,8 @@ function buildConfig(app_config, {
|
|
|
53740
53839
|
use_kelly = false,
|
|
53741
53840
|
kelly_confidence_factor = 0.95,
|
|
53742
53841
|
kelly_minimum_risk = 0.2,
|
|
53743
|
-
kelly_prediction_model = "exponential"
|
|
53842
|
+
kelly_prediction_model = "exponential",
|
|
53843
|
+
kelly_func = "theoretical"
|
|
53744
53844
|
}) {
|
|
53745
53845
|
let fee = app_config.fee / 100;
|
|
53746
53846
|
let working_risk = risk || app_config.risk_per_trade;
|
|
@@ -53768,7 +53868,8 @@ function buildConfig(app_config, {
|
|
|
53768
53868
|
use_kelly: use_kelly || app_config.kelly?.use_kelly,
|
|
53769
53869
|
kelly_confidence_factor: kelly_confidence_factor || app_config.kelly?.kelly_confidence_factor,
|
|
53770
53870
|
kelly_minimum_risk: kelly_minimum_risk || app_config.kelly?.kelly_minimum_risk,
|
|
53771
|
-
kelly_prediction_model: kelly_prediction_model || app_config.kelly?.kelly_prediction_model
|
|
53871
|
+
kelly_prediction_model: kelly_prediction_model || app_config.kelly?.kelly_prediction_model,
|
|
53872
|
+
kelly_func: kelly_func || app_config.kelly?.kelly_func
|
|
53772
53873
|
};
|
|
53773
53874
|
const instance = new Signal(config2);
|
|
53774
53875
|
if (raw_instance) {
|
|
@@ -53851,7 +53952,8 @@ function get_app_config_and_max_size(config2, payload) {
|
|
|
53851
53952
|
use_kelly: payload.use_kelly,
|
|
53852
53953
|
kelly_confidence_factor: payload.kelly_confidence_factor,
|
|
53853
53954
|
kelly_minimum_risk: payload.kelly_minimum_risk,
|
|
53854
|
-
kelly_prediction_model: payload.kelly_prediction_model
|
|
53955
|
+
kelly_prediction_model: payload.kelly_prediction_model,
|
|
53956
|
+
kelly_func: payload.kelly_func
|
|
53855
53957
|
});
|
|
53856
53958
|
const max_size = initialResult[0]?.avg_size;
|
|
53857
53959
|
const last_value = initialResult[0];
|
|
@@ -53888,7 +53990,8 @@ function buildAppConfig(config2, payload) {
|
|
|
53888
53990
|
use_kelly: payload.use_kelly,
|
|
53889
53991
|
kelly_confidence_factor: payload.kelly_confidence_factor,
|
|
53890
53992
|
kelly_minimum_risk: payload.kelly_minimum_risk,
|
|
53891
|
-
kelly_prediction_model: payload.kelly_prediction_model
|
|
53993
|
+
kelly_prediction_model: payload.kelly_prediction_model,
|
|
53994
|
+
kelly_func: payload.kelly_func
|
|
53892
53995
|
});
|
|
53893
53996
|
app_config.max_size = max_size;
|
|
53894
53997
|
app_config.entry = payload.entry || app_config.entry;
|
|
@@ -53899,7 +54002,8 @@ function buildAppConfig(config2, payload) {
|
|
|
53899
54002
|
use_kelly: payload.use_kelly,
|
|
53900
54003
|
kelly_confidence_factor: payload.kelly_confidence_factor,
|
|
53901
54004
|
kelly_minimum_risk: payload.kelly_minimum_risk,
|
|
53902
|
-
kelly_prediction_model: payload.kelly_prediction_model
|
|
54005
|
+
kelly_prediction_model: payload.kelly_prediction_model,
|
|
54006
|
+
kelly_func: payload.kelly_func
|
|
53903
54007
|
};
|
|
53904
54008
|
return app_config;
|
|
53905
54009
|
}
|
|
@@ -58286,6 +58390,7 @@ class ExchangeAccount {
|
|
|
58286
58390
|
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
58287
58391
|
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
58288
58392
|
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
58393
|
+
kelly_func: config2.kelly?.kelly_func,
|
|
58289
58394
|
...override
|
|
58290
58395
|
});
|
|
58291
58396
|
return app_config;
|
|
@@ -58407,6 +58512,13 @@ class ExchangeAccount {
|
|
|
58407
58512
|
app_config.risk_per_trade = solution.risk_per_trade;
|
|
58408
58513
|
app_config.min_size = solution.min_size;
|
|
58409
58514
|
app_config.risk_reward = solution.risk_reward;
|
|
58515
|
+
app_config.kelly = {
|
|
58516
|
+
use_kelly: solution.use_kelly,
|
|
58517
|
+
kelly_confidence_factor: solution.kelly_confidence_factor,
|
|
58518
|
+
kelly_minimum_risk: solution.kelly_minimum_risk,
|
|
58519
|
+
kelly_prediction_model: solution.kelly_prediction_model,
|
|
58520
|
+
kelly_func: solution.kelly_func
|
|
58521
|
+
};
|
|
58410
58522
|
const options = {
|
|
58411
58523
|
take_profit: null,
|
|
58412
58524
|
entry: app_config.entry,
|
|
@@ -58420,7 +58532,12 @@ class ExchangeAccount {
|
|
|
58420
58532
|
gap: app_config.gap,
|
|
58421
58533
|
rr: app_config.rr,
|
|
58422
58534
|
price_places: app_config.price_places,
|
|
58423
|
-
decimal_places: app_config.decimal_places
|
|
58535
|
+
decimal_places: app_config.decimal_places,
|
|
58536
|
+
use_kelly: solution.use_kelly,
|
|
58537
|
+
kelly_confidence_factor: solution.kelly_confidence_factor,
|
|
58538
|
+
kelly_minimum_risk: solution.kelly_minimum_risk,
|
|
58539
|
+
kelly_prediction_model: solution.kelly_prediction_model,
|
|
58540
|
+
kelly_func: solution.kelly_func
|
|
58424
58541
|
};
|
|
58425
58542
|
const trades = sortedBuildConfig(app_config, options);
|
|
58426
58543
|
const entry_orders = {
|
|
@@ -58537,6 +58654,11 @@ class ExchangeAccount {
|
|
|
58537
58654
|
}
|
|
58538
58655
|
async placeSharedOrder(action, payload) {
|
|
58539
58656
|
const { stop_percent = 100 } = payload;
|
|
58657
|
+
const kind = payload.entry > payload.stop ? "long" : "short";
|
|
58658
|
+
const config2 = await this.getPositionConfig({
|
|
58659
|
+
symbol: payload.symbol,
|
|
58660
|
+
kind
|
|
58661
|
+
});
|
|
58540
58662
|
const app_config = await this.buildAppConfig({
|
|
58541
58663
|
entry: payload.entry,
|
|
58542
58664
|
stop: payload.stop,
|
|
@@ -58544,7 +58666,12 @@ class ExchangeAccount {
|
|
|
58544
58666
|
risk: payload.risk,
|
|
58545
58667
|
symbol: payload.symbol,
|
|
58546
58668
|
profit: 0,
|
|
58547
|
-
update_db: payload.update_db
|
|
58669
|
+
update_db: payload.update_db,
|
|
58670
|
+
use_kelly: config2.kelly?.use_kelly,
|
|
58671
|
+
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
58672
|
+
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
58673
|
+
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
58674
|
+
kelly_func: config2.kelly?.kelly_func
|
|
58548
58675
|
});
|
|
58549
58676
|
const { entry_orders, stop_orders, trades } = await this.placeConfigOrders(app_config, {
|
|
58550
58677
|
risk_reward: payload.risk_reward,
|
|
@@ -58555,7 +58682,12 @@ class ExchangeAccount {
|
|
|
58555
58682
|
neg_pnl: 0,
|
|
58556
58683
|
min_size: app_config.min_size,
|
|
58557
58684
|
symbol: payload.symbol,
|
|
58558
|
-
stop_percent
|
|
58685
|
+
stop_percent,
|
|
58686
|
+
use_kelly: config2.kelly?.use_kelly,
|
|
58687
|
+
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
58688
|
+
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
58689
|
+
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
58690
|
+
kelly_func: config2.kelly?.kelly_func
|
|
58559
58691
|
}, false);
|
|
58560
58692
|
if (payload.raw) {
|
|
58561
58693
|
let actual_orders_to_buy = await this.determineAmountToBuy({
|
package/dist/index.d.ts
CHANGED
|
@@ -1027,6 +1027,7 @@ export declare class Strategy {
|
|
|
1027
1027
|
kelly_confidence_factor?: number;
|
|
1028
1028
|
kelly_minimum_risk?: number;
|
|
1029
1029
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
1030
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
1030
1031
|
};
|
|
1031
1032
|
};
|
|
1032
1033
|
identifyGapConfig(payload: {
|
|
@@ -1145,6 +1146,7 @@ export type SignalConfigType = {
|
|
|
1145
1146
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
1146
1147
|
kelly_confidence_factor?: number;
|
|
1147
1148
|
kelly_minimum_risk?: number;
|
|
1149
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
1148
1150
|
};
|
|
1149
1151
|
declare class Signal {
|
|
1150
1152
|
focus: number;
|
|
@@ -1171,7 +1173,8 @@ declare class Signal {
|
|
|
1171
1173
|
kelly_prediction_model: "exponential" | "normal" | "uniform";
|
|
1172
1174
|
kelly_confidence_factor: number;
|
|
1173
1175
|
kelly_minimum_risk: number;
|
|
1174
|
-
|
|
1176
|
+
kelly_func: "theoretical" | "position_based" | "theoretical_fixed";
|
|
1177
|
+
constructor({ focus, 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, }: SignalConfigType);
|
|
1175
1178
|
build_entry({ current_price, stop_loss, pnl, stop_percent, kind, risk, no_of_trades, take_profit, }: {
|
|
1176
1179
|
take_profit?: number;
|
|
1177
1180
|
no_of_trades?: number;
|
|
@@ -1299,6 +1302,7 @@ export type AppConfig = {
|
|
|
1299
1302
|
kelly_confidence_factor?: number;
|
|
1300
1303
|
kelly_minimum_risk?: number;
|
|
1301
1304
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
1305
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
1302
1306
|
};
|
|
1303
1307
|
};
|
|
1304
1308
|
export type ExtendConfigType = {
|
|
@@ -1320,8 +1324,9 @@ export type ExtendConfigType = {
|
|
|
1320
1324
|
kelly_confidence_factor?: number;
|
|
1321
1325
|
kelly_minimum_risk?: number;
|
|
1322
1326
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
1327
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
1323
1328
|
};
|
|
1324
|
-
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, }: ExtendConfigType): any[] | Signal;
|
|
1329
|
+
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, }: ExtendConfigType): any[] | Signal;
|
|
1325
1330
|
export declare function buildAvg({ _trades, kind, }: {
|
|
1326
1331
|
_trades: any[];
|
|
1327
1332
|
kind: "long" | "short";
|
|
@@ -1335,6 +1340,7 @@ export declare function get_app_config_and_max_size(config: GlobalConfig, payloa
|
|
|
1335
1340
|
kelly_confidence_factor?: number;
|
|
1336
1341
|
kelly_minimum_risk?: number;
|
|
1337
1342
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
1343
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
1338
1344
|
}): {
|
|
1339
1345
|
app_config: AppConfig;
|
|
1340
1346
|
max_size: any;
|
|
@@ -1358,6 +1364,7 @@ export declare function buildAppConfig(config: GlobalConfig, payload: {
|
|
|
1358
1364
|
kelly_confidence_factor?: number;
|
|
1359
1365
|
kelly_minimum_risk?: number;
|
|
1360
1366
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
1367
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
1361
1368
|
}): AppConfig;
|
|
1362
1369
|
export declare function getOptimumStopAndRisk(app_config: AppConfig, params: {
|
|
1363
1370
|
max_size: number;
|
|
@@ -1896,6 +1903,7 @@ declare class ExchangeAccount$1 {
|
|
|
1896
1903
|
kelly_confidence_factor?: number;
|
|
1897
1904
|
kelly_minimum_risk?: number;
|
|
1898
1905
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
1906
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
1899
1907
|
}): Promise<AppConfig>;
|
|
1900
1908
|
tradeConfig(payload: {
|
|
1901
1909
|
symbol: string;
|
|
@@ -1938,6 +1946,11 @@ declare class ExchangeAccount$1 {
|
|
|
1938
1946
|
min_size: number;
|
|
1939
1947
|
symbol: string;
|
|
1940
1948
|
stop_percent?: number;
|
|
1949
|
+
use_kelly?: boolean;
|
|
1950
|
+
kelly_confidence_factor?: number;
|
|
1951
|
+
kelly_minimum_risk?: number;
|
|
1952
|
+
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
1953
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
1941
1954
|
}, place?: boolean, skip_stop?: boolean): Promise<{
|
|
1942
1955
|
entry_orders: {
|
|
1943
1956
|
orders: {
|
|
@@ -2249,6 +2262,7 @@ declare class ExchangeAccount$1 {
|
|
|
2249
2262
|
kelly_confidence_factor?: number;
|
|
2250
2263
|
kelly_minimum_risk?: number;
|
|
2251
2264
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
2265
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
2252
2266
|
};
|
|
2253
2267
|
}>;
|
|
2254
2268
|
runSimulation(payload: {
|
|
@@ -2435,6 +2449,7 @@ declare class ExchangeAccount$1 {
|
|
|
2435
2449
|
kelly_confidence_factor?: number;
|
|
2436
2450
|
kelly_minimum_risk?: number;
|
|
2437
2451
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
2452
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
2438
2453
|
};
|
|
2439
2454
|
};
|
|
2440
2455
|
last_value: any;
|
|
@@ -2708,6 +2723,7 @@ declare class App {
|
|
|
2708
2723
|
kelly_confidence_factor?: number;
|
|
2709
2724
|
kelly_minimum_risk?: number;
|
|
2710
2725
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
2726
|
+
kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
|
|
2711
2727
|
};
|
|
2712
2728
|
};
|
|
2713
2729
|
last_value: any;
|