reportify-sdk 0.2.1 → 0.2.3
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.mts +55 -5
- package/dist/index.d.ts +55 -5
- package/dist/index.js +58 -6
- package/dist/index.mjs +58 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -115,6 +115,16 @@ type Interval = '1d' | '1w' | '1m';
|
|
|
115
115
|
type PriceAdjust = 'forward' | 'backward' | 'none';
|
|
116
116
|
type Market = 'us' | 'hk' | 'cn';
|
|
117
117
|
type IPOStatus = 'Filing' | 'Hearing' | 'Priced';
|
|
118
|
+
interface IndustryConstituent {
|
|
119
|
+
symbol: string;
|
|
120
|
+
area: string;
|
|
121
|
+
name: string;
|
|
122
|
+
type_name?: string;
|
|
123
|
+
industry_one_level_name?: string;
|
|
124
|
+
industry_second_level_name?: string;
|
|
125
|
+
industry_third_level_name?: string;
|
|
126
|
+
[key: string]: unknown;
|
|
127
|
+
}
|
|
118
128
|
interface TimelineOptions {
|
|
119
129
|
num?: number;
|
|
120
130
|
}
|
|
@@ -272,6 +282,24 @@ declare class StockModule {
|
|
|
272
282
|
* Get Hong Kong IPO calendar
|
|
273
283
|
*/
|
|
274
284
|
ipoCalendarHK(status?: IPOStatus): Promise<IPOEvent[]>;
|
|
285
|
+
/**
|
|
286
|
+
* Get constituent stocks of an industry
|
|
287
|
+
*
|
|
288
|
+
* @param market - Stock market ("cn", "hk", "us")
|
|
289
|
+
* @param name - Industry name
|
|
290
|
+
* @param type - Industry classification type (optional)
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```typescript
|
|
294
|
+
* // Get CN defense industry stocks
|
|
295
|
+
* const stocks = await client.stock.industryConstituent('cn', '军工');
|
|
296
|
+
* console.log(stocks);
|
|
297
|
+
*
|
|
298
|
+
* // Get US technology stocks
|
|
299
|
+
* const techStocks = await client.stock.industryConstituent('us', 'Technology');
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
industryConstituent(market: Market, name: string, type?: string): Promise<IndustryConstituent[]>;
|
|
275
303
|
private normalizeArrayResponse;
|
|
276
304
|
}
|
|
277
305
|
|
|
@@ -498,16 +526,18 @@ interface OHLCVData {
|
|
|
498
526
|
[key: string]: unknown;
|
|
499
527
|
}
|
|
500
528
|
interface BacktestParams {
|
|
501
|
-
symbol: string;
|
|
502
|
-
formula: string;
|
|
503
529
|
startDate: string;
|
|
504
530
|
endDate: string;
|
|
531
|
+
symbol: string;
|
|
505
532
|
market?: StockMarket;
|
|
533
|
+
entryFormula: string;
|
|
534
|
+
exitFormula?: string;
|
|
506
535
|
initialCash?: number;
|
|
507
536
|
commission?: number;
|
|
508
537
|
stopLoss?: number;
|
|
509
538
|
sizerPercent?: number;
|
|
510
539
|
autoClose?: boolean;
|
|
540
|
+
labels?: Record<string, string>;
|
|
511
541
|
}
|
|
512
542
|
interface BacktestResult {
|
|
513
543
|
success: boolean;
|
|
@@ -684,17 +714,37 @@ declare class QuantModule {
|
|
|
684
714
|
*
|
|
685
715
|
* @example
|
|
686
716
|
* ```typescript
|
|
717
|
+
* // Simple golden cross strategy
|
|
687
718
|
* const result = await client.quant.backtest({
|
|
688
|
-
* symbol: '000001',
|
|
689
|
-
* formula: 'CROSS(MA(5), MA(20))', // Golden cross buy signal
|
|
690
719
|
* startDate: '2023-01-01',
|
|
691
720
|
* endDate: '2024-01-01',
|
|
721
|
+
* symbol: '000001',
|
|
722
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy when MA5 crosses above MA20
|
|
692
723
|
* initialCash: 100000
|
|
693
724
|
* });
|
|
694
725
|
*
|
|
695
726
|
* console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
|
|
696
727
|
* console.log(`Max Drawdown: ${(result.max_drawdown * 100).toFixed(2)}%`);
|
|
697
728
|
* console.log(`Win Rate: ${(result.win_rate * 100).toFixed(2)}%`);
|
|
729
|
+
*
|
|
730
|
+
* // Strategy with entry and exit signals
|
|
731
|
+
* const result2 = await client.quant.backtest({
|
|
732
|
+
* startDate: '2023-01-01',
|
|
733
|
+
* endDate: '2024-01-01',
|
|
734
|
+
* symbol: '000001',
|
|
735
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy signal
|
|
736
|
+
* exitFormula: 'CROSSDOWN(MA(5), MA(20))' // Sell signal
|
|
737
|
+
* });
|
|
738
|
+
*
|
|
739
|
+
* // With custom labels for analysis
|
|
740
|
+
* const result3 = await client.quant.backtest({
|
|
741
|
+
* startDate: '2023-01-01',
|
|
742
|
+
* endDate: '2024-01-01',
|
|
743
|
+
* symbol: '000001',
|
|
744
|
+
* entryFormula: 'RSI(14) < 30',
|
|
745
|
+
* exitFormula: 'RSI(14) > 70',
|
|
746
|
+
* labels: { rsi: 'RSI(14)', ma20: 'MA(20)' }
|
|
747
|
+
* });
|
|
698
748
|
* ```
|
|
699
749
|
*/
|
|
700
750
|
backtest(params: BacktestParams): Promise<BacktestResult>;
|
|
@@ -777,4 +827,4 @@ declare class Reportify {
|
|
|
777
827
|
searchTranscripts(query: string, options?: SearchOptions): Promise<Document[]>;
|
|
778
828
|
}
|
|
779
829
|
|
|
780
|
-
export { APIError, AuthenticationError, type BacktestParams, type BacktestResult, type BatchOHLCVParams, type Chunk, type CompanyInfo, type CompanyOverview, DocsModule, type Document, type EarningsEvent, type FactorComputeParams, type FactorMeta, type FinancialStatement, type IPOEvent, type IPOStatus, type IndicatorComputeParams, type IndicatorData, type IndicatorMeta, type Interval, KBModule, type KBSearchOptions, type Market, NotFoundError, type OHLCVData, type OHLCVParams, type PaginatedResponse, type Period, type PriceAdjust, type PriceData, QuantModule, type Quote, RateLimitError, Reportify, type ReportifyConfig, ReportifyError, type ScreenParams, type ScreenedStock, type SearchOptions, type Shareholder, type StockInfo, type StockMarket, StockModule, TimelineModule, type TimelineOptions };
|
|
830
|
+
export { APIError, AuthenticationError, type BacktestParams, type BacktestResult, type BatchOHLCVParams, type Chunk, type CompanyInfo, type CompanyOverview, DocsModule, type Document, type EarningsEvent, type FactorComputeParams, type FactorMeta, type FinancialStatement, type IPOEvent, type IPOStatus, type IndicatorComputeParams, type IndicatorData, type IndicatorMeta, type IndustryConstituent, type Interval, KBModule, type KBSearchOptions, type Market, NotFoundError, type OHLCVData, type OHLCVParams, type PaginatedResponse, type Period, type PriceAdjust, type PriceData, QuantModule, type Quote, RateLimitError, Reportify, type ReportifyConfig, ReportifyError, type ScreenParams, type ScreenedStock, type SearchOptions, type Shareholder, type StockInfo, type StockMarket, StockModule, TimelineModule, type TimelineOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -115,6 +115,16 @@ type Interval = '1d' | '1w' | '1m';
|
|
|
115
115
|
type PriceAdjust = 'forward' | 'backward' | 'none';
|
|
116
116
|
type Market = 'us' | 'hk' | 'cn';
|
|
117
117
|
type IPOStatus = 'Filing' | 'Hearing' | 'Priced';
|
|
118
|
+
interface IndustryConstituent {
|
|
119
|
+
symbol: string;
|
|
120
|
+
area: string;
|
|
121
|
+
name: string;
|
|
122
|
+
type_name?: string;
|
|
123
|
+
industry_one_level_name?: string;
|
|
124
|
+
industry_second_level_name?: string;
|
|
125
|
+
industry_third_level_name?: string;
|
|
126
|
+
[key: string]: unknown;
|
|
127
|
+
}
|
|
118
128
|
interface TimelineOptions {
|
|
119
129
|
num?: number;
|
|
120
130
|
}
|
|
@@ -272,6 +282,24 @@ declare class StockModule {
|
|
|
272
282
|
* Get Hong Kong IPO calendar
|
|
273
283
|
*/
|
|
274
284
|
ipoCalendarHK(status?: IPOStatus): Promise<IPOEvent[]>;
|
|
285
|
+
/**
|
|
286
|
+
* Get constituent stocks of an industry
|
|
287
|
+
*
|
|
288
|
+
* @param market - Stock market ("cn", "hk", "us")
|
|
289
|
+
* @param name - Industry name
|
|
290
|
+
* @param type - Industry classification type (optional)
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```typescript
|
|
294
|
+
* // Get CN defense industry stocks
|
|
295
|
+
* const stocks = await client.stock.industryConstituent('cn', '军工');
|
|
296
|
+
* console.log(stocks);
|
|
297
|
+
*
|
|
298
|
+
* // Get US technology stocks
|
|
299
|
+
* const techStocks = await client.stock.industryConstituent('us', 'Technology');
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
industryConstituent(market: Market, name: string, type?: string): Promise<IndustryConstituent[]>;
|
|
275
303
|
private normalizeArrayResponse;
|
|
276
304
|
}
|
|
277
305
|
|
|
@@ -498,16 +526,18 @@ interface OHLCVData {
|
|
|
498
526
|
[key: string]: unknown;
|
|
499
527
|
}
|
|
500
528
|
interface BacktestParams {
|
|
501
|
-
symbol: string;
|
|
502
|
-
formula: string;
|
|
503
529
|
startDate: string;
|
|
504
530
|
endDate: string;
|
|
531
|
+
symbol: string;
|
|
505
532
|
market?: StockMarket;
|
|
533
|
+
entryFormula: string;
|
|
534
|
+
exitFormula?: string;
|
|
506
535
|
initialCash?: number;
|
|
507
536
|
commission?: number;
|
|
508
537
|
stopLoss?: number;
|
|
509
538
|
sizerPercent?: number;
|
|
510
539
|
autoClose?: boolean;
|
|
540
|
+
labels?: Record<string, string>;
|
|
511
541
|
}
|
|
512
542
|
interface BacktestResult {
|
|
513
543
|
success: boolean;
|
|
@@ -684,17 +714,37 @@ declare class QuantModule {
|
|
|
684
714
|
*
|
|
685
715
|
* @example
|
|
686
716
|
* ```typescript
|
|
717
|
+
* // Simple golden cross strategy
|
|
687
718
|
* const result = await client.quant.backtest({
|
|
688
|
-
* symbol: '000001',
|
|
689
|
-
* formula: 'CROSS(MA(5), MA(20))', // Golden cross buy signal
|
|
690
719
|
* startDate: '2023-01-01',
|
|
691
720
|
* endDate: '2024-01-01',
|
|
721
|
+
* symbol: '000001',
|
|
722
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy when MA5 crosses above MA20
|
|
692
723
|
* initialCash: 100000
|
|
693
724
|
* });
|
|
694
725
|
*
|
|
695
726
|
* console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
|
|
696
727
|
* console.log(`Max Drawdown: ${(result.max_drawdown * 100).toFixed(2)}%`);
|
|
697
728
|
* console.log(`Win Rate: ${(result.win_rate * 100).toFixed(2)}%`);
|
|
729
|
+
*
|
|
730
|
+
* // Strategy with entry and exit signals
|
|
731
|
+
* const result2 = await client.quant.backtest({
|
|
732
|
+
* startDate: '2023-01-01',
|
|
733
|
+
* endDate: '2024-01-01',
|
|
734
|
+
* symbol: '000001',
|
|
735
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy signal
|
|
736
|
+
* exitFormula: 'CROSSDOWN(MA(5), MA(20))' // Sell signal
|
|
737
|
+
* });
|
|
738
|
+
*
|
|
739
|
+
* // With custom labels for analysis
|
|
740
|
+
* const result3 = await client.quant.backtest({
|
|
741
|
+
* startDate: '2023-01-01',
|
|
742
|
+
* endDate: '2024-01-01',
|
|
743
|
+
* symbol: '000001',
|
|
744
|
+
* entryFormula: 'RSI(14) < 30',
|
|
745
|
+
* exitFormula: 'RSI(14) > 70',
|
|
746
|
+
* labels: { rsi: 'RSI(14)', ma20: 'MA(20)' }
|
|
747
|
+
* });
|
|
698
748
|
* ```
|
|
699
749
|
*/
|
|
700
750
|
backtest(params: BacktestParams): Promise<BacktestResult>;
|
|
@@ -777,4 +827,4 @@ declare class Reportify {
|
|
|
777
827
|
searchTranscripts(query: string, options?: SearchOptions): Promise<Document[]>;
|
|
778
828
|
}
|
|
779
829
|
|
|
780
|
-
export { APIError, AuthenticationError, type BacktestParams, type BacktestResult, type BatchOHLCVParams, type Chunk, type CompanyInfo, type CompanyOverview, DocsModule, type Document, type EarningsEvent, type FactorComputeParams, type FactorMeta, type FinancialStatement, type IPOEvent, type IPOStatus, type IndicatorComputeParams, type IndicatorData, type IndicatorMeta, type Interval, KBModule, type KBSearchOptions, type Market, NotFoundError, type OHLCVData, type OHLCVParams, type PaginatedResponse, type Period, type PriceAdjust, type PriceData, QuantModule, type Quote, RateLimitError, Reportify, type ReportifyConfig, ReportifyError, type ScreenParams, type ScreenedStock, type SearchOptions, type Shareholder, type StockInfo, type StockMarket, StockModule, TimelineModule, type TimelineOptions };
|
|
830
|
+
export { APIError, AuthenticationError, type BacktestParams, type BacktestResult, type BatchOHLCVParams, type Chunk, type CompanyInfo, type CompanyOverview, DocsModule, type Document, type EarningsEvent, type FactorComputeParams, type FactorMeta, type FinancialStatement, type IPOEvent, type IPOStatus, type IndicatorComputeParams, type IndicatorData, type IndicatorMeta, type IndustryConstituent, type Interval, KBModule, type KBSearchOptions, type Market, NotFoundError, type OHLCVData, type OHLCVParams, type PaginatedResponse, type Period, type PriceAdjust, type PriceData, QuantModule, type Quote, RateLimitError, Reportify, type ReportifyConfig, ReportifyError, type ScreenParams, type ScreenedStock, type SearchOptions, type Shareholder, type StockInfo, type StockMarket, StockModule, TimelineModule, type TimelineOptions };
|
package/dist/index.js
CHANGED
|
@@ -255,6 +255,31 @@ var StockModule = class {
|
|
|
255
255
|
);
|
|
256
256
|
return this.normalizeArrayResponse(response);
|
|
257
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Get constituent stocks of an industry
|
|
260
|
+
*
|
|
261
|
+
* @param market - Stock market ("cn", "hk", "us")
|
|
262
|
+
* @param name - Industry name
|
|
263
|
+
* @param type - Industry classification type (optional)
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* // Get CN defense industry stocks
|
|
268
|
+
* const stocks = await client.stock.industryConstituent('cn', '军工');
|
|
269
|
+
* console.log(stocks);
|
|
270
|
+
*
|
|
271
|
+
* // Get US technology stocks
|
|
272
|
+
* const techStocks = await client.stock.industryConstituent('us', 'Technology');
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
async industryConstituent(market, name, type) {
|
|
276
|
+
const body = { market, name };
|
|
277
|
+
if (type) {
|
|
278
|
+
body.type = type;
|
|
279
|
+
}
|
|
280
|
+
const response = await this.client.post("/v1/stock/industry-constituent", body);
|
|
281
|
+
return this.normalizeArrayResponse(response);
|
|
282
|
+
}
|
|
258
283
|
// ===========================================================================
|
|
259
284
|
// Helper Methods
|
|
260
285
|
// ===========================================================================
|
|
@@ -655,32 +680,59 @@ var QuantModule = class {
|
|
|
655
680
|
*
|
|
656
681
|
* @example
|
|
657
682
|
* ```typescript
|
|
683
|
+
* // Simple golden cross strategy
|
|
658
684
|
* const result = await client.quant.backtest({
|
|
659
|
-
* symbol: '000001',
|
|
660
|
-
* formula: 'CROSS(MA(5), MA(20))', // Golden cross buy signal
|
|
661
685
|
* startDate: '2023-01-01',
|
|
662
686
|
* endDate: '2024-01-01',
|
|
687
|
+
* symbol: '000001',
|
|
688
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy when MA5 crosses above MA20
|
|
663
689
|
* initialCash: 100000
|
|
664
690
|
* });
|
|
665
691
|
*
|
|
666
692
|
* console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
|
|
667
693
|
* console.log(`Max Drawdown: ${(result.max_drawdown * 100).toFixed(2)}%`);
|
|
668
694
|
* console.log(`Win Rate: ${(result.win_rate * 100).toFixed(2)}%`);
|
|
695
|
+
*
|
|
696
|
+
* // Strategy with entry and exit signals
|
|
697
|
+
* const result2 = await client.quant.backtest({
|
|
698
|
+
* startDate: '2023-01-01',
|
|
699
|
+
* endDate: '2024-01-01',
|
|
700
|
+
* symbol: '000001',
|
|
701
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy signal
|
|
702
|
+
* exitFormula: 'CROSSDOWN(MA(5), MA(20))' // Sell signal
|
|
703
|
+
* });
|
|
704
|
+
*
|
|
705
|
+
* // With custom labels for analysis
|
|
706
|
+
* const result3 = await client.quant.backtest({
|
|
707
|
+
* startDate: '2023-01-01',
|
|
708
|
+
* endDate: '2024-01-01',
|
|
709
|
+
* symbol: '000001',
|
|
710
|
+
* entryFormula: 'RSI(14) < 30',
|
|
711
|
+
* exitFormula: 'RSI(14) > 70',
|
|
712
|
+
* labels: { rsi: 'RSI(14)', ma20: 'MA(20)' }
|
|
713
|
+
* });
|
|
669
714
|
* ```
|
|
670
715
|
*/
|
|
671
716
|
async backtest(params) {
|
|
672
|
-
|
|
673
|
-
symbol: params.symbol,
|
|
674
|
-
formula: params.formula,
|
|
717
|
+
const body = {
|
|
675
718
|
start_date: params.startDate,
|
|
676
719
|
end_date: params.endDate,
|
|
720
|
+
symbol: params.symbol,
|
|
677
721
|
market: params.market || "cn",
|
|
722
|
+
entry_formula: params.entryFormula,
|
|
678
723
|
initial_cash: params.initialCash ?? 1e5,
|
|
679
724
|
commission: params.commission ?? 0,
|
|
680
725
|
stop_loss: params.stopLoss ?? 0,
|
|
681
726
|
sizer_percent: params.sizerPercent ?? 99,
|
|
682
727
|
auto_close: params.autoClose ?? true
|
|
683
|
-
}
|
|
728
|
+
};
|
|
729
|
+
if (params.exitFormula !== void 0) {
|
|
730
|
+
body.exit_formula = params.exitFormula;
|
|
731
|
+
}
|
|
732
|
+
if (params.labels !== void 0) {
|
|
733
|
+
body.labels = params.labels;
|
|
734
|
+
}
|
|
735
|
+
return this.client.post("/v1/quant/backtest", body);
|
|
684
736
|
}
|
|
685
737
|
};
|
|
686
738
|
|
package/dist/index.mjs
CHANGED
|
@@ -219,6 +219,31 @@ var StockModule = class {
|
|
|
219
219
|
);
|
|
220
220
|
return this.normalizeArrayResponse(response);
|
|
221
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Get constituent stocks of an industry
|
|
224
|
+
*
|
|
225
|
+
* @param market - Stock market ("cn", "hk", "us")
|
|
226
|
+
* @param name - Industry name
|
|
227
|
+
* @param type - Industry classification type (optional)
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* // Get CN defense industry stocks
|
|
232
|
+
* const stocks = await client.stock.industryConstituent('cn', '军工');
|
|
233
|
+
* console.log(stocks);
|
|
234
|
+
*
|
|
235
|
+
* // Get US technology stocks
|
|
236
|
+
* const techStocks = await client.stock.industryConstituent('us', 'Technology');
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
async industryConstituent(market, name, type) {
|
|
240
|
+
const body = { market, name };
|
|
241
|
+
if (type) {
|
|
242
|
+
body.type = type;
|
|
243
|
+
}
|
|
244
|
+
const response = await this.client.post("/v1/stock/industry-constituent", body);
|
|
245
|
+
return this.normalizeArrayResponse(response);
|
|
246
|
+
}
|
|
222
247
|
// ===========================================================================
|
|
223
248
|
// Helper Methods
|
|
224
249
|
// ===========================================================================
|
|
@@ -619,32 +644,59 @@ var QuantModule = class {
|
|
|
619
644
|
*
|
|
620
645
|
* @example
|
|
621
646
|
* ```typescript
|
|
647
|
+
* // Simple golden cross strategy
|
|
622
648
|
* const result = await client.quant.backtest({
|
|
623
|
-
* symbol: '000001',
|
|
624
|
-
* formula: 'CROSS(MA(5), MA(20))', // Golden cross buy signal
|
|
625
649
|
* startDate: '2023-01-01',
|
|
626
650
|
* endDate: '2024-01-01',
|
|
651
|
+
* symbol: '000001',
|
|
652
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy when MA5 crosses above MA20
|
|
627
653
|
* initialCash: 100000
|
|
628
654
|
* });
|
|
629
655
|
*
|
|
630
656
|
* console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
|
|
631
657
|
* console.log(`Max Drawdown: ${(result.max_drawdown * 100).toFixed(2)}%`);
|
|
632
658
|
* console.log(`Win Rate: ${(result.win_rate * 100).toFixed(2)}%`);
|
|
659
|
+
*
|
|
660
|
+
* // Strategy with entry and exit signals
|
|
661
|
+
* const result2 = await client.quant.backtest({
|
|
662
|
+
* startDate: '2023-01-01',
|
|
663
|
+
* endDate: '2024-01-01',
|
|
664
|
+
* symbol: '000001',
|
|
665
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy signal
|
|
666
|
+
* exitFormula: 'CROSSDOWN(MA(5), MA(20))' // Sell signal
|
|
667
|
+
* });
|
|
668
|
+
*
|
|
669
|
+
* // With custom labels for analysis
|
|
670
|
+
* const result3 = await client.quant.backtest({
|
|
671
|
+
* startDate: '2023-01-01',
|
|
672
|
+
* endDate: '2024-01-01',
|
|
673
|
+
* symbol: '000001',
|
|
674
|
+
* entryFormula: 'RSI(14) < 30',
|
|
675
|
+
* exitFormula: 'RSI(14) > 70',
|
|
676
|
+
* labels: { rsi: 'RSI(14)', ma20: 'MA(20)' }
|
|
677
|
+
* });
|
|
633
678
|
* ```
|
|
634
679
|
*/
|
|
635
680
|
async backtest(params) {
|
|
636
|
-
|
|
637
|
-
symbol: params.symbol,
|
|
638
|
-
formula: params.formula,
|
|
681
|
+
const body = {
|
|
639
682
|
start_date: params.startDate,
|
|
640
683
|
end_date: params.endDate,
|
|
684
|
+
symbol: params.symbol,
|
|
641
685
|
market: params.market || "cn",
|
|
686
|
+
entry_formula: params.entryFormula,
|
|
642
687
|
initial_cash: params.initialCash ?? 1e5,
|
|
643
688
|
commission: params.commission ?? 0,
|
|
644
689
|
stop_loss: params.stopLoss ?? 0,
|
|
645
690
|
sizer_percent: params.sizerPercent ?? 99,
|
|
646
691
|
auto_close: params.autoClose ?? true
|
|
647
|
-
}
|
|
692
|
+
};
|
|
693
|
+
if (params.exitFormula !== void 0) {
|
|
694
|
+
body.exit_formula = params.exitFormula;
|
|
695
|
+
}
|
|
696
|
+
if (params.labels !== void 0) {
|
|
697
|
+
body.labels = params.labels;
|
|
698
|
+
}
|
|
699
|
+
return this.client.post("/v1/quant/backtest", body);
|
|
648
700
|
}
|
|
649
701
|
};
|
|
650
702
|
|