@quantform/core 0.7.17 → 0.7.19

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.
@@ -1,5 +1,5 @@
1
1
  import { BacktestStorage } from './use-backtest';
2
- export declare const useBacktestQueryBuffer: <T>(storage: BacktestStorage<T>) => {
2
+ export declare function useBacktestQueryBuffer<T>(storage: BacktestStorage<T>): {
3
3
  size(): number;
4
4
  peek(): {
5
5
  timestamp: number;
@@ -1 +1 @@
1
- {"version":3,"file":"use-backtest-query-buffer.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest-query-buffer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,eAAO,MAAM,sBAAsB;;;mBAGJ,MAAM;;;;mBAAN,MAAM;;;;;CAwCnC,CAAC"}
1
+ {"version":3,"file":"use-backtest-query-buffer.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest-query-buffer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjD,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;;;mBAGtC,MAAM;iBAAW,CAAC;;;mBAAlB,MAAM;iBAAW,CAAC;;;;EAwChD"}
@@ -10,11 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.useBacktestQueryBuffer = void 0;
13
- const replay_1 = require("../replay");
14
13
  const storage_1 = require("../storage");
15
- const with_memo_1 = require("../with-memo");
16
- exports.useBacktestQueryBuffer = (0, with_memo_1.withMemo)((storage) => {
17
- const { from, to } = (0, replay_1.useReplayOptions)();
14
+ const use_backtest_options_1 = require("./use-backtest-options");
15
+ function useBacktestQueryBuffer(storage) {
16
+ const { from, to } = (0, use_backtest_options_1.useBacktestOptions)();
18
17
  let page = [];
19
18
  let index = 0;
20
19
  let completed = false;
@@ -49,4 +48,5 @@ exports.useBacktestQueryBuffer = (0, with_memo_1.withMemo)((storage) => {
49
48
  });
50
49
  }
51
50
  };
52
- });
51
+ }
52
+ exports.useBacktestQueryBuffer = useBacktestQueryBuffer;
@@ -5,6 +5,7 @@ export type BacktestStorageQuery<V> = {
5
5
  sync: <T extends QueryObjectType<K>, K extends QueryObject>(query: Query<InferQueryObject<T>> & {
6
6
  where: {
7
7
  timestamp: {
8
+ type: 'between';
8
9
  min: number;
9
10
  max: number;
10
11
  };
@@ -1 +1 @@
1
- {"version":3,"file":"use-backtest-storage.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,eAAe,EAGhB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI;IACpC,IAAI,EAAE,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EACxD,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG;QAClC,KAAK,EAAE;YAAE,SAAS,EAAE;gBAAE,GAAG,EAAE,MAAM,CAAC;gBAAC,GAAG,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,CAAC;KACpD,EACD,OAAO,EAAE;QAAE,IAAI,EAAE,CAAC,OAAO,EAAE;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,CAAC,CAAA;SAAE,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,KAC/E,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AASF,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,CAAC,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,CAAC,GAChC,eAAe,CAAC,CAAC,CAAC,CAgDpB"}
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.useBacktestStorage = void 0;
13
+ const hash_code_1 = require("../hash-code");
13
14
  const storage_1 = require("../storage");
14
15
  const storageIndexObject = storage_1.Storage.createObject('index://range', {
15
16
  timestamp: 'number',
@@ -24,12 +25,13 @@ function useBacktestStorage(uri, { sync }) {
24
25
  timestamp: 'number',
25
26
  payload: 'string'
26
27
  });
28
+ const id = (0, hash_code_1.hashCode)(storageObjectKey);
27
29
  return {
28
30
  query(query) {
29
31
  return __awaiter(this, void 0, void 0, function* () {
30
32
  const [index] = yield storage.query(storageIndexObject, {
31
33
  limit: 1,
32
- where: { uri: (0, storage_1.eq)(storageObjectKey) }
34
+ where: { timestamp: (0, storage_1.eq)(id) }
33
35
  });
34
36
  const { min, max } = query.where.timestamp;
35
37
  if (!index || min < index.min || max > index.max) {
@@ -45,7 +47,7 @@ function useBacktestStorage(uri, { sync }) {
45
47
  });
46
48
  yield storage.save(storageIndexObject, [
47
49
  {
48
- timestamp: 0,
50
+ timestamp: id,
49
51
  max,
50
52
  min,
51
53
  uri: storageObjectKey
@@ -4,6 +4,7 @@ export interface BacktestStorage<V> {
4
4
  query(query: Query<QueryObject> & {
5
5
  where: {
6
6
  timestamp: {
7
+ type: 'between';
7
8
  min: number;
8
9
  max: number;
9
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"use-backtest.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKlD,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,KAAK,CACH,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,GAA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
+ export declare function hashCode(str: string): number;
2
+ //# sourceMappingURL=hash-code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-code.d.ts","sourceRoot":"","sources":["../src/hash-code.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,UAOnC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hashCode = void 0;
4
+ function hashCode(str) {
5
+ let hash = 0;
6
+ for (let i = 0; i < str.length; i++) {
7
+ hash = (hash << 5) - hash + str.charCodeAt(i);
8
+ hash |= 0;
9
+ }
10
+ return hash;
11
+ }
12
+ exports.hashCode = hashCode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantform/core",
3
- "version": "0.7.17",
3
+ "version": "0.7.19",
4
4
  "license": "MIT",
5
5
  "author": "Mateusz Majchrzak",
6
6
  "description": "Node.js library for building systematic trading strategies in reactive way.",
@@ -1,11 +1,10 @@
1
- import { useReplayOptions } from '@lib/replay';
2
1
  import { between } from '@lib/storage';
3
- import { withMemo } from '@lib/with-memo';
4
2
 
5
3
  import { BacktestStorage } from './use-backtest';
4
+ import { useBacktestOptions } from './use-backtest-options';
6
5
 
7
- export const useBacktestQueryBuffer = withMemo(<T>(storage: BacktestStorage<T>) => {
8
- const { from, to } = useReplayOptions();
6
+ export function useBacktestQueryBuffer<T>(storage: BacktestStorage<T>) {
7
+ const { from, to } = useBacktestOptions();
9
8
 
10
9
  let page: Array<{ timestamp: number; payload: T }> = [];
11
10
  let index = 0;
@@ -47,4 +46,4 @@ export const useBacktestQueryBuffer = withMemo(<T>(storage: BacktestStorage<T>)
47
46
  completed = page.length === 0;
48
47
  }
49
48
  };
50
- });
49
+ }
@@ -1,3 +1,4 @@
1
+ import { hashCode } from '@lib/hash-code';
1
2
  import {
2
3
  eq,
3
4
  InferQueryObject,
@@ -14,7 +15,7 @@ import { BacktestStorage } from './use-backtest';
14
15
  export type BacktestStorageQuery<V> = {
15
16
  sync: <T extends QueryObjectType<K>, K extends QueryObject>(
16
17
  query: Query<InferQueryObject<T>> & {
17
- where: { timestamp: { min: number; max: number } };
18
+ where: { timestamp: { type: 'between'; min: number; max: number } };
18
19
  },
19
20
  storage: { save: (objects: { timestamp: number; payload: V }[]) => Promise<void> }
20
21
  ) => Promise<void>;
@@ -38,11 +39,13 @@ export function useBacktestStorage<V, P extends Record<string, string | number>>
38
39
  payload: 'string'
39
40
  });
40
41
 
42
+ const id = hashCode(storageObjectKey);
43
+
41
44
  return {
42
45
  async query(query) {
43
46
  const [index] = await storage.query(storageIndexObject, {
44
47
  limit: 1,
45
- where: { uri: eq(storageObjectKey) }
48
+ where: { timestamp: eq(id) }
46
49
  });
47
50
 
48
51
  const { min, max } = query.where.timestamp;
@@ -62,7 +65,7 @@ export function useBacktestStorage<V, P extends Record<string, string | number>>
62
65
 
63
66
  await storage.save(storageIndexObject, [
64
67
  {
65
- timestamp: 0,
68
+ timestamp: id,
66
69
  max,
67
70
  min,
68
71
  uri: storageObjectKey
@@ -7,7 +7,9 @@ import { useBacktestScheduler } from './use-backtest-scheduler';
7
7
 
8
8
  export interface BacktestStorage<V> {
9
9
  query(
10
- query: Query<QueryObject> & { where: { timestamp: { min: number; max: number } } }
10
+ query: Query<QueryObject> & {
11
+ where: { timestamp: { type: 'between'; min: number; max: number } };
12
+ }
11
13
  ): Promise<{ timestamp: number; payload: V }[]>;
12
14
  }
13
15
 
@@ -0,0 +1,8 @@
1
+ export function hashCode(str: string) {
2
+ let hash = 0;
3
+ for (let i = 0; i < str.length; i++) {
4
+ hash = (hash << 5) - hash + str.charCodeAt(i);
5
+ hash |= 0;
6
+ }
7
+ return hash;
8
+ }