reportify-sdk 0.2.1 → 0.2.2
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 +26 -4
- package/dist/index.d.ts +26 -4
- package/dist/index.js +33 -6
- package/dist/index.mjs +33 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -498,16 +498,18 @@ interface OHLCVData {
|
|
|
498
498
|
[key: string]: unknown;
|
|
499
499
|
}
|
|
500
500
|
interface BacktestParams {
|
|
501
|
-
symbol: string;
|
|
502
|
-
formula: string;
|
|
503
501
|
startDate: string;
|
|
504
502
|
endDate: string;
|
|
503
|
+
symbol: string;
|
|
505
504
|
market?: StockMarket;
|
|
505
|
+
entryFormula: string;
|
|
506
|
+
exitFormula?: string;
|
|
506
507
|
initialCash?: number;
|
|
507
508
|
commission?: number;
|
|
508
509
|
stopLoss?: number;
|
|
509
510
|
sizerPercent?: number;
|
|
510
511
|
autoClose?: boolean;
|
|
512
|
+
labels?: Record<string, string>;
|
|
511
513
|
}
|
|
512
514
|
interface BacktestResult {
|
|
513
515
|
success: boolean;
|
|
@@ -684,17 +686,37 @@ declare class QuantModule {
|
|
|
684
686
|
*
|
|
685
687
|
* @example
|
|
686
688
|
* ```typescript
|
|
689
|
+
* // Simple golden cross strategy
|
|
687
690
|
* const result = await client.quant.backtest({
|
|
688
|
-
* symbol: '000001',
|
|
689
|
-
* formula: 'CROSS(MA(5), MA(20))', // Golden cross buy signal
|
|
690
691
|
* startDate: '2023-01-01',
|
|
691
692
|
* endDate: '2024-01-01',
|
|
693
|
+
* symbol: '000001',
|
|
694
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy when MA5 crosses above MA20
|
|
692
695
|
* initialCash: 100000
|
|
693
696
|
* });
|
|
694
697
|
*
|
|
695
698
|
* console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
|
|
696
699
|
* console.log(`Max Drawdown: ${(result.max_drawdown * 100).toFixed(2)}%`);
|
|
697
700
|
* console.log(`Win Rate: ${(result.win_rate * 100).toFixed(2)}%`);
|
|
701
|
+
*
|
|
702
|
+
* // Strategy with entry and exit signals
|
|
703
|
+
* const result2 = await client.quant.backtest({
|
|
704
|
+
* startDate: '2023-01-01',
|
|
705
|
+
* endDate: '2024-01-01',
|
|
706
|
+
* symbol: '000001',
|
|
707
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy signal
|
|
708
|
+
* exitFormula: 'CROSSDOWN(MA(5), MA(20))' // Sell signal
|
|
709
|
+
* });
|
|
710
|
+
*
|
|
711
|
+
* // With custom labels for analysis
|
|
712
|
+
* const result3 = await client.quant.backtest({
|
|
713
|
+
* startDate: '2023-01-01',
|
|
714
|
+
* endDate: '2024-01-01',
|
|
715
|
+
* symbol: '000001',
|
|
716
|
+
* entryFormula: 'RSI(14) < 30',
|
|
717
|
+
* exitFormula: 'RSI(14) > 70',
|
|
718
|
+
* labels: { rsi: 'RSI(14)', ma20: 'MA(20)' }
|
|
719
|
+
* });
|
|
698
720
|
* ```
|
|
699
721
|
*/
|
|
700
722
|
backtest(params: BacktestParams): Promise<BacktestResult>;
|
package/dist/index.d.ts
CHANGED
|
@@ -498,16 +498,18 @@ interface OHLCVData {
|
|
|
498
498
|
[key: string]: unknown;
|
|
499
499
|
}
|
|
500
500
|
interface BacktestParams {
|
|
501
|
-
symbol: string;
|
|
502
|
-
formula: string;
|
|
503
501
|
startDate: string;
|
|
504
502
|
endDate: string;
|
|
503
|
+
symbol: string;
|
|
505
504
|
market?: StockMarket;
|
|
505
|
+
entryFormula: string;
|
|
506
|
+
exitFormula?: string;
|
|
506
507
|
initialCash?: number;
|
|
507
508
|
commission?: number;
|
|
508
509
|
stopLoss?: number;
|
|
509
510
|
sizerPercent?: number;
|
|
510
511
|
autoClose?: boolean;
|
|
512
|
+
labels?: Record<string, string>;
|
|
511
513
|
}
|
|
512
514
|
interface BacktestResult {
|
|
513
515
|
success: boolean;
|
|
@@ -684,17 +686,37 @@ declare class QuantModule {
|
|
|
684
686
|
*
|
|
685
687
|
* @example
|
|
686
688
|
* ```typescript
|
|
689
|
+
* // Simple golden cross strategy
|
|
687
690
|
* const result = await client.quant.backtest({
|
|
688
|
-
* symbol: '000001',
|
|
689
|
-
* formula: 'CROSS(MA(5), MA(20))', // Golden cross buy signal
|
|
690
691
|
* startDate: '2023-01-01',
|
|
691
692
|
* endDate: '2024-01-01',
|
|
693
|
+
* symbol: '000001',
|
|
694
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy when MA5 crosses above MA20
|
|
692
695
|
* initialCash: 100000
|
|
693
696
|
* });
|
|
694
697
|
*
|
|
695
698
|
* console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
|
|
696
699
|
* console.log(`Max Drawdown: ${(result.max_drawdown * 100).toFixed(2)}%`);
|
|
697
700
|
* console.log(`Win Rate: ${(result.win_rate * 100).toFixed(2)}%`);
|
|
701
|
+
*
|
|
702
|
+
* // Strategy with entry and exit signals
|
|
703
|
+
* const result2 = await client.quant.backtest({
|
|
704
|
+
* startDate: '2023-01-01',
|
|
705
|
+
* endDate: '2024-01-01',
|
|
706
|
+
* symbol: '000001',
|
|
707
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy signal
|
|
708
|
+
* exitFormula: 'CROSSDOWN(MA(5), MA(20))' // Sell signal
|
|
709
|
+
* });
|
|
710
|
+
*
|
|
711
|
+
* // With custom labels for analysis
|
|
712
|
+
* const result3 = await client.quant.backtest({
|
|
713
|
+
* startDate: '2023-01-01',
|
|
714
|
+
* endDate: '2024-01-01',
|
|
715
|
+
* symbol: '000001',
|
|
716
|
+
* entryFormula: 'RSI(14) < 30',
|
|
717
|
+
* exitFormula: 'RSI(14) > 70',
|
|
718
|
+
* labels: { rsi: 'RSI(14)', ma20: 'MA(20)' }
|
|
719
|
+
* });
|
|
698
720
|
* ```
|
|
699
721
|
*/
|
|
700
722
|
backtest(params: BacktestParams): Promise<BacktestResult>;
|
package/dist/index.js
CHANGED
|
@@ -655,32 +655,59 @@ var QuantModule = class {
|
|
|
655
655
|
*
|
|
656
656
|
* @example
|
|
657
657
|
* ```typescript
|
|
658
|
+
* // Simple golden cross strategy
|
|
658
659
|
* const result = await client.quant.backtest({
|
|
659
|
-
* symbol: '000001',
|
|
660
|
-
* formula: 'CROSS(MA(5), MA(20))', // Golden cross buy signal
|
|
661
660
|
* startDate: '2023-01-01',
|
|
662
661
|
* endDate: '2024-01-01',
|
|
662
|
+
* symbol: '000001',
|
|
663
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy when MA5 crosses above MA20
|
|
663
664
|
* initialCash: 100000
|
|
664
665
|
* });
|
|
665
666
|
*
|
|
666
667
|
* console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
|
|
667
668
|
* console.log(`Max Drawdown: ${(result.max_drawdown * 100).toFixed(2)}%`);
|
|
668
669
|
* console.log(`Win Rate: ${(result.win_rate * 100).toFixed(2)}%`);
|
|
670
|
+
*
|
|
671
|
+
* // Strategy with entry and exit signals
|
|
672
|
+
* const result2 = await client.quant.backtest({
|
|
673
|
+
* startDate: '2023-01-01',
|
|
674
|
+
* endDate: '2024-01-01',
|
|
675
|
+
* symbol: '000001',
|
|
676
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy signal
|
|
677
|
+
* exitFormula: 'CROSSDOWN(MA(5), MA(20))' // Sell signal
|
|
678
|
+
* });
|
|
679
|
+
*
|
|
680
|
+
* // With custom labels for analysis
|
|
681
|
+
* const result3 = await client.quant.backtest({
|
|
682
|
+
* startDate: '2023-01-01',
|
|
683
|
+
* endDate: '2024-01-01',
|
|
684
|
+
* symbol: '000001',
|
|
685
|
+
* entryFormula: 'RSI(14) < 30',
|
|
686
|
+
* exitFormula: 'RSI(14) > 70',
|
|
687
|
+
* labels: { rsi: 'RSI(14)', ma20: 'MA(20)' }
|
|
688
|
+
* });
|
|
669
689
|
* ```
|
|
670
690
|
*/
|
|
671
691
|
async backtest(params) {
|
|
672
|
-
|
|
673
|
-
symbol: params.symbol,
|
|
674
|
-
formula: params.formula,
|
|
692
|
+
const body = {
|
|
675
693
|
start_date: params.startDate,
|
|
676
694
|
end_date: params.endDate,
|
|
695
|
+
symbol: params.symbol,
|
|
677
696
|
market: params.market || "cn",
|
|
697
|
+
entry_formula: params.entryFormula,
|
|
678
698
|
initial_cash: params.initialCash ?? 1e5,
|
|
679
699
|
commission: params.commission ?? 0,
|
|
680
700
|
stop_loss: params.stopLoss ?? 0,
|
|
681
701
|
sizer_percent: params.sizerPercent ?? 99,
|
|
682
702
|
auto_close: params.autoClose ?? true
|
|
683
|
-
}
|
|
703
|
+
};
|
|
704
|
+
if (params.exitFormula !== void 0) {
|
|
705
|
+
body.exit_formula = params.exitFormula;
|
|
706
|
+
}
|
|
707
|
+
if (params.labels !== void 0) {
|
|
708
|
+
body.labels = params.labels;
|
|
709
|
+
}
|
|
710
|
+
return this.client.post("/v1/quant/backtest", body);
|
|
684
711
|
}
|
|
685
712
|
};
|
|
686
713
|
|
package/dist/index.mjs
CHANGED
|
@@ -619,32 +619,59 @@ var QuantModule = class {
|
|
|
619
619
|
*
|
|
620
620
|
* @example
|
|
621
621
|
* ```typescript
|
|
622
|
+
* // Simple golden cross strategy
|
|
622
623
|
* const result = await client.quant.backtest({
|
|
623
|
-
* symbol: '000001',
|
|
624
|
-
* formula: 'CROSS(MA(5), MA(20))', // Golden cross buy signal
|
|
625
624
|
* startDate: '2023-01-01',
|
|
626
625
|
* endDate: '2024-01-01',
|
|
626
|
+
* symbol: '000001',
|
|
627
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy when MA5 crosses above MA20
|
|
627
628
|
* initialCash: 100000
|
|
628
629
|
* });
|
|
629
630
|
*
|
|
630
631
|
* console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
|
|
631
632
|
* console.log(`Max Drawdown: ${(result.max_drawdown * 100).toFixed(2)}%`);
|
|
632
633
|
* console.log(`Win Rate: ${(result.win_rate * 100).toFixed(2)}%`);
|
|
634
|
+
*
|
|
635
|
+
* // Strategy with entry and exit signals
|
|
636
|
+
* const result2 = await client.quant.backtest({
|
|
637
|
+
* startDate: '2023-01-01',
|
|
638
|
+
* endDate: '2024-01-01',
|
|
639
|
+
* symbol: '000001',
|
|
640
|
+
* entryFormula: 'CROSS(MA(5), MA(20))', // Buy signal
|
|
641
|
+
* exitFormula: 'CROSSDOWN(MA(5), MA(20))' // Sell signal
|
|
642
|
+
* });
|
|
643
|
+
*
|
|
644
|
+
* // With custom labels for analysis
|
|
645
|
+
* const result3 = await client.quant.backtest({
|
|
646
|
+
* startDate: '2023-01-01',
|
|
647
|
+
* endDate: '2024-01-01',
|
|
648
|
+
* symbol: '000001',
|
|
649
|
+
* entryFormula: 'RSI(14) < 30',
|
|
650
|
+
* exitFormula: 'RSI(14) > 70',
|
|
651
|
+
* labels: { rsi: 'RSI(14)', ma20: 'MA(20)' }
|
|
652
|
+
* });
|
|
633
653
|
* ```
|
|
634
654
|
*/
|
|
635
655
|
async backtest(params) {
|
|
636
|
-
|
|
637
|
-
symbol: params.symbol,
|
|
638
|
-
formula: params.formula,
|
|
656
|
+
const body = {
|
|
639
657
|
start_date: params.startDate,
|
|
640
658
|
end_date: params.endDate,
|
|
659
|
+
symbol: params.symbol,
|
|
641
660
|
market: params.market || "cn",
|
|
661
|
+
entry_formula: params.entryFormula,
|
|
642
662
|
initial_cash: params.initialCash ?? 1e5,
|
|
643
663
|
commission: params.commission ?? 0,
|
|
644
664
|
stop_loss: params.stopLoss ?? 0,
|
|
645
665
|
sizer_percent: params.sizerPercent ?? 99,
|
|
646
666
|
auto_close: params.autoClose ?? true
|
|
647
|
-
}
|
|
667
|
+
};
|
|
668
|
+
if (params.exitFormula !== void 0) {
|
|
669
|
+
body.exit_formula = params.exitFormula;
|
|
670
|
+
}
|
|
671
|
+
if (params.labels !== void 0) {
|
|
672
|
+
body.labels = params.labels;
|
|
673
|
+
}
|
|
674
|
+
return this.client.post("/v1/quant/backtest", body);
|
|
648
675
|
}
|
|
649
676
|
};
|
|
650
677
|
|