qmwts 1.1.45 → 1.1.46

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/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import ArrayUtils from './utils/array-utils';
1
+ export { default as ArrayUtils } from './utils/array-utils';
2
+ export { default as FinanceUtils } from './utils/finance-utils';
3
+ export type { XIRREntity } from './utils/finance-utils';
2
4
  import Downloader from './utils/downloader';
3
5
  import NumberUtils from './utils/number-utils';
4
6
  import JsonUtils from './utils/json-utils';
@@ -9,4 +11,4 @@ import FileUtils from './utils/file-utils';
9
11
  import LocalDate from './class/local-date';
10
12
  import LocalDateTime from './class/local-date-time';
11
13
  import YearMonth from './class/year-month';
12
- export { ArrayUtils, Downloader, NumberUtils, JsonUtils, UUIDUtils, PrototypeUtils, RequestDataGenerator, FileUtils, LocalDate, LocalDateTime, YearMonth, };
14
+ export { Downloader, NumberUtils, JsonUtils, UUIDUtils, PrototypeUtils, RequestDataGenerator, FileUtils, LocalDate, LocalDateTime, YearMonth, };
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.FileUtils = exports.RequestDataGenerator = exports.PrototypeUtils = exports.UUIDUtils = exports.JsonUtils = exports.NumberUtils = exports.Downloader = exports.ArrayUtils = void 0;
3
+ exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.FileUtils = exports.RequestDataGenerator = exports.PrototypeUtils = exports.UUIDUtils = exports.JsonUtils = exports.NumberUtils = exports.Downloader = exports.FinanceUtils = exports.ArrayUtils = void 0;
4
4
  // https://www.jianshu.com/p/8fa2c50720e4
5
5
  var array_utils_1 = require("./utils/array-utils");
6
- exports.ArrayUtils = array_utils_1.default;
6
+ Object.defineProperty(exports, "ArrayUtils", { enumerable: true, get: function () { return array_utils_1.default; } });
7
+ var finance_utils_1 = require("./utils/finance-utils");
8
+ Object.defineProperty(exports, "FinanceUtils", { enumerable: true, get: function () { return finance_utils_1.default; } });
7
9
  var downloader_1 = require("./utils/downloader");
8
10
  exports.Downloader = downloader_1.default;
9
11
  var number_utils_1 = require("./utils/number-utils");
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ XIRR(entities: XIRREntity[], guess?: number): number | null;
3
+ };
4
+ export default _default;
5
+ export interface XIRREntity {
6
+ date: Date;
7
+ amount: number;
8
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ // 货币相关工具类
13
+ exports.default = {
14
+ // https://support.microsoft.com/zh-cn/office/xirr-%E5%87%BD%E6%95%B0-de1242ec-6477-445b-b11b-a303ad9adc9d
15
+ // 不定期投资收益率
16
+ XIRR: function (entities, guess) {
17
+ if (guess === void 0) { guess = 0.1; }
18
+ // 按照日期从小到大排列
19
+ var list = __spreadArray([], entities, true).sort(function (a, b) { return a.date.getTime() - b.date.getTime(); });
20
+ var d0 = list[0].date.getTime();
21
+ var npv = function (rate) {
22
+ var total = 0;
23
+ for (var i = list.length - 1; i >= 0; i--) {
24
+ var daysDiff = (list[i].date.getTime() - d0) / (1000 * 3600 * 24);
25
+ total += list[i].amount / Math.pow(1 + rate, daysDiff / 365);
26
+ }
27
+ return total;
28
+ };
29
+ var epsilon = 1e-6; // 精度
30
+ var x0 = guess;
31
+ var x1;
32
+ var iteration = 0;
33
+ while (iteration < 100) {
34
+ var f0 = npv(x0);
35
+ var fPrime = (npv(x0 + epsilon) - f0) / epsilon;
36
+ x1 = x0 - f0 / fPrime;
37
+ if (Math.abs(x1 - x0) < epsilon)
38
+ return x1;
39
+ x0 = x1;
40
+ iteration++;
41
+ }
42
+ return null;
43
+ },
44
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qmwts",
3
- "version": "1.1.45",
3
+ "version": "1.1.46",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,6 +0,0 @@
1
- declare const _default: {
2
- isToday(date: Date): boolean;
3
- toDateString(date: Date): string;
4
- toDateTimeString(date: Date): string;
5
- };
6
- export default _default;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {
4
- isToday: function (date) {
5
- var today = new Date();
6
- return today.getFullYear() === date.getFullYear()
7
- && today.getMonth() === date.getMonth()
8
- && today.getDate() === date.getDate();
9
- },
10
- toDateString: function (date) {
11
- return '';
12
- },
13
- toDateTimeString: function (date) {
14
- return '';
15
- }
16
- };
File without changes
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Promise.resolve().then(function () {
3
- console.log(0);
4
- return Promise.resolve(4);
5
- }).then(function (res) {
6
- console.log(res);
7
- });
8
- Promise.resolve().then(function () {
9
- console.log(1);
10
- }).then(function () {
11
- console.log(2);
12
- }).then(function () {
13
- console.log(3);
14
- }).then(function () {
15
- console.log(5);
16
- console.log(6);
17
- });