elemento-alpha-tools 1.2.21 → 1.2.22
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/optimization/population/Individual.d.ts +9 -0
- package/dist/optimization/population/Individual.js +10 -0
- package/dist/optimization/population/Individual.js.map +1 -0
- package/dist/optimization/population/PopulationGenerator.d.ts +9 -0
- package/dist/optimization/population/PopulationGenerator.js +21 -0
- package/dist/optimization/population/PopulationGenerator.js.map +1 -0
- package/dist/optimization/search/Goal.d.ts +9 -0
- package/dist/optimization/search/Goal.js +16 -0
- package/dist/optimization/search/Goal.js.map +1 -0
- package/dist/optimization/search/MultiObjectivePopulationSearch.d.ts +20 -0
- package/dist/optimization/search/MultiObjectivePopulationSearch.js +34 -0
- package/dist/optimization/search/MultiObjectivePopulationSearch.js.map +1 -0
- package/dist/optimization/search/Space.d.ts +7 -0
- package/dist/optimization/search/Space.js +3 -0
- package/dist/optimization/search/Space.js.map +1 -0
- package/dist/optimization/search/portfolio/PortfolioIndividual.d.ts +5 -0
- package/dist/optimization/search/portfolio/PortfolioIndividual.js +14 -0
- package/dist/optimization/search/portfolio/PortfolioIndividual.js.map +1 -0
- package/dist/optimization/search/portfolio/PortfolioIndividualBuilder.d.ts +5 -0
- package/dist/optimization/search/portfolio/PortfolioIndividualBuilder.js +11 -0
- package/dist/optimization/search/portfolio/PortfolioIndividualBuilder.js.map +1 -0
- package/dist/optimization/search/portfolio/PortfolioSearch.d.ts +18 -0
- package/dist/optimization/search/portfolio/PortfolioSearch.js +72 -0
- package/dist/optimization/search/portfolio/PortfolioSearch.js.map +1 -0
- package/dist/optimization/search/portfolio/PortfolioSpace.d.ts +32 -0
- package/dist/optimization/search/portfolio/PortfolioSpace.js +131 -0
- package/dist/optimization/search/portfolio/PortfolioSpace.js.map +1 -0
- package/dist/optimization/search/portfolio/PortfolioTypes.d.ts +26 -0
- package/dist/optimization/search/portfolio/PortfolioTypes.js +3 -0
- package/dist/optimization/search/portfolio/PortfolioTypes.js.map +1 -0
- package/dist/optimization/search/portfolio/goals/ReturnGoal.d.ts +17 -0
- package/dist/optimization/search/portfolio/goals/ReturnGoal.js +72 -0
- package/dist/optimization/search/portfolio/goals/ReturnGoal.js.map +1 -0
- package/dist/optimization/search/portfolio/goals/VolatilityGoal.d.ts +17 -0
- package/dist/optimization/search/portfolio/goals/VolatilityGoal.js +93 -0
- package/dist/optimization/search/portfolio/goals/VolatilityGoal.js.map +1 -0
- package/dist/optimization/search/portfolio/noDominanceSelector/EnviromentSelector.d.ts +21 -0
- package/dist/optimization/search/portfolio/noDominanceSelector/EnviromentSelector.js +98 -0
- package/dist/optimization/search/portfolio/noDominanceSelector/EnviromentSelector.js.map +1 -0
- package/dist/optimization/search/portfolio/tournament/TournamentSelector.d.ts +11 -0
- package/dist/optimization/search/portfolio/tournament/TournamentSelector.js +52 -0
- package/dist/optimization/search/portfolio/tournament/TournamentSelector.js.map +1 -0
- package/dist/optimization/search/portfolio/variate/PortfolioMutation.d.ts +8 -0
- package/dist/optimization/search/portfolio/variate/PortfolioMutation.js +26 -0
- package/dist/optimization/search/portfolio/variate/PortfolioMutation.js.map +1 -0
- package/dist/optimization/search/portfolio/variate/PortfolioXOver.d.ts +8 -0
- package/dist/optimization/search/portfolio/variate/PortfolioXOver.js +23 -0
- package/dist/optimization/search/portfolio/variate/PortfolioXOver.js.map +1 -0
- package/dist/optimization/search/variate/Variation.d.ts +9 -0
- package/dist/optimization/search/variate/Variation.js +13 -0
- package/dist/optimization/search/variate/Variation.js.map +1 -0
- package/dist/sort/Order.d.ts +4 -0
- package/dist/sort/Order.js +3 -0
- package/dist/sort/Order.js.map +1 -0
- package/dist/sort/ReversedOrder.d.ts +7 -0
- package/dist/sort/ReversedOrder.js +16 -0
- package/dist/sort/ReversedOrder.js.map +1 -0
- package/dist/sort/real/RealOrder.d.ts +7 -0
- package/dist/sort/real/RealOrder.js +18 -0
- package/dist/sort/real/RealOrder.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Individual = void 0;
|
|
4
|
+
class Individual {
|
|
5
|
+
constructor(genotype) {
|
|
6
|
+
this.genotype = genotype;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.Individual = Individual;
|
|
10
|
+
//# sourceMappingURL=Individual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Individual.js","sourceRoot":"","sources":["../../../src/optimization/population/Individual.ts"],"names":[],"mappings":";;;AAAA,MAAsB,UAAU;IAI5B,YAAY,QAAW;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CAGJ;AATD,gCASC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Individual, IndividualBuilder } from "./Individual";
|
|
2
|
+
import { Space } from "../search/Space";
|
|
3
|
+
export declare class PopulationGenerator<G, P, F> {
|
|
4
|
+
private space;
|
|
5
|
+
private builder;
|
|
6
|
+
constructor(generator: Space<G>, builder: IndividualBuilder<G, P, F>);
|
|
7
|
+
generate(count: number): Individual<G, P, F>[];
|
|
8
|
+
getSpace(): Space<G>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PopulationGenerator = void 0;
|
|
4
|
+
class PopulationGenerator {
|
|
5
|
+
constructor(generator, builder) {
|
|
6
|
+
this.space = generator;
|
|
7
|
+
this.builder = builder;
|
|
8
|
+
}
|
|
9
|
+
generate(count) {
|
|
10
|
+
let genotypes = this.space.generateMany(count);
|
|
11
|
+
let population = [];
|
|
12
|
+
for (let genotype of genotypes)
|
|
13
|
+
population.push(this.builder.apply(genotype));
|
|
14
|
+
return population;
|
|
15
|
+
}
|
|
16
|
+
getSpace() {
|
|
17
|
+
return this.space;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.PopulationGenerator = PopulationGenerator;
|
|
21
|
+
//# sourceMappingURL=PopulationGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PopulationGenerator.js","sourceRoot":"","sources":["../../../src/optimization/population/PopulationGenerator.ts"],"names":[],"mappings":";;;AAGA,MAAa,mBAAmB;IAI5B,YAAY,SAAmB,EAAE,OAAmC;QAChE,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAEM,QAAQ,CAAC,KAAa;QACzB,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAC/C,IAAI,UAAU,GAAG,EAAE,CAAC;QACpB,KAAK,IAAI,QAAQ,IAAI,SAAS;YAC1B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;QAClD,OAAO,UAAU,CAAC;IACtB,CAAC;IAEM,QAAQ;QACX,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;CACJ;AApBD,kDAoBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Order } from "../../sort/Order";
|
|
2
|
+
export declare abstract class Goal<T, R> {
|
|
3
|
+
protected order: Order<R>;
|
|
4
|
+
constructor(order: Order<R>);
|
|
5
|
+
getOrder(): Order<R>;
|
|
6
|
+
abstract compute(x: T): R;
|
|
7
|
+
compare(x: T, y: T): number;
|
|
8
|
+
abstract init(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Goal = void 0;
|
|
4
|
+
class Goal {
|
|
5
|
+
constructor(order) {
|
|
6
|
+
this.order = order;
|
|
7
|
+
}
|
|
8
|
+
getOrder() {
|
|
9
|
+
return this.order;
|
|
10
|
+
}
|
|
11
|
+
compare(x, y) {
|
|
12
|
+
return this.order.compare(this.compute(x), this.compute(y));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.Goal = Goal;
|
|
16
|
+
//# sourceMappingURL=Goal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Goal.js","sourceRoot":"","sources":["../../../src/optimization/search/Goal.ts"],"names":[],"mappings":";;;AAEA,MAAsB,IAAI;IAGtB,YAAY,KAAe;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAEM,QAAQ;QACX,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAIM,OAAO,CAAC,CAAI,EAAE,CAAI;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC;CAGJ;AAlBD,oBAkBC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PopulationGenerator } from "../population/PopulationGenerator";
|
|
2
|
+
import { Individual } from "../population/Individual";
|
|
3
|
+
import { Variation } from "./variate/Variation";
|
|
4
|
+
import { Goal } from "./Goal";
|
|
5
|
+
export interface Coupling<G, P, F> {
|
|
6
|
+
operIndex: number;
|
|
7
|
+
parents: Individual<G, P, F>[];
|
|
8
|
+
}
|
|
9
|
+
export declare abstract class MultiObjectivePopulationSearch<G, P, F, R> {
|
|
10
|
+
protected generator: PopulationGenerator<G, P, F[]>;
|
|
11
|
+
protected goals: Goal<Individual<G, P, F[]>, F>[];
|
|
12
|
+
protected opers: Variation<G>[];
|
|
13
|
+
constructor(generator: PopulationGenerator<G, P, F[]>, goals: Goal<Individual<G, P, F[]>, F>[], opers: Variation<G>[]);
|
|
14
|
+
apply(iters: number, popSize: number): Promise<Individual<G, P, F[]>[]>;
|
|
15
|
+
protected abstract evaluate(population: Individual<G, P, F[]>[]): Promise<void>;
|
|
16
|
+
protected abstract select(population: Individual<G, P, F[]>[]): Coupling<G, P, F[]>[];
|
|
17
|
+
protected abstract reproduce(couplings: Coupling<G, P, F[]>[]): Individual<G, P, F[]>[];
|
|
18
|
+
protected abstract replace(population: Individual<G, P, F[]>[], offspring: Individual<G, P, F[]>[], popSize: number): Individual<G, P, F[]>[];
|
|
19
|
+
protected abstract choose(population: Individual<G, P, F[]>[]): Individual<G, P, F[]>[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MultiObjectivePopulationSearch = void 0;
|
|
13
|
+
class MultiObjectivePopulationSearch {
|
|
14
|
+
constructor(generator, goals, opers) {
|
|
15
|
+
this.generator = generator;
|
|
16
|
+
this.goals = goals;
|
|
17
|
+
this.opers = opers;
|
|
18
|
+
}
|
|
19
|
+
apply(iters, popSize) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
let population = this.generator.generate(popSize);
|
|
22
|
+
yield this.evaluate(population);
|
|
23
|
+
for (let iter = 1; iter <= iters; iter++) {
|
|
24
|
+
let couplings = this.select(population);
|
|
25
|
+
let offspring = this.reproduce(couplings);
|
|
26
|
+
yield this.evaluate(offspring);
|
|
27
|
+
population = this.replace(population, offspring, popSize);
|
|
28
|
+
}
|
|
29
|
+
return this.choose(population);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.MultiObjectivePopulationSearch = MultiObjectivePopulationSearch;
|
|
34
|
+
//# sourceMappingURL=MultiObjectivePopulationSearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultiObjectivePopulationSearch.js","sourceRoot":"","sources":["../../../src/optimization/search/MultiObjectivePopulationSearch.ts"],"names":[],"mappings":";;;;;;;;;;;;AAUA,MAAsB,8BAA8B;IAKhD,YAAY,SAAyC,EAAE,KAAuC,EAAE,KAAqB;QACjH,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAEY,KAAK,CAAC,KAAa,EAAE,OAAe;;YAC7C,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAClD,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YAChC,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,IAAI,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC;gBACvC,IAAI,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBACxC,IAAI,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;gBAC1C,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;gBAC/B,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YAC9D,CAAC;YACD,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACnC,CAAC;KAAA;CAQJ;AA7BD,wEA6BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Space.js","sourceRoot":"","sources":["../../../src/optimization/search/Space.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PortfolioIndividual = void 0;
|
|
4
|
+
const Individual_1 = require("../../population/Individual");
|
|
5
|
+
class PortfolioIndividual extends Individual_1.Individual {
|
|
6
|
+
constructor(genotype) {
|
|
7
|
+
super(genotype);
|
|
8
|
+
}
|
|
9
|
+
grow() {
|
|
10
|
+
return this.genotype;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.PortfolioIndividual = PortfolioIndividual;
|
|
14
|
+
//# sourceMappingURL=PortfolioIndividual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PortfolioIndividual.js","sourceRoot":"","sources":["../../../../src/optimization/search/portfolio/PortfolioIndividual.ts"],"names":[],"mappings":";;;AAAA,4DAAyD;AAEzD,MAAa,mBAAoB,SAAQ,uBAAwC;IAC/E,YAAY,QAAkB;QAC5B,KAAK,CAAC,QAAQ,CAAC,CAAC;IAClB,CAAC;IAEM,IAAI;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AARD,kDAQC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IndividualBuilder } from "../../population/Individual";
|
|
2
|
+
import { PortfolioIndividual } from "./PortfolioIndividual";
|
|
3
|
+
export declare class PortfolioIndividualBuilder implements IndividualBuilder<number[], number[], number[]> {
|
|
4
|
+
apply(genotype: number[]): PortfolioIndividual;
|
|
5
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PortfolioIndividualBuilder = void 0;
|
|
4
|
+
const PortfolioIndividual_1 = require("./PortfolioIndividual");
|
|
5
|
+
class PortfolioIndividualBuilder {
|
|
6
|
+
apply(genotype) {
|
|
7
|
+
return new PortfolioIndividual_1.PortfolioIndividual(genotype);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.PortfolioIndividualBuilder = PortfolioIndividualBuilder;
|
|
11
|
+
//# sourceMappingURL=PortfolioIndividualBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PortfolioIndividualBuilder.js","sourceRoot":"","sources":["../../../../src/optimization/search/portfolio/PortfolioIndividualBuilder.ts"],"names":[],"mappings":";;;AACA,+DAA4D;AAE5D,MAAa,0BAA0B;IAC9B,KAAK,CAAC,QAAkB;QAC7B,OAAO,IAAI,yCAAmB,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;CACF;AAJD,gEAIC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Individual } from '../../population/Individual';
|
|
2
|
+
import { PopulationGenerator } from '../../population/PopulationGenerator';
|
|
3
|
+
import { Goal } from '../Goal';
|
|
4
|
+
import { Coupling, MultiObjectivePopulationSearch } from '../MultiObjectivePopulationSearch';
|
|
5
|
+
import { Space } from '../Space';
|
|
6
|
+
import { Variation } from '../variate/Variation';
|
|
7
|
+
export declare class PortfolioSearch extends MultiObjectivePopulationSearch<number[], number[], number, Individual<number[], number[], number[]>> {
|
|
8
|
+
private selector;
|
|
9
|
+
private archive;
|
|
10
|
+
private environmentalSelector;
|
|
11
|
+
private space;
|
|
12
|
+
constructor(space: Space<number[]>, generator: PopulationGenerator<number[], number[], number[]>, goals: Goal<Individual<number[], number[], number[]>, number>[], operators: Variation<number[]>[]);
|
|
13
|
+
protected evaluate(population: Individual<number[], number[], number[]>[]): Promise<void>;
|
|
14
|
+
protected select(population: Individual<number[], number[], number[]>[]): Coupling<number[], number[], number[]>[];
|
|
15
|
+
protected reproduce(couplings: Coupling<number[], number[], number[]>[]): Individual<number[], number[], number[]>[];
|
|
16
|
+
protected replace(population: Individual<number[], number[], number[]>[], offspring: Individual<number[], number[], number[]>[], popSize: number): Individual<number[], number[], number[]>[];
|
|
17
|
+
protected choose(population: Individual<number[], number[], number[]>[]): Individual<number[], number[], number[]>[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PortfolioSearch = void 0;
|
|
13
|
+
const MultiObjectivePopulationSearch_1 = require("../MultiObjectivePopulationSearch");
|
|
14
|
+
const EnviromentSelector_1 = require("./noDominanceSelector/EnviromentSelector");
|
|
15
|
+
const PortfolioIndividual_1 = require("./PortfolioIndividual");
|
|
16
|
+
const TournamentSelector_1 = require("./tournament/TournamentSelector");
|
|
17
|
+
class PortfolioSearch extends MultiObjectivePopulationSearch_1.MultiObjectivePopulationSearch {
|
|
18
|
+
constructor(space, generator, goals, operators) {
|
|
19
|
+
super(generator, goals, operators);
|
|
20
|
+
this.archive = [];
|
|
21
|
+
this.space = space;
|
|
22
|
+
this.selector = new TournamentSelector_1.TournamentSelector(goals);
|
|
23
|
+
this.environmentalSelector = new EnviromentSelector_1.EnvironmentSelector(space, goals);
|
|
24
|
+
}
|
|
25
|
+
evaluate(population) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
for (let individual of population)
|
|
28
|
+
if (individual.fitness === undefined || individual.fitness.length !== this.goals.length) {
|
|
29
|
+
let fitnessValues = [];
|
|
30
|
+
for (let goal of this.goals) {
|
|
31
|
+
const value = goal.compute(individual);
|
|
32
|
+
fitnessValues.push(value);
|
|
33
|
+
}
|
|
34
|
+
individual.fitness = fitnessValues;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
select(population) {
|
|
39
|
+
const couplings = [];
|
|
40
|
+
for (let individual of population) {
|
|
41
|
+
const operIndex = Math.floor(Math.random() * this.opers.length);
|
|
42
|
+
const operator = this.opers[operIndex];
|
|
43
|
+
let coupling = { operIndex, parents: [individual] };
|
|
44
|
+
for (let i = 1; i < operator.arity(); i++)
|
|
45
|
+
coupling.parents.push(this.selector.selectOne(population));
|
|
46
|
+
couplings.push(coupling);
|
|
47
|
+
}
|
|
48
|
+
return couplings;
|
|
49
|
+
}
|
|
50
|
+
reproduce(couplings) {
|
|
51
|
+
let offspring = [];
|
|
52
|
+
for (let coupling of couplings) {
|
|
53
|
+
const parentGenotypes = coupling.parents.map(p => p.genotype);
|
|
54
|
+
const childrenGenotypes = this.opers[coupling.operIndex].apply(parentGenotypes);
|
|
55
|
+
for (let childGenotype of childrenGenotypes)
|
|
56
|
+
offspring.push(new PortfolioIndividual_1.PortfolioIndividual(this.space.repair(childGenotype)));
|
|
57
|
+
}
|
|
58
|
+
return offspring;
|
|
59
|
+
}
|
|
60
|
+
replace(population, offspring, popSize) {
|
|
61
|
+
this.archive = this.environmentalSelector.reduceEquals(this.environmentalSelector.chooseNonDominated(population.concat(offspring).concat(this.archive)).individuals);
|
|
62
|
+
console.log("Population before enviromental selection: ", population.length, "Population after adding offspring: ", population.length + offspring.length, "Archive size: ", this.archive.length);
|
|
63
|
+
return this.environmentalSelector.apply(population.concat(offspring), population.length);
|
|
64
|
+
// this.archive = this.environmentalSelector.chooseSurvivors(population, offspring, population.length);
|
|
65
|
+
// return this.archive;
|
|
66
|
+
}
|
|
67
|
+
choose(population) {
|
|
68
|
+
return this.archive;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.PortfolioSearch = PortfolioSearch;
|
|
72
|
+
//# sourceMappingURL=PortfolioSearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PortfolioSearch.js","sourceRoot":"","sources":["../../../../src/optimization/search/portfolio/PortfolioSearch.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,sFAA6F;AAG7F,iFAA+E;AAC/E,+DAA4D;AAC5D,wEAAqE;AAErE,MAAa,eAAgB,SAAQ,+DAAoG;IAMvI,YAAY,KAAsB,EAAE,SAA4D,EAAE,KAA+D,EAAE,SAAgC;QACjM,KAAK,CAAC,SAAS,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;QAL7B,YAAO,GAA+C,EAAE,CAAC;QAM/D,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,uCAAkB,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,CAAC,qBAAqB,GAAG,IAAI,wCAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACrE,CAAC;IAEe,QAAQ,CAAC,UAAsD;;YAC7E,KAAK,IAAI,UAAU,IAAI,UAAU;gBAC/B,IAAI,UAAU,CAAC,OAAO,KAAK,SAAS,IAAI,UAAU,CAAC,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;oBACxF,IAAI,aAAa,GAAa,EAAE,CAAC;oBACjC,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;wBAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;wBACvC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBAC5B,CAAC;oBAC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AAC,CAAC,CAAC,CAAC;QAC9E,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAES,OAAO,CAAC,UAAsD,EAAE,SAAqD,EAAE,OAAe;QAC9I,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;QACrK,OAAO,CAAC,GAAG,CAAC,4CAA4C,EAAE,UAAU,CAAC,MAAM,EAAE,qCAAqC,EAAE,UAAU,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEjM,OAAO,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;QACzF,uGAAuG;QACvG,uBAAuB;IACzB,CAAC;IAES,MAAM,CAAC,UAAsD;QACrE,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AA7DD,0CA6DC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Space } from '../Space';
|
|
2
|
+
export interface PorfolioRestrictions {
|
|
3
|
+
constraints: {
|
|
4
|
+
minWeigth: number;
|
|
5
|
+
maxWeight: number;
|
|
6
|
+
}[];
|
|
7
|
+
groupedConstraints: {
|
|
8
|
+
constraintIndices: number[];
|
|
9
|
+
minWeight: number;
|
|
10
|
+
maxWeight: number;
|
|
11
|
+
}[];
|
|
12
|
+
}
|
|
13
|
+
export declare class PortfolioSpace implements Space<number[]> {
|
|
14
|
+
private maxIterations;
|
|
15
|
+
private tolerance;
|
|
16
|
+
private gradient;
|
|
17
|
+
private groupGradient;
|
|
18
|
+
private restrictions;
|
|
19
|
+
constructor(restrictions: PorfolioRestrictions, maxIterations?: number, tolerance?: number, gradient?: number, groupGradient?: number);
|
|
20
|
+
equals(one: number[], two: number[]): boolean;
|
|
21
|
+
getRestrictions(): PorfolioRestrictions;
|
|
22
|
+
generateMany(count: number): number[][];
|
|
23
|
+
generateOne(): number[];
|
|
24
|
+
repairMany(population: number[][]): number[][];
|
|
25
|
+
repair(individual: number[]): number[];
|
|
26
|
+
private repairGroupConstraints;
|
|
27
|
+
private decreaseGroupWeights;
|
|
28
|
+
private increaseGroupeWeights;
|
|
29
|
+
private applyBoxConstraints;
|
|
30
|
+
private checkRestrictions;
|
|
31
|
+
private normalize;
|
|
32
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PortfolioSpace = void 0;
|
|
4
|
+
class PortfolioSpace {
|
|
5
|
+
constructor(restrictions, maxIterations = 500, tolerance = 1e-7, gradient = 0.6, groupGradient = 0.9) {
|
|
6
|
+
this.maxIterations = maxIterations;
|
|
7
|
+
this.tolerance = tolerance;
|
|
8
|
+
this.gradient = gradient;
|
|
9
|
+
this.groupGradient = groupGradient;
|
|
10
|
+
this.restrictions = restrictions;
|
|
11
|
+
}
|
|
12
|
+
equals(one, two) {
|
|
13
|
+
for (let i = 0; i < one.length; i++)
|
|
14
|
+
if (Math.abs(one[i] - two[i]) > 1e-4)
|
|
15
|
+
return false;
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
getRestrictions() {
|
|
19
|
+
return this.restrictions;
|
|
20
|
+
}
|
|
21
|
+
generateMany(count) {
|
|
22
|
+
let porforlios = [];
|
|
23
|
+
for (let i = 0; i < count; i++)
|
|
24
|
+
porforlios.push(this.generateOne());
|
|
25
|
+
return porforlios;
|
|
26
|
+
}
|
|
27
|
+
generateOne() {
|
|
28
|
+
let portfolio = [];
|
|
29
|
+
for (let constraint of this.restrictions.constraints)
|
|
30
|
+
portfolio.push(Math.random() * (constraint.maxWeight - constraint.minWeigth) + constraint.minWeigth);
|
|
31
|
+
return this.repair(portfolio);
|
|
32
|
+
}
|
|
33
|
+
repairMany(population) {
|
|
34
|
+
return population.map(individual => this.repair(individual));
|
|
35
|
+
}
|
|
36
|
+
repair(individual) {
|
|
37
|
+
individual = this.normalize(individual);
|
|
38
|
+
for (let iter = 1; iter <= this.maxIterations && !this.checkRestrictions(individual); iter++) {
|
|
39
|
+
individual = this.applyBoxConstraints(individual);
|
|
40
|
+
individual = this.normalize(individual);
|
|
41
|
+
if (this.restrictions.groupedConstraints.length > 0) {
|
|
42
|
+
individual = this.repairGroupConstraints(individual);
|
|
43
|
+
individual = this.normalize(individual);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return individual;
|
|
47
|
+
}
|
|
48
|
+
repairGroupConstraints(currentWeights) {
|
|
49
|
+
const current = [...currentWeights];
|
|
50
|
+
for (const group of this.restrictions.groupedConstraints) {
|
|
51
|
+
const groupSum = group.constraintIndices.reduce((sum, index) => sum + current[index], 0);
|
|
52
|
+
if (groupSum < group.minWeight - this.tolerance) {
|
|
53
|
+
this.increaseGroupeWeights(current, group, groupSum);
|
|
54
|
+
}
|
|
55
|
+
else if (groupSum > group.maxWeight + this.tolerance) {
|
|
56
|
+
this.decreaseGroupWeights(current, group, groupSum);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return current;
|
|
60
|
+
}
|
|
61
|
+
decreaseGroupWeights(current, group, groupSum) {
|
|
62
|
+
let excess = groupSum - group.maxWeight;
|
|
63
|
+
if (excess * this.groupGradient > this.tolerance)
|
|
64
|
+
excess *= this.groupGradient;
|
|
65
|
+
const availableDecrease = group.constraintIndices.map(index => current[index] - this.restrictions.constraints[index].minWeigth);
|
|
66
|
+
const totalAvailable = availableDecrease.reduce((sum, val) => sum + val, 0);
|
|
67
|
+
if (totalAvailable > excess) {
|
|
68
|
+
for (let j = 0; j < group.constraintIndices.length; j++) {
|
|
69
|
+
const idx = group.constraintIndices[j];
|
|
70
|
+
const proportion = availableDecrease[j] / totalAvailable;
|
|
71
|
+
current[idx] -= proportion * excess;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
for (const idx of group.constraintIndices) {
|
|
76
|
+
current[idx] = this.restrictions.constraints[idx].minWeigth;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
increaseGroupeWeights(currentWeight, group, groupSum) {
|
|
81
|
+
let deficit = group.minWeight - groupSum;
|
|
82
|
+
if (deficit * this.groupGradient > this.tolerance)
|
|
83
|
+
deficit *= this.groupGradient;
|
|
84
|
+
const availableIncrease = group.constraintIndices.map(index => this.restrictions.constraints[index].maxWeight - currentWeight[index]);
|
|
85
|
+
const totalAvailable = availableIncrease.reduce((sum, val) => sum + val, 0);
|
|
86
|
+
if (totalAvailable > deficit) {
|
|
87
|
+
for (let j = 0; j < group.constraintIndices.length; j++) {
|
|
88
|
+
const idx = group.constraintIndices[j];
|
|
89
|
+
const proportion = availableIncrease[j] / totalAvailable;
|
|
90
|
+
currentWeight[idx] += proportion * deficit;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
for (const idx of group.constraintIndices) {
|
|
95
|
+
currentWeight[idx] = this.restrictions.constraints[idx].maxWeight;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
applyBoxConstraints(currentWeights) {
|
|
100
|
+
return currentWeights.map((weight, index) => {
|
|
101
|
+
const min = this.restrictions.constraints[index].minWeigth;
|
|
102
|
+
const max = this.restrictions.constraints[index].maxWeight;
|
|
103
|
+
if (weight < min) {
|
|
104
|
+
let diference = (min - weight) * this.gradient;
|
|
105
|
+
return diference < this.tolerance ? min : weight + diference;
|
|
106
|
+
}
|
|
107
|
+
else if (weight > max) {
|
|
108
|
+
let diference = (weight - max) * this.gradient;
|
|
109
|
+
return diference < this.tolerance ? max : weight - diference;
|
|
110
|
+
}
|
|
111
|
+
return weight;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
checkRestrictions(individual) {
|
|
115
|
+
for (let i = 0; i < individual.length; i++)
|
|
116
|
+
if (individual[i] < this.restrictions.constraints[i].minWeigth - this.tolerance || individual[i] > this.restrictions.constraints[i].maxWeight + this.tolerance)
|
|
117
|
+
return false;
|
|
118
|
+
for (let group of this.restrictions.groupedConstraints) {
|
|
119
|
+
let groupSum = group.constraintIndices.reduce((sum, index) => sum + individual[index], 0);
|
|
120
|
+
if (groupSum < group.minWeight - this.tolerance || groupSum > group.maxWeight + this.tolerance)
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
normalize(weights) {
|
|
126
|
+
const total = weights.reduce((sum, weight) => sum + weight, 0);
|
|
127
|
+
return weights.map(weight => weight / total);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.PortfolioSpace = PortfolioSpace;
|
|
131
|
+
//# sourceMappingURL=PortfolioSpace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PortfolioSpace.js","sourceRoot":"","sources":["../../../../src/optimization/search/portfolio/PortfolioSpace.ts"],"names":[],"mappings":";;;AAcA,MAAa,cAAc;IAOzB,YAAY,YAAkC,EAAE,gBAAwB,GAAG,EAAE,YAAoB,IAAI,EAAE,WAAmB,GAAG,EAAE,gBAAwB,GAAG;QACxJ,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAEM,MAAM,CAAC,GAAa,EAAE,GAAa;QACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,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AAG,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS;gBAAE,OAAO,KAAK,CAAC;QAC/G,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,SAAS,CAAC,OAAiB;QACjC,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;QAC/D,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;IAC/C,CAAC;CACF;AApID,wCAoIC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface IAssetConstraint {
|
|
2
|
+
assetId: number;
|
|
3
|
+
asset: string;
|
|
4
|
+
allocation?: number;
|
|
5
|
+
constraint: {
|
|
6
|
+
minWeight: number;
|
|
7
|
+
maxWeight: number;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface IGroupedConstraint {
|
|
11
|
+
constraintIndices: number[];
|
|
12
|
+
minWeight: number;
|
|
13
|
+
maxWeight: number;
|
|
14
|
+
}
|
|
15
|
+
export interface IPortfolioSettings {
|
|
16
|
+
constraints: IAssetConstraint[];
|
|
17
|
+
groupedConstraints: IGroupedConstraint[];
|
|
18
|
+
isValid?: boolean;
|
|
19
|
+
validationMessage?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface IPortfolioData {
|
|
22
|
+
businessId: number;
|
|
23
|
+
userId: number;
|
|
24
|
+
type: string;
|
|
25
|
+
settings: IPortfolioSettings;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PortfolioTypes.js","sourceRoot":"","sources":["../../../../src/optimization/search/portfolio/PortfolioTypes.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IMarketData } from '../../../../crud/MarketDataManager';
|
|
2
|
+
import { Order } from '../../../../sort/Order';
|
|
3
|
+
import { Individual } from '../../../population/Individual';
|
|
4
|
+
import { Goal } from '../../Goal';
|
|
5
|
+
import { IPortfolioData } from '../PortfolioTypes';
|
|
6
|
+
export declare class ReturnGoal extends Goal<Individual<number[], number[], number[]>, number> {
|
|
7
|
+
private marketData;
|
|
8
|
+
private assetIds;
|
|
9
|
+
private cachedReturns;
|
|
10
|
+
constructor(order: Order<number>, portfolioData?: IPortfolioData, marketData?: IMarketData[]);
|
|
11
|
+
private normaliceMarketData;
|
|
12
|
+
private calculateDailyReturns;
|
|
13
|
+
private calculateAnnualReturn;
|
|
14
|
+
private getAssetReturn;
|
|
15
|
+
compute(individual: Individual<number[], number[], number[]>): number;
|
|
16
|
+
init(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ReturnGoal = void 0;
|
|
13
|
+
const Goal_1 = require("../../Goal");
|
|
14
|
+
class ReturnGoal extends Goal_1.Goal {
|
|
15
|
+
constructor(order, portfolioData, marketData) {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
super(order);
|
|
18
|
+
this.assetIds = [];
|
|
19
|
+
this.assetIds = ((_b = (_a = portfolioData === null || portfolioData === void 0 ? void 0 : portfolioData.settings) === null || _a === void 0 ? void 0 : _a.constraints) === null || _b === void 0 ? void 0 : _b.map(c => c.assetId)) || [];
|
|
20
|
+
this.marketData = this.normaliceMarketData(marketData);
|
|
21
|
+
this.cachedReturns = new Map();
|
|
22
|
+
}
|
|
23
|
+
normaliceMarketData(marketData) {
|
|
24
|
+
const marketDataByAsset = new Map();
|
|
25
|
+
for (const assetMarketData of marketData) {
|
|
26
|
+
const assetId = Array.isArray(assetMarketData.assetId) ? assetMarketData.assetId[0] : assetMarketData.assetId;
|
|
27
|
+
if (!marketDataByAsset.has(assetId))
|
|
28
|
+
marketDataByAsset.set(assetId, []);
|
|
29
|
+
marketDataByAsset.get(assetId).push(assetMarketData);
|
|
30
|
+
}
|
|
31
|
+
return marketDataByAsset;
|
|
32
|
+
}
|
|
33
|
+
calculateDailyReturns(prices) {
|
|
34
|
+
const returns = [];
|
|
35
|
+
for (let i = 1; i < prices.length; i++) {
|
|
36
|
+
returns.push(prices[i] / prices[i - 1] - 1);
|
|
37
|
+
}
|
|
38
|
+
return returns;
|
|
39
|
+
}
|
|
40
|
+
calculateAnnualReturn(dailyReturns) {
|
|
41
|
+
const avgDailyReturn = dailyReturns.reduce((sum, r) => sum + r, 0) / dailyReturns.length;
|
|
42
|
+
return Math.pow(1 + avgDailyReturn, 365) - 1;
|
|
43
|
+
}
|
|
44
|
+
getAssetReturn(assetId) {
|
|
45
|
+
if (!this.cachedReturns.has(assetId)) {
|
|
46
|
+
const data = this.marketData.get(assetId);
|
|
47
|
+
const sortedData = [...data].sort((a, b) => a.date - b.date);
|
|
48
|
+
const prices = sortedData.map(d => d.value);
|
|
49
|
+
const dailyReturns = this.calculateDailyReturns(prices);
|
|
50
|
+
const annualReturn = this.calculateAnnualReturn(dailyReturns);
|
|
51
|
+
this.cachedReturns.set(assetId, annualReturn);
|
|
52
|
+
return annualReturn;
|
|
53
|
+
}
|
|
54
|
+
return this.cachedReturns.get(assetId);
|
|
55
|
+
}
|
|
56
|
+
compute(individual) {
|
|
57
|
+
const weights = individual.genotype;
|
|
58
|
+
let portfolioReturn = 0;
|
|
59
|
+
for (let i = 0; i < weights.length; i++) {
|
|
60
|
+
const assetId = this.assetIds[i];
|
|
61
|
+
const assetReturn = this.getAssetReturn(assetId);
|
|
62
|
+
portfolioReturn += weights[i] * assetReturn;
|
|
63
|
+
}
|
|
64
|
+
return portfolioReturn;
|
|
65
|
+
}
|
|
66
|
+
init() {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.ReturnGoal = ReturnGoal;
|
|
72
|
+
//# sourceMappingURL=ReturnGoal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReturnGoal.js","sourceRoot":"","sources":["../../../../../src/optimization/search/portfolio/goals/ReturnGoal.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,qCAAkC;AAGlC,MAAa,UAAW,SAAQ,WAAsD;IAKpF,YAAY,KAAoB,EAAE,aAA8B,EAAE,UAA0B;;QAC1F,KAAK,CAAC,KAAK,CAAC,CAAC;QAJP,aAAQ,GAAa,EAAE,CAAC;QAK9B,IAAI,CAAC,QAAQ,GAAG,CAAA,MAAA,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,QAAQ,0CAAE,WAAW,0CAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAI,EAAE,CAAC;QAChF,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;QACvD,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;IACjC,CAAC;IACO,mBAAmB,CAAC,UAAqC;QAC/D,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAyB,CAAC;QAC3D,KAAK,MAAM,eAAe,IAAI,UAAW,EAAE,CAAC;YAC1C,MAAM,OAAO,GAAG,KAAK,CAAC,O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,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAK,GAAG,CAAC,CAAC,IAAK,CAAC,CAAC;YAChE,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAM,CAAC,CAAC;YAC7C,MAAM,YAAY,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;YACxD,MAAM,YAAY,GAAG,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;YAC9D,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YAC9C,OAAO,YAAY,CAAC;QACtB,CAAC;QACD,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAE,CAAC;IAC1C,CAAC;IAEM,OAAO,CAAC,UAAoD;QACjE,MAAM,OAAO,GAAG,UAAU,CAAC,QAAQ,CAAC;QACpC,IAAI,eAAe,GAAG,CAAC,CAAC;QAExB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YACjC,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YACjD,eAAe,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;QAC9C,CAAC;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;IAEY,IAAI;;QACjB,CAAC;KAAA;CACF;AA9DD,gCA8DC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IMarketData } from '../../../../crud/MarketDataManager';
|
|
2
|
+
import { Order } from '../../../../sort/Order';
|
|
3
|
+
import { Individual } from '../../../population/Individual';
|
|
4
|
+
import { Goal } from '../../Goal';
|
|
5
|
+
import { IPortfolioData } from '../PortfolioTypes';
|
|
6
|
+
export declare class VolatilityGoal extends Goal<Individual<number[], number[], number[]>, number> {
|
|
7
|
+
private marketData;
|
|
8
|
+
private assetIds;
|
|
9
|
+
private covarianceMatrix;
|
|
10
|
+
constructor(order: Order<number>, portfolioData?: IPortfolioData, marketData?: IMarketData[]);
|
|
11
|
+
private normalizeMarketData;
|
|
12
|
+
private calculateDailyReturns;
|
|
13
|
+
private calculateCovariance;
|
|
14
|
+
private buildCovarianceMatrix;
|
|
15
|
+
compute(individual: Individual<number[], number[], number[]>): number;
|
|
16
|
+
init(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.VolatilityGoal = void 0;
|
|
13
|
+
const Goal_1 = require("../../Goal");
|
|
14
|
+
class VolatilityGoal extends Goal_1.Goal {
|
|
15
|
+
constructor(order, portfolioData, marketData) {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
super(order);
|
|
18
|
+
this.assetIds = [];
|
|
19
|
+
this.covarianceMatrix = [];
|
|
20
|
+
this.assetIds = ((_b = (_a = portfolioData === null || portfolioData === void 0 ? void 0 : portfolioData.settings) === null || _a === void 0 ? void 0 : _a.constraints) === null || _b === void 0 ? void 0 : _b.map(c => c.assetId)) || [];
|
|
21
|
+
this.marketData = this.normalizeMarketData(marketData);
|
|
22
|
+
if (this.assetIds.length > 0 && this.marketData.size > 0)
|
|
23
|
+
this.buildCovarianceMatrix();
|
|
24
|
+
}
|
|
25
|
+
normalizeMarketData(marketData) {
|
|
26
|
+
const marketDataByAsset = new Map();
|
|
27
|
+
if (!marketData)
|
|
28
|
+
return marketDataByAsset;
|
|
29
|
+
for (const point of marketData) {
|
|
30
|
+
const assetId = Array.isArray(point.assetId) ? point.assetId[0] : point.assetId;
|
|
31
|
+
if (!marketDataByAsset.has(assetId)) {
|
|
32
|
+
marketDataByAsset.set(assetId, []);
|
|
33
|
+
}
|
|
34
|
+
marketDataByAsset.get(assetId).push(point);
|
|
35
|
+
}
|
|
36
|
+
return marketDataByAsset;
|
|
37
|
+
}
|
|
38
|
+
calculateDailyReturns(prices) {
|
|
39
|
+
const returns = [];
|
|
40
|
+
for (let i = 1; i < prices.length; i++) {
|
|
41
|
+
returns.push(prices[i] / prices[i - 1] - 1);
|
|
42
|
+
}
|
|
43
|
+
return returns;
|
|
44
|
+
}
|
|
45
|
+
calculateCovariance(returns1, returns2) {
|
|
46
|
+
const limitedArraySize = Math.min(returns1.length, returns2.length);
|
|
47
|
+
const mean1 = returns1.reduce((s, returnValue) => s + returnValue, 0) / limitedArraySize;
|
|
48
|
+
const mean2 = returns2.reduce((s, returnValue) => s + returnValue, 0) / limitedArraySize;
|
|
49
|
+
let covariance = 0;
|
|
50
|
+
for (let i = 0; i < limitedArraySize; i++) {
|
|
51
|
+
covariance += (returns1[i] - mean1) * (returns2[i] - mean2);
|
|
52
|
+
}
|
|
53
|
+
return covariance / limitedArraySize;
|
|
54
|
+
}
|
|
55
|
+
buildCovarianceMatrix() {
|
|
56
|
+
var _a;
|
|
57
|
+
const totalAssets = this.assetIds.length;
|
|
58
|
+
const returnsMatrix = [];
|
|
59
|
+
for (const assetId of this.assetIds) {
|
|
60
|
+
const data = this.marketData.get(assetId);
|
|
61
|
+
if (!data) {
|
|
62
|
+
returnsMatrix.push([]);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const sorted = [...data].sort((a, b) => a.date - b.date);
|
|
66
|
+
const prices = (_a = sorted.map(priceData => priceData.value)) !== null && _a !== void 0 ? _a : [];
|
|
67
|
+
returnsMatrix.push(this.calculateDailyReturns(prices));
|
|
68
|
+
}
|
|
69
|
+
this.covarianceMatrix = [];
|
|
70
|
+
for (let i = 0; i < totalAssets; i++) {
|
|
71
|
+
this.covarianceMatrix[i] = [];
|
|
72
|
+
for (let j = 0; j < totalAssets; j++) {
|
|
73
|
+
const cov = this.calculateCovariance(returnsMatrix[i], returnsMatrix[j]);
|
|
74
|
+
this.covarianceMatrix[i][j] = cov * 365;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
compute(individual) {
|
|
79
|
+
const weights = individual.genotype;
|
|
80
|
+
let variance = 0;
|
|
81
|
+
for (let i = 0; i < weights.length; i++) {
|
|
82
|
+
for (let j = 0; j < weights.length; j++) {
|
|
83
|
+
variance += weights[i] * weights[j] * this.covarianceMatrix[i][j];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return Math.sqrt(variance);
|
|
87
|
+
}
|
|
88
|
+
init() {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.VolatilityGoal = VolatilityGoal;
|
|
93
|
+
//# sourceMappingURL=VolatilityGoal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VolatilityGoal.js","sourceRoot":"","sources":["../../../../../src/optimization/search/portfolio/goals/VolatilityGoal.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,qCAAkC;AAGlC,MAAa,cAAe,SAAQ,WAAsD;IAKxF,YAAY,KAAoB,EAAE,aAA8B,EAAE,UAA0B;;QAC1F,KAAK,CAAC,KAAK,CAAC,C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EAAE,EAAE,CAAC;YACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACxC,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACpE,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAEY,IAAI;8DAAmB,CAAC;KAAA;CACtC;AAzFD,wCAyFC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Individual } from '../../../population/Individual';
|
|
2
|
+
import { Goal } from '../../Goal';
|
|
3
|
+
import { Space } from '../../Space';
|
|
4
|
+
export declare class EnvironmentSelector<G, P, F> {
|
|
5
|
+
private goals;
|
|
6
|
+
private growthRate;
|
|
7
|
+
private maxPopulation;
|
|
8
|
+
private space;
|
|
9
|
+
constructor(space: Space<G>, goals: Goal<Individual<G, P, F[]>, F>[], growthRate?: number, maxPopulation?: number);
|
|
10
|
+
reduceEquals(population: Individual<G, P, F[]>[]): Individual<G, P, F[]>[];
|
|
11
|
+
private isUnique;
|
|
12
|
+
chooseNonDominated(population: Individual<G, P, F[]>[]): {
|
|
13
|
+
indexes: number[];
|
|
14
|
+
individuals: Individual<G, P, F[]>[];
|
|
15
|
+
};
|
|
16
|
+
private isDominated;
|
|
17
|
+
private dominates;
|
|
18
|
+
private distance;
|
|
19
|
+
private truncate;
|
|
20
|
+
apply(population: Individual<G, P, F[]>[], currentSize: number): Individual<G, P, F[]>[];
|
|
21
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnvironmentSelector = void 0;
|
|
4
|
+
class EnvironmentSelector {
|
|
5
|
+
constructor(space, goals, growthRate = 1.1, maxPopulation = 200) {
|
|
6
|
+
this.space = space;
|
|
7
|
+
this.goals = goals;
|
|
8
|
+
this.growthRate = growthRate;
|
|
9
|
+
this.maxPopulation = maxPopulation;
|
|
10
|
+
}
|
|
11
|
+
reduceEquals(population) {
|
|
12
|
+
let uniquePopulation = [];
|
|
13
|
+
for (let individual of population)
|
|
14
|
+
if (this.isUnique(individual, uniquePopulation))
|
|
15
|
+
uniquePopulation.push(individual);
|
|
16
|
+
return uniquePopulation;
|
|
17
|
+
}
|
|
18
|
+
isUnique(individual, uniquePopulation) {
|
|
19
|
+
for (let uniqueIndividual of uniquePopulation)
|
|
20
|
+
if (this.space.equals(individual.genotype, uniqueIndividual.genotype))
|
|
21
|
+
return false;
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
chooseNonDominated(population) {
|
|
25
|
+
let result = { indexes: [], individuals: [] };
|
|
26
|
+
for (let i = 0; i < population.length; i++)
|
|
27
|
+
if (!this.isDominated(i, population)) {
|
|
28
|
+
result.indexes.push(i);
|
|
29
|
+
result.individuals.push(population[i]);
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
isDominated(i, population) {
|
|
34
|
+
for (let j = 0; j < population.length; j++)
|
|
35
|
+
if (i !== j && this.dominates(population[j], population[i]))
|
|
36
|
+
return true;
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
dominates(first, second) {
|
|
40
|
+
let isBetterInAtLeastOne = false;
|
|
41
|
+
for (let i = 0; i < this.goals.length; i++) {
|
|
42
|
+
const comparison = this.goals[i].getOrder().compare(first.fitness[i], second.fitness[i]);
|
|
43
|
+
if (comparison < 0)
|
|
44
|
+
return false;
|
|
45
|
+
if (comparison > 0)
|
|
46
|
+
isBetterInAtLeastOne = true;
|
|
47
|
+
}
|
|
48
|
+
return isBetterInAtLeastOne;
|
|
49
|
+
}
|
|
50
|
+
distance(ind1, ind2) {
|
|
51
|
+
let sum = 0;
|
|
52
|
+
for (let i = 0; i < ind1.fitness.length; i++) {
|
|
53
|
+
const diff = ind1.fitness[i] - ind2.fitness[i];
|
|
54
|
+
sum += diff * diff;
|
|
55
|
+
}
|
|
56
|
+
return Math.sqrt(sum);
|
|
57
|
+
}
|
|
58
|
+
truncate(population, maxPopulationSize) {
|
|
59
|
+
while (population.length > maxPopulationSize) {
|
|
60
|
+
let minimumDistance = Infinity;
|
|
61
|
+
let toRemove = 0;
|
|
62
|
+
for (let i = 0; i < population.length; i++) {
|
|
63
|
+
let nearest = Infinity;
|
|
64
|
+
for (let j = 0; j < population.length; j++) {
|
|
65
|
+
if (i !== j) {
|
|
66
|
+
const distanceBetweenIndividuals = this.distance(population[i], population[j]);
|
|
67
|
+
if (distanceBetweenIndividuals < nearest)
|
|
68
|
+
nearest = distanceBetweenIndividuals;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (nearest < minimumDistance) {
|
|
72
|
+
minimumDistance = nearest;
|
|
73
|
+
toRemove = i;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
population.splice(toRemove, 1);
|
|
77
|
+
}
|
|
78
|
+
return population;
|
|
79
|
+
}
|
|
80
|
+
apply(population, currentSize) {
|
|
81
|
+
const target = Math.min(Math.floor(currentSize * this.growthRate), this.maxPopulation);
|
|
82
|
+
let nextPopulation = [];
|
|
83
|
+
while (nextPopulation.length < target && population.length > 0) {
|
|
84
|
+
let nonDominated = this.chooseNonDominated(population);
|
|
85
|
+
if (nextPopulation.length + nonDominated.individuals.length <= target) {
|
|
86
|
+
nextPopulation = nextPopulation.concat(this.reduceEquals(nonDominated.individuals));
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const needed = target - nextPopulation.length;
|
|
90
|
+
nextPopulation = nextPopulation.concat(this.truncate(this.reduceEquals(nonDominated.individuals), needed));
|
|
91
|
+
}
|
|
92
|
+
population = population.filter((_, i) => !nonDominated.indexes.includes(i));
|
|
93
|
+
}
|
|
94
|
+
return nextPopulation;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.EnvironmentSelector = EnvironmentSelector;
|
|
98
|
+
//# sourceMappingURL=EnviromentSelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnviromentSelector.js","sourceRoot":"","sources":["../../../../../src/optimization/search/portfolio/noDominanceSelector/EnviromentSelector.ts"],"names":[],"mappings":";;;AAIA,MAAa,mBAAmB;IAM9B,YAAY,KAAe,EAAE,KAAuC,EAAE,aAAqB,GAAG,EAAE,gBAAwB,GAAG;QACzH,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAEM,YAAY,CAAC,UAAmC;QACrD,IAAI,gBAAgB,GAA4B,EAAE,CAAC;QACnD,KAAK,IAAI,UAAU,IAAI,UAAU;YAC7B,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;gBAC3C,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1C,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAEO,QAAQ,CAAC,UAAiC,EAAE,gBAAyC;QAC3F,KAAK,IAAI,gBAAgB,IAAI,gBAAgB;YACzC,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,gBAAgB,CAAC,QAAQ,CAAC;gBACjE,OAAO,KAAK,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,kBAAkB,CAAC,UAAmC;QAC3D,IAAI,MAAM,GAAgE,EAAE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;QAC3G,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE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AAC;IACpB,CAAC;IAEM,KAAK,CAAC,UAAmC,EAAE,WAAmB;QACnE,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QACvF,IAAI,cAAc,GAA4B,EAAE,CAAC;QAEjD,OAAO,cAAc,CAAC,MAAM,GAAG,MAAM,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/D,IAAI,YAAY,GAAG,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;YAEvD,IAAI,cAAc,CAAC,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,MAAM,IAAI,MAAM,EAAE,CAAC;gBACtE,cAAc,GAAG,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC;YACtF,CAAC;iBAAM,CAAC;gBACN,MAAM,MAAM,GAAG,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC;gBAC9C,cAAc,GAAG,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YAC7G,CAAC;YAED,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9E,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AAvGD,kDAuGC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Individual } from '../../../population/Individual';
|
|
2
|
+
import { Goal } from '../../Goal';
|
|
3
|
+
export declare class TournamentSelector<G, P, F> {
|
|
4
|
+
private goals;
|
|
5
|
+
constructor(goals: Goal<Individual<G, P, F[]>, F>[]);
|
|
6
|
+
selectOne(population: Individual<G, P, F[]>[]): Individual<G, P, F[]>;
|
|
7
|
+
private selectParticipants;
|
|
8
|
+
private combat;
|
|
9
|
+
private selectRandomGoal;
|
|
10
|
+
private calculateStrength;
|
|
11
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TournamentSelector = void 0;
|
|
4
|
+
class TournamentSelector {
|
|
5
|
+
constructor(goals) {
|
|
6
|
+
this.goals = goals;
|
|
7
|
+
}
|
|
8
|
+
selectOne(population) {
|
|
9
|
+
const participants = this.selectParticipants(population, 4);
|
|
10
|
+
const semifinalists = [
|
|
11
|
+
this.combat(participants[0], participants[1]),
|
|
12
|
+
this.combat(participants[2], participants[3])
|
|
13
|
+
];
|
|
14
|
+
const winner = this.combat(semifinalists[0], semifinalists[1]);
|
|
15
|
+
return winner;
|
|
16
|
+
}
|
|
17
|
+
selectParticipants(population, count) {
|
|
18
|
+
const participants = [];
|
|
19
|
+
const indices = new Set();
|
|
20
|
+
while (indices.size < count) {
|
|
21
|
+
const randomIndex = Math.floor(Math.random() * population.length);
|
|
22
|
+
if (!indices.has(randomIndex)) {
|
|
23
|
+
indices.add(randomIndex);
|
|
24
|
+
participants.push(population[randomIndex]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return participants;
|
|
28
|
+
}
|
|
29
|
+
combat(first, second) {
|
|
30
|
+
const goalIndex = this.selectRandomGoal();
|
|
31
|
+
const strength = this.calculateStrength(first, second, goalIndex);
|
|
32
|
+
const random = Math.random();
|
|
33
|
+
const winner = random < strength ? first : second;
|
|
34
|
+
return winner;
|
|
35
|
+
}
|
|
36
|
+
selectRandomGoal() {
|
|
37
|
+
return Math.floor(Math.random() * this.goals.length);
|
|
38
|
+
}
|
|
39
|
+
calculateStrength(firstIndividual, secondIndividual, goalIndex) {
|
|
40
|
+
const firstValue = Math.abs(firstIndividual.fitness[goalIndex]);
|
|
41
|
+
const secondValue = Math.abs(secondIndividual.fitness[goalIndex]);
|
|
42
|
+
const total = firstValue + secondValue;
|
|
43
|
+
let strength = firstValue / total;
|
|
44
|
+
const goal = this.goals[goalIndex];
|
|
45
|
+
const isMinimization = goal.getOrder().compare(firstIndividual.fitness[goalIndex], secondIndividual.fitness[goalIndex]) > 0;
|
|
46
|
+
if (isMinimization)
|
|
47
|
+
strength = 1 - strength;
|
|
48
|
+
return strength;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.TournamentSelector = TournamentSelector;
|
|
52
|
+
//# sourceMappingURL=TournamentSelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TournamentSelector.js","sourceRoot":"","sources":["../../../../../src/optimization/search/portfolio/tournament/TournamentSelector.ts"],"names":[],"mappings":";;;AAGA,MAAa,kBAAkB;IAG7B,YAAY,KAAuC;QACjD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAEM,SAAS,CAAC,UAAmC;QAClD,MAAM,YAAY,GAAG,IAAI,CAAC,kBAAkB,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;QAC5D,MAAM,aAAa,GAAG;YACpB,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;YAC7C,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;SAC9C,CAAC;QACF,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/D,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,kBAAkB,CAAC,UAAmC,EAAE,KAAa;QAC3E,MAAM,YAAY,GAA4B,EAAE,CAAC;QACjD,MAAM,OAAO,GAAG,IAAI,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AAW,CAAC;QAEvC,IAAI,QAAQ,GAAG,UAAU,GAAG,KAAK,CAAC;QAClC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACnC,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC,OAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC,OAAQ,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC;QAE9H,IAAI,cAAc;YAAE,QAAQ,GAAG,CAAC,GAAG,QAAQ,CAAC;QAE5C,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAzDD,gDAyDC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Variation } from "../../variate/Variation";
|
|
2
|
+
import { PortfolioSpace } from "../PortfolioSpace";
|
|
3
|
+
export declare class PortfolioMutation extends Variation<number[]> {
|
|
4
|
+
constructor(space: PortfolioSpace);
|
|
5
|
+
arity(): number;
|
|
6
|
+
range_arity(): number;
|
|
7
|
+
protected variate(parents: number[][]): number[][];
|
|
8
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PortfolioMutation = void 0;
|
|
4
|
+
const Variation_1 = require("../../variate/Variation");
|
|
5
|
+
class PortfolioMutation extends Variation_1.Variation {
|
|
6
|
+
constructor(space) {
|
|
7
|
+
super(space);
|
|
8
|
+
}
|
|
9
|
+
arity() {
|
|
10
|
+
return 1;
|
|
11
|
+
}
|
|
12
|
+
range_arity() {
|
|
13
|
+
return 1;
|
|
14
|
+
}
|
|
15
|
+
variate(parents) {
|
|
16
|
+
let child = parents[0].slice();
|
|
17
|
+
let mutationProbability = 1.0 / child.length;
|
|
18
|
+
let restrictions = this.space.getRestrictions();
|
|
19
|
+
for (let i = 0; i < child.length; i++)
|
|
20
|
+
if (Math.random() < mutationProbability)
|
|
21
|
+
child[i] = (Math.random() * (restrictions.constraints[i].maxWeight - restrictions.constraints[i].minWeigth)) + restrictions.constraints[i].minWeigth;
|
|
22
|
+
return [child];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.PortfolioMutation = PortfolioMutation;
|
|
26
|
+
//# sourceMappingURL=PortfolioMutation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PortfolioMutation.js","sourceRoot":"","sources":["../../../../../src/optimization/search/portfolio/variate/PortfolioMutation.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAGpD,MAAa,iBAAkB,SAAQ,qBAAmB;IACtD,YAAY,KAAqB;QAC7B,KAAK,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IACM,KAAK;QACR,OAAO,CAAC,CAAC;IACb,CAAC;IACM,WAAW;QACd,OAAO,CAAC,CAAC;IACb,CAAC;IACS,OAAO,CAAC,OAAmB;QACjC,IAAI,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;QAC/B,IAAI,mBAAmB,GAAW,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;QACrD,IAAI,YAAY,GAAI,IAAI,CAAC,KAAwB,CAAC,eAAe,EAAE,CAAC;QACpE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;YACjC,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,mBAAmB;gBACnC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC7J,OAAO,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;CACJ;AAnBD,8CAmBC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Variation } from "../../variate/Variation";
|
|
2
|
+
import { PortfolioSpace } from "../PortfolioSpace";
|
|
3
|
+
export declare class PortfolioXOver extends Variation<number[]> {
|
|
4
|
+
constructor(space: PortfolioSpace);
|
|
5
|
+
arity(): number;
|
|
6
|
+
range_arity(): number;
|
|
7
|
+
protected variate(parents: number[][]): number[][];
|
|
8
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PortfolioXOver = void 0;
|
|
4
|
+
const Variation_1 = require("../../variate/Variation");
|
|
5
|
+
class PortfolioXOver extends Variation_1.Variation {
|
|
6
|
+
constructor(space) {
|
|
7
|
+
super(space);
|
|
8
|
+
}
|
|
9
|
+
arity() {
|
|
10
|
+
return 2;
|
|
11
|
+
}
|
|
12
|
+
range_arity() {
|
|
13
|
+
return 2;
|
|
14
|
+
}
|
|
15
|
+
variate(parents) {
|
|
16
|
+
let point = Math.floor(Math.random() * parents[0].length);
|
|
17
|
+
let child1 = parents[0].slice(0, point).concat(parents[1].slice(point));
|
|
18
|
+
let child2 = parents[1].slice(0, point).concat(parents[0].slice(point));
|
|
19
|
+
return [child1, child2];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.PortfolioXOver = PortfolioXOver;
|
|
23
|
+
//# sourceMappingURL=PortfolioXOver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PortfolioXOver.js","sourceRoot":"","sources":["../../../../../src/optimization/search/portfolio/variate/PortfolioXOver.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAGpD,MAAa,cAAe,SAAQ,qBAAmB;IACnD,YAAY,KAAqB;QAC7B,KAAK,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IAEM,KAAK;QACR,OAAO,CAAC,CAAC;IACb,CAAC;IAEM,WAAW;QACd,OAAO,CAAC,CAAC;IACb,CAAC;IAES,OAAO,CAAC,OAAmB;QACjC,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAC1D,IAAI,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACxE,IAAI,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACxE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC;CACJ;AAnBD,wCAmBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Space } from "../Space";
|
|
2
|
+
export declare abstract class Variation<T> {
|
|
3
|
+
protected space: Space<T>;
|
|
4
|
+
constructor(space: Space<T>);
|
|
5
|
+
abstract arity(): number;
|
|
6
|
+
abstract range_arity(): number;
|
|
7
|
+
apply(parents: T[]): T[];
|
|
8
|
+
protected abstract variate(parents: T[]): T[];
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Variation = void 0;
|
|
4
|
+
class Variation {
|
|
5
|
+
constructor(space) {
|
|
6
|
+
this.space = space;
|
|
7
|
+
}
|
|
8
|
+
apply(parents) {
|
|
9
|
+
return this.space.repairMany(this.variate(parents));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.Variation = Variation;
|
|
13
|
+
//# sourceMappingURL=Variation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Variation.js","sourceRoot":"","sources":["../../../../src/optimization/search/variate/Variation.ts"],"names":[],"mappings":";;;AAEA,MAAsB,SAAS;IAG3B,YAAY,KAAe;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAKM,KAAK,CAAC,OAAY;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC;CAGJ;AAfD,8BAeC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Order.js","sourceRoot":"","sources":["../../src/sort/Order.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReversedOrder = void 0;
|
|
4
|
+
class ReversedOrder {
|
|
5
|
+
constructor(originalOrder) {
|
|
6
|
+
this.originalOrder = originalOrder;
|
|
7
|
+
}
|
|
8
|
+
compare(one, two) {
|
|
9
|
+
return this.originalOrder.compare(two, one);
|
|
10
|
+
}
|
|
11
|
+
equals(one, two) {
|
|
12
|
+
return this.originalOrder.equals(one, two);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.ReversedOrder = ReversedOrder;
|
|
16
|
+
//# sourceMappingURL=ReversedOrder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReversedOrder.js","sourceRoot":"","sources":["../../src/sort/ReversedOrder.ts"],"names":[],"mappings":";;;AAEA,MAAa,aAAa;IAGtB,YAAY,aAAuB;QAC/B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACvC,CAAC;IAEM,OAAO,CAAC,GAAM,EAAE,GAAM;QACzB,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAChD,CAAC;IAEM,MAAM,CAAC,GAAM,EAAE,GAAM;QACxB,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC/C,CAAC;CACJ;AAdD,sCAcC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RealOrder = void 0;
|
|
4
|
+
class RealOrder {
|
|
5
|
+
constructor(minimize) {
|
|
6
|
+
this.minimize = minimize !== null && minimize !== void 0 ? minimize : false;
|
|
7
|
+
}
|
|
8
|
+
compare(one, two) {
|
|
9
|
+
if (this.minimize)
|
|
10
|
+
return this.equals(one, two) ? 0 : (one < two ? 1 : -1);
|
|
11
|
+
return this.equals(one, two) ? 0 : (one < two ? -1 : 1);
|
|
12
|
+
}
|
|
13
|
+
equals(one, two) {
|
|
14
|
+
return Math.abs(one - two) < 1e-6; //Cami lo dejo en 1e-9
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.RealOrder = RealOrder;
|
|
18
|
+
//# sourceMappingURL=RealOrder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RealOrder.js","sourceRoot":"","sources":["../../../src/sort/real/RealOrder.ts"],"names":[],"mappings":";;;AAEA,MAAa,SAAS;IAGlB,YAAY,QAAkB;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,KAAK,CAAC;IACtC,CAAC;IAEM,OAAO,CAAC,GAAW,EAAE,GAAW;QACnC,IAAI,IAAI,CAAC,QAAQ;YACb,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC;IAEM,MAAM,CAAC,GAAW,EAAE,GAAW;QAClC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,sBAAsB;IAC7D,CAAC;CACJ;AAhBD,8BAgBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elemento-alpha-tools",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.22",
|
|
4
4
|
"description": "Librería para los servicios de elemento alpha",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -34,17 +34,17 @@
|
|
|
34
34
|
"@types/express": "^5.0.5",
|
|
35
35
|
"@types/jest": "^30.0.0",
|
|
36
36
|
"@types/morgan": "^1.9.9",
|
|
37
|
-
"@types/node": "^24.
|
|
37
|
+
"@types/node": "^24.10.1",
|
|
38
38
|
"jest": "^30.2.0",
|
|
39
|
-
"rimraf": "^6.0
|
|
39
|
+
"rimraf": "^6.1.0",
|
|
40
40
|
"ts-jest": "^29.4.5",
|
|
41
41
|
"typescript": "^5.9.3"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"axios": "^1.13.
|
|
44
|
+
"axios": "^1.13.2",
|
|
45
45
|
"crypto-js": "^4.2.0",
|
|
46
46
|
"dotenv": "^17.2.3",
|
|
47
|
-
"itrm-tools": "^1.3.
|
|
47
|
+
"itrm-tools": "^1.3.22",
|
|
48
48
|
"morgan": "^1.10.0"
|
|
49
49
|
},
|
|
50
50
|
"optionalDependencies": {
|