reportify-sdk 0.1.0 → 0.2.1

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 CHANGED
@@ -426,6 +426,280 @@ declare class DocsModule {
426
426
  searchChunks(query: string, options?: ChunkSearchOptions): Promise<Chunk[]>;
427
427
  }
428
428
 
429
+ /**
430
+ * Quant Module
431
+ *
432
+ * Provides quantitative analysis tools including indicators, factors, quotes, and backtesting.
433
+ * Based on Mai-language syntax compatible with TongDaXin/TongHuaShun.
434
+ */
435
+
436
+ type StockMarket = 'cn' | 'hk' | 'us';
437
+ interface IndicatorMeta {
438
+ name: string;
439
+ description: string;
440
+ fields: string[];
441
+ }
442
+ interface IndicatorComputeParams {
443
+ symbols: string[];
444
+ formula: string;
445
+ market?: StockMarket;
446
+ startDate?: string;
447
+ endDate?: string;
448
+ }
449
+ interface IndicatorData {
450
+ symbol: string;
451
+ date: string;
452
+ [key: string]: unknown;
453
+ }
454
+ interface FactorMeta {
455
+ name: string;
456
+ type: 'variable' | 'function';
457
+ level: 0 | 1 | 2;
458
+ description: string;
459
+ }
460
+ interface FactorComputeParams {
461
+ symbols: string[];
462
+ formula: string;
463
+ market?: StockMarket;
464
+ startDate?: string;
465
+ endDate?: string;
466
+ }
467
+ interface ScreenParams {
468
+ formula: string;
469
+ market?: StockMarket;
470
+ checkDate?: string;
471
+ symbols?: string[];
472
+ }
473
+ interface ScreenedStock {
474
+ symbol: string;
475
+ close: number;
476
+ factor_value?: number | boolean;
477
+ }
478
+ interface OHLCVParams {
479
+ symbol: string;
480
+ market?: StockMarket;
481
+ startDate?: string;
482
+ endDate?: string;
483
+ }
484
+ interface BatchOHLCVParams {
485
+ symbols: string[];
486
+ market?: StockMarket;
487
+ startDate?: string;
488
+ endDate?: string;
489
+ }
490
+ interface OHLCVData {
491
+ symbol: string;
492
+ date: string;
493
+ open: number;
494
+ high: number;
495
+ low: number;
496
+ close: number;
497
+ volume: number;
498
+ [key: string]: unknown;
499
+ }
500
+ interface BacktestParams {
501
+ symbol: string;
502
+ formula: string;
503
+ startDate: string;
504
+ endDate: string;
505
+ market?: StockMarket;
506
+ initialCash?: number;
507
+ commission?: number;
508
+ stopLoss?: number;
509
+ sizerPercent?: number;
510
+ autoClose?: boolean;
511
+ }
512
+ interface BacktestResult {
513
+ success: boolean;
514
+ initial_cash: number;
515
+ final_cash: number;
516
+ total_return: number;
517
+ total_return_pct: number;
518
+ max_drawdown: number;
519
+ profit_factor: number;
520
+ win_rate: number;
521
+ total_trades: number;
522
+ trades: Array<{
523
+ date: string;
524
+ action: 'buy' | 'sell';
525
+ price: number;
526
+ quantity: number;
527
+ value: number;
528
+ pnl?: number;
529
+ }>;
530
+ }
531
+ /**
532
+ * Quantitative analysis module
533
+ *
534
+ * @example
535
+ * ```typescript
536
+ * // Compute RSI indicator
537
+ * const data = await client.quant.computeIndicators({
538
+ * symbols: ['000001'],
539
+ * formula: 'RSI(14)'
540
+ * });
541
+ *
542
+ * // Screen stocks by formula
543
+ * const stocks = await client.quant.screen({
544
+ * formula: 'RSI(14) < 30'
545
+ * });
546
+ * ```
547
+ */
548
+ declare class QuantModule {
549
+ private client;
550
+ constructor(client: Reportify);
551
+ /**
552
+ * Get list of available technical indicators
553
+ *
554
+ * @returns Array of indicator definitions
555
+ *
556
+ * @example
557
+ * ```typescript
558
+ * const indicators = await client.quant.listIndicators();
559
+ * indicators.forEach(ind => {
560
+ * console.log(`${ind.name}: ${ind.description}`);
561
+ * console.log(` Fields: ${ind.fields.join(', ')}`);
562
+ * });
563
+ * ```
564
+ */
565
+ listIndicators(): Promise<IndicatorMeta[]>;
566
+ /**
567
+ * Compute indicator values for given symbols
568
+ *
569
+ * @param params - Indicator computation parameters
570
+ * @returns Array of indicator data
571
+ *
572
+ * @example
573
+ * ```typescript
574
+ * // RSI indicator
575
+ * const data = await client.quant.computeIndicators({
576
+ * symbols: ['000001'],
577
+ * formula: 'RSI(14)'
578
+ * });
579
+ *
580
+ * // MACD indicator
581
+ * const data = await client.quant.computeIndicators({
582
+ * symbols: ['000001'],
583
+ * formula: 'MACD()'
584
+ * });
585
+ * ```
586
+ */
587
+ computeIndicators(params: IndicatorComputeParams): Promise<IndicatorData[]>;
588
+ /**
589
+ * Get list of available factors (variables and functions)
590
+ *
591
+ * @returns Array of factor definitions organized by level
592
+ */
593
+ listFactors(): Promise<FactorMeta[]>;
594
+ /**
595
+ * Compute factor values for given symbols
596
+ *
597
+ * Uses Mai-language syntax compatible with TongDaXin/TongHuaShun.
598
+ *
599
+ * @param params - Factor computation parameters
600
+ * @returns Array of factor data
601
+ *
602
+ * @example
603
+ * ```typescript
604
+ * // Simple indicator
605
+ * const data = await client.quant.computeFactors({
606
+ * symbols: ['000001'],
607
+ * formula: 'RSI(14)'
608
+ * });
609
+ *
610
+ * // MACD DIF line
611
+ * const data = await client.quant.computeFactors({
612
+ * symbols: ['000001'],
613
+ * formula: 'MACD().dif'
614
+ * });
615
+ *
616
+ * // Close above 20-day MA
617
+ * const data = await client.quant.computeFactors({
618
+ * symbols: ['000001'],
619
+ * formula: 'CLOSE > MA(20)'
620
+ * });
621
+ * ```
622
+ */
623
+ computeFactors(params: FactorComputeParams): Promise<IndicatorData[]>;
624
+ /**
625
+ * Screen stocks based on factor formula
626
+ *
627
+ * @param params - Screening parameters
628
+ * @returns Array of stocks that passed the filter
629
+ *
630
+ * @example
631
+ * ```typescript
632
+ * // RSI oversold
633
+ * const stocks = await client.quant.screen({
634
+ * formula: 'RSI(14) < 30'
635
+ * });
636
+ *
637
+ * // Golden cross
638
+ * const stocks = await client.quant.screen({
639
+ * formula: 'CROSS(MA(5), MA(10))'
640
+ * });
641
+ *
642
+ * // Uptrend
643
+ * const stocks = await client.quant.screen({
644
+ * formula: '(CLOSE > MA(20)) & (MA(20) > MA(60))'
645
+ * });
646
+ * ```
647
+ */
648
+ screen(params: ScreenParams): Promise<ScreenedStock[]>;
649
+ /**
650
+ * Get OHLCV daily data for a single symbol
651
+ *
652
+ * @param params - OHLCV parameters
653
+ * @returns Array of OHLCV data
654
+ *
655
+ * @example
656
+ * ```typescript
657
+ * const data = await client.quant.ohlcv({
658
+ * symbol: '000001',
659
+ * startDate: '2024-01-01'
660
+ * });
661
+ * ```
662
+ */
663
+ ohlcv(params: OHLCVParams): Promise<OHLCVData[]>;
664
+ /**
665
+ * Get OHLCV data for multiple symbols
666
+ *
667
+ * @param params - Batch OHLCV parameters
668
+ * @returns Array of OHLCV data sorted by date (descending), then by symbol
669
+ *
670
+ * @example
671
+ * ```typescript
672
+ * const data = await client.quant.ohlcvBatch({
673
+ * symbols: ['000001', '600519'],
674
+ * startDate: '2024-01-01'
675
+ * });
676
+ * ```
677
+ */
678
+ ohlcvBatch(params: BatchOHLCVParams): Promise<OHLCVData[]>;
679
+ /**
680
+ * Execute strategy backtest
681
+ *
682
+ * @param params - Backtest parameters
683
+ * @returns Backtest results
684
+ *
685
+ * @example
686
+ * ```typescript
687
+ * const result = await client.quant.backtest({
688
+ * symbol: '000001',
689
+ * formula: 'CROSS(MA(5), MA(20))', // Golden cross buy signal
690
+ * startDate: '2023-01-01',
691
+ * endDate: '2024-01-01',
692
+ * initialCash: 100000
693
+ * });
694
+ *
695
+ * console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
696
+ * console.log(`Max Drawdown: ${(result.max_drawdown * 100).toFixed(2)}%`);
697
+ * console.log(`Win Rate: ${(result.win_rate * 100).toFixed(2)}%`);
698
+ * ```
699
+ */
700
+ backtest(params: BacktestParams): Promise<BacktestResult>;
701
+ }
702
+
429
703
  /**
430
704
  * Reportify Client
431
705
  *
@@ -454,6 +728,7 @@ declare class Reportify {
454
728
  readonly timeline: TimelineModule;
455
729
  readonly kb: KBModule;
456
730
  readonly docs: DocsModule;
731
+ readonly quant: QuantModule;
457
732
  constructor(config: ReportifyConfig);
458
733
  /**
459
734
  * Make an HTTP request to the API
@@ -502,4 +777,4 @@ declare class Reportify {
502
777
  searchTranscripts(query: string, options?: SearchOptions): Promise<Document[]>;
503
778
  }
504
779
 
505
- export { APIError, AuthenticationError, type Chunk, type CompanyInfo, type CompanyOverview, DocsModule, type Document, type EarningsEvent, type FinancialStatement, type IPOEvent, type IPOStatus, type Interval, KBModule, type KBSearchOptions, type Market, NotFoundError, type PaginatedResponse, type Period, type PriceAdjust, type PriceData, type Quote, RateLimitError, Reportify, type ReportifyConfig, ReportifyError, type SearchOptions, type Shareholder, type StockInfo, StockModule, TimelineModule, type TimelineOptions };
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 };
package/dist/index.d.ts CHANGED
@@ -426,6 +426,280 @@ declare class DocsModule {
426
426
  searchChunks(query: string, options?: ChunkSearchOptions): Promise<Chunk[]>;
427
427
  }
428
428
 
429
+ /**
430
+ * Quant Module
431
+ *
432
+ * Provides quantitative analysis tools including indicators, factors, quotes, and backtesting.
433
+ * Based on Mai-language syntax compatible with TongDaXin/TongHuaShun.
434
+ */
435
+
436
+ type StockMarket = 'cn' | 'hk' | 'us';
437
+ interface IndicatorMeta {
438
+ name: string;
439
+ description: string;
440
+ fields: string[];
441
+ }
442
+ interface IndicatorComputeParams {
443
+ symbols: string[];
444
+ formula: string;
445
+ market?: StockMarket;
446
+ startDate?: string;
447
+ endDate?: string;
448
+ }
449
+ interface IndicatorData {
450
+ symbol: string;
451
+ date: string;
452
+ [key: string]: unknown;
453
+ }
454
+ interface FactorMeta {
455
+ name: string;
456
+ type: 'variable' | 'function';
457
+ level: 0 | 1 | 2;
458
+ description: string;
459
+ }
460
+ interface FactorComputeParams {
461
+ symbols: string[];
462
+ formula: string;
463
+ market?: StockMarket;
464
+ startDate?: string;
465
+ endDate?: string;
466
+ }
467
+ interface ScreenParams {
468
+ formula: string;
469
+ market?: StockMarket;
470
+ checkDate?: string;
471
+ symbols?: string[];
472
+ }
473
+ interface ScreenedStock {
474
+ symbol: string;
475
+ close: number;
476
+ factor_value?: number | boolean;
477
+ }
478
+ interface OHLCVParams {
479
+ symbol: string;
480
+ market?: StockMarket;
481
+ startDate?: string;
482
+ endDate?: string;
483
+ }
484
+ interface BatchOHLCVParams {
485
+ symbols: string[];
486
+ market?: StockMarket;
487
+ startDate?: string;
488
+ endDate?: string;
489
+ }
490
+ interface OHLCVData {
491
+ symbol: string;
492
+ date: string;
493
+ open: number;
494
+ high: number;
495
+ low: number;
496
+ close: number;
497
+ volume: number;
498
+ [key: string]: unknown;
499
+ }
500
+ interface BacktestParams {
501
+ symbol: string;
502
+ formula: string;
503
+ startDate: string;
504
+ endDate: string;
505
+ market?: StockMarket;
506
+ initialCash?: number;
507
+ commission?: number;
508
+ stopLoss?: number;
509
+ sizerPercent?: number;
510
+ autoClose?: boolean;
511
+ }
512
+ interface BacktestResult {
513
+ success: boolean;
514
+ initial_cash: number;
515
+ final_cash: number;
516
+ total_return: number;
517
+ total_return_pct: number;
518
+ max_drawdown: number;
519
+ profit_factor: number;
520
+ win_rate: number;
521
+ total_trades: number;
522
+ trades: Array<{
523
+ date: string;
524
+ action: 'buy' | 'sell';
525
+ price: number;
526
+ quantity: number;
527
+ value: number;
528
+ pnl?: number;
529
+ }>;
530
+ }
531
+ /**
532
+ * Quantitative analysis module
533
+ *
534
+ * @example
535
+ * ```typescript
536
+ * // Compute RSI indicator
537
+ * const data = await client.quant.computeIndicators({
538
+ * symbols: ['000001'],
539
+ * formula: 'RSI(14)'
540
+ * });
541
+ *
542
+ * // Screen stocks by formula
543
+ * const stocks = await client.quant.screen({
544
+ * formula: 'RSI(14) < 30'
545
+ * });
546
+ * ```
547
+ */
548
+ declare class QuantModule {
549
+ private client;
550
+ constructor(client: Reportify);
551
+ /**
552
+ * Get list of available technical indicators
553
+ *
554
+ * @returns Array of indicator definitions
555
+ *
556
+ * @example
557
+ * ```typescript
558
+ * const indicators = await client.quant.listIndicators();
559
+ * indicators.forEach(ind => {
560
+ * console.log(`${ind.name}: ${ind.description}`);
561
+ * console.log(` Fields: ${ind.fields.join(', ')}`);
562
+ * });
563
+ * ```
564
+ */
565
+ listIndicators(): Promise<IndicatorMeta[]>;
566
+ /**
567
+ * Compute indicator values for given symbols
568
+ *
569
+ * @param params - Indicator computation parameters
570
+ * @returns Array of indicator data
571
+ *
572
+ * @example
573
+ * ```typescript
574
+ * // RSI indicator
575
+ * const data = await client.quant.computeIndicators({
576
+ * symbols: ['000001'],
577
+ * formula: 'RSI(14)'
578
+ * });
579
+ *
580
+ * // MACD indicator
581
+ * const data = await client.quant.computeIndicators({
582
+ * symbols: ['000001'],
583
+ * formula: 'MACD()'
584
+ * });
585
+ * ```
586
+ */
587
+ computeIndicators(params: IndicatorComputeParams): Promise<IndicatorData[]>;
588
+ /**
589
+ * Get list of available factors (variables and functions)
590
+ *
591
+ * @returns Array of factor definitions organized by level
592
+ */
593
+ listFactors(): Promise<FactorMeta[]>;
594
+ /**
595
+ * Compute factor values for given symbols
596
+ *
597
+ * Uses Mai-language syntax compatible with TongDaXin/TongHuaShun.
598
+ *
599
+ * @param params - Factor computation parameters
600
+ * @returns Array of factor data
601
+ *
602
+ * @example
603
+ * ```typescript
604
+ * // Simple indicator
605
+ * const data = await client.quant.computeFactors({
606
+ * symbols: ['000001'],
607
+ * formula: 'RSI(14)'
608
+ * });
609
+ *
610
+ * // MACD DIF line
611
+ * const data = await client.quant.computeFactors({
612
+ * symbols: ['000001'],
613
+ * formula: 'MACD().dif'
614
+ * });
615
+ *
616
+ * // Close above 20-day MA
617
+ * const data = await client.quant.computeFactors({
618
+ * symbols: ['000001'],
619
+ * formula: 'CLOSE > MA(20)'
620
+ * });
621
+ * ```
622
+ */
623
+ computeFactors(params: FactorComputeParams): Promise<IndicatorData[]>;
624
+ /**
625
+ * Screen stocks based on factor formula
626
+ *
627
+ * @param params - Screening parameters
628
+ * @returns Array of stocks that passed the filter
629
+ *
630
+ * @example
631
+ * ```typescript
632
+ * // RSI oversold
633
+ * const stocks = await client.quant.screen({
634
+ * formula: 'RSI(14) < 30'
635
+ * });
636
+ *
637
+ * // Golden cross
638
+ * const stocks = await client.quant.screen({
639
+ * formula: 'CROSS(MA(5), MA(10))'
640
+ * });
641
+ *
642
+ * // Uptrend
643
+ * const stocks = await client.quant.screen({
644
+ * formula: '(CLOSE > MA(20)) & (MA(20) > MA(60))'
645
+ * });
646
+ * ```
647
+ */
648
+ screen(params: ScreenParams): Promise<ScreenedStock[]>;
649
+ /**
650
+ * Get OHLCV daily data for a single symbol
651
+ *
652
+ * @param params - OHLCV parameters
653
+ * @returns Array of OHLCV data
654
+ *
655
+ * @example
656
+ * ```typescript
657
+ * const data = await client.quant.ohlcv({
658
+ * symbol: '000001',
659
+ * startDate: '2024-01-01'
660
+ * });
661
+ * ```
662
+ */
663
+ ohlcv(params: OHLCVParams): Promise<OHLCVData[]>;
664
+ /**
665
+ * Get OHLCV data for multiple symbols
666
+ *
667
+ * @param params - Batch OHLCV parameters
668
+ * @returns Array of OHLCV data sorted by date (descending), then by symbol
669
+ *
670
+ * @example
671
+ * ```typescript
672
+ * const data = await client.quant.ohlcvBatch({
673
+ * symbols: ['000001', '600519'],
674
+ * startDate: '2024-01-01'
675
+ * });
676
+ * ```
677
+ */
678
+ ohlcvBatch(params: BatchOHLCVParams): Promise<OHLCVData[]>;
679
+ /**
680
+ * Execute strategy backtest
681
+ *
682
+ * @param params - Backtest parameters
683
+ * @returns Backtest results
684
+ *
685
+ * @example
686
+ * ```typescript
687
+ * const result = await client.quant.backtest({
688
+ * symbol: '000001',
689
+ * formula: 'CROSS(MA(5), MA(20))', // Golden cross buy signal
690
+ * startDate: '2023-01-01',
691
+ * endDate: '2024-01-01',
692
+ * initialCash: 100000
693
+ * });
694
+ *
695
+ * console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
696
+ * console.log(`Max Drawdown: ${(result.max_drawdown * 100).toFixed(2)}%`);
697
+ * console.log(`Win Rate: ${(result.win_rate * 100).toFixed(2)}%`);
698
+ * ```
699
+ */
700
+ backtest(params: BacktestParams): Promise<BacktestResult>;
701
+ }
702
+
429
703
  /**
430
704
  * Reportify Client
431
705
  *
@@ -454,6 +728,7 @@ declare class Reportify {
454
728
  readonly timeline: TimelineModule;
455
729
  readonly kb: KBModule;
456
730
  readonly docs: DocsModule;
731
+ readonly quant: QuantModule;
457
732
  constructor(config: ReportifyConfig);
458
733
  /**
459
734
  * Make an HTTP request to the API
@@ -502,4 +777,4 @@ declare class Reportify {
502
777
  searchTranscripts(query: string, options?: SearchOptions): Promise<Document[]>;
503
778
  }
504
779
 
505
- export { APIError, AuthenticationError, type Chunk, type CompanyInfo, type CompanyOverview, DocsModule, type Document, type EarningsEvent, type FinancialStatement, type IPOEvent, type IPOStatus, type Interval, KBModule, type KBSearchOptions, type Market, NotFoundError, type PaginatedResponse, type Period, type PriceAdjust, type PriceData, type Quote, RateLimitError, Reportify, type ReportifyConfig, ReportifyError, type SearchOptions, type Shareholder, type StockInfo, StockModule, TimelineModule, type TimelineOptions };
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 };
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ __export(index_exports, {
25
25
  DocsModule: () => DocsModule,
26
26
  KBModule: () => KBModule,
27
27
  NotFoundError: () => NotFoundError,
28
+ QuantModule: () => QuantModule,
28
29
  RateLimitError: () => RateLimitError,
29
30
  Reportify: () => Reportify,
30
31
  ReportifyError: () => ReportifyError,
@@ -455,6 +456,234 @@ var DocsModule = class {
455
456
  }
456
457
  };
457
458
 
459
+ // src/quant.ts
460
+ var QuantModule = class {
461
+ constructor(client) {
462
+ this.client = client;
463
+ }
464
+ // ===========================================================================
465
+ // Indicators
466
+ // ===========================================================================
467
+ /**
468
+ * Get list of available technical indicators
469
+ *
470
+ * @returns Array of indicator definitions
471
+ *
472
+ * @example
473
+ * ```typescript
474
+ * const indicators = await client.quant.listIndicators();
475
+ * indicators.forEach(ind => {
476
+ * console.log(`${ind.name}: ${ind.description}`);
477
+ * console.log(` Fields: ${ind.fields.join(', ')}`);
478
+ * });
479
+ * ```
480
+ */
481
+ async listIndicators() {
482
+ return this.client.get("/v1/quant/indicators");
483
+ }
484
+ /**
485
+ * Compute indicator values for given symbols
486
+ *
487
+ * @param params - Indicator computation parameters
488
+ * @returns Array of indicator data
489
+ *
490
+ * @example
491
+ * ```typescript
492
+ * // RSI indicator
493
+ * const data = await client.quant.computeIndicators({
494
+ * symbols: ['000001'],
495
+ * formula: 'RSI(14)'
496
+ * });
497
+ *
498
+ * // MACD indicator
499
+ * const data = await client.quant.computeIndicators({
500
+ * symbols: ['000001'],
501
+ * formula: 'MACD()'
502
+ * });
503
+ * ```
504
+ */
505
+ async computeIndicators(params) {
506
+ const response = await this.client.post("/v1/quant/indicators/compute", {
507
+ symbols: params.symbols,
508
+ formula: params.formula,
509
+ market: params.market || "cn",
510
+ start_date: params.startDate,
511
+ end_date: params.endDate
512
+ });
513
+ return response.datas || [];
514
+ }
515
+ // ===========================================================================
516
+ // Factors
517
+ // ===========================================================================
518
+ /**
519
+ * Get list of available factors (variables and functions)
520
+ *
521
+ * @returns Array of factor definitions organized by level
522
+ */
523
+ async listFactors() {
524
+ return this.client.get("/v1/quant/factors");
525
+ }
526
+ /**
527
+ * Compute factor values for given symbols
528
+ *
529
+ * Uses Mai-language syntax compatible with TongDaXin/TongHuaShun.
530
+ *
531
+ * @param params - Factor computation parameters
532
+ * @returns Array of factor data
533
+ *
534
+ * @example
535
+ * ```typescript
536
+ * // Simple indicator
537
+ * const data = await client.quant.computeFactors({
538
+ * symbols: ['000001'],
539
+ * formula: 'RSI(14)'
540
+ * });
541
+ *
542
+ * // MACD DIF line
543
+ * const data = await client.quant.computeFactors({
544
+ * symbols: ['000001'],
545
+ * formula: 'MACD().dif'
546
+ * });
547
+ *
548
+ * // Close above 20-day MA
549
+ * const data = await client.quant.computeFactors({
550
+ * symbols: ['000001'],
551
+ * formula: 'CLOSE > MA(20)'
552
+ * });
553
+ * ```
554
+ */
555
+ async computeFactors(params) {
556
+ const response = await this.client.post("/v1/quant/factors/compute", {
557
+ symbols: params.symbols,
558
+ formula: params.formula,
559
+ market: params.market || "cn",
560
+ start_date: params.startDate,
561
+ end_date: params.endDate
562
+ });
563
+ return response.datas || [];
564
+ }
565
+ /**
566
+ * Screen stocks based on factor formula
567
+ *
568
+ * @param params - Screening parameters
569
+ * @returns Array of stocks that passed the filter
570
+ *
571
+ * @example
572
+ * ```typescript
573
+ * // RSI oversold
574
+ * const stocks = await client.quant.screen({
575
+ * formula: 'RSI(14) < 30'
576
+ * });
577
+ *
578
+ * // Golden cross
579
+ * const stocks = await client.quant.screen({
580
+ * formula: 'CROSS(MA(5), MA(10))'
581
+ * });
582
+ *
583
+ * // Uptrend
584
+ * const stocks = await client.quant.screen({
585
+ * formula: '(CLOSE > MA(20)) & (MA(20) > MA(60))'
586
+ * });
587
+ * ```
588
+ */
589
+ async screen(params) {
590
+ const response = await this.client.post("/v1/quant/factors/screen", {
591
+ formula: params.formula,
592
+ market: params.market || "cn",
593
+ check_date: params.checkDate,
594
+ symbols: params.symbols
595
+ });
596
+ return response.datas || [];
597
+ }
598
+ // ===========================================================================
599
+ // Quotes
600
+ // ===========================================================================
601
+ /**
602
+ * Get OHLCV daily data for a single symbol
603
+ *
604
+ * @param params - OHLCV parameters
605
+ * @returns Array of OHLCV data
606
+ *
607
+ * @example
608
+ * ```typescript
609
+ * const data = await client.quant.ohlcv({
610
+ * symbol: '000001',
611
+ * startDate: '2024-01-01'
612
+ * });
613
+ * ```
614
+ */
615
+ async ohlcv(params) {
616
+ const response = await this.client.get("/v1/quant/quotes/ohlcv", {
617
+ symbol: params.symbol,
618
+ market: params.market || "cn",
619
+ start_date: params.startDate,
620
+ end_date: params.endDate
621
+ });
622
+ return response.datas || [];
623
+ }
624
+ /**
625
+ * Get OHLCV data for multiple symbols
626
+ *
627
+ * @param params - Batch OHLCV parameters
628
+ * @returns Array of OHLCV data sorted by date (descending), then by symbol
629
+ *
630
+ * @example
631
+ * ```typescript
632
+ * const data = await client.quant.ohlcvBatch({
633
+ * symbols: ['000001', '600519'],
634
+ * startDate: '2024-01-01'
635
+ * });
636
+ * ```
637
+ */
638
+ async ohlcvBatch(params) {
639
+ const response = await this.client.post("/v1/quant/quotes/ohlcv/batch", {
640
+ symbols: params.symbols,
641
+ market: params.market || "cn",
642
+ start_date: params.startDate,
643
+ end_date: params.endDate
644
+ });
645
+ return response.datas || [];
646
+ }
647
+ // ===========================================================================
648
+ // Backtest
649
+ // ===========================================================================
650
+ /**
651
+ * Execute strategy backtest
652
+ *
653
+ * @param params - Backtest parameters
654
+ * @returns Backtest results
655
+ *
656
+ * @example
657
+ * ```typescript
658
+ * const result = await client.quant.backtest({
659
+ * symbol: '000001',
660
+ * formula: 'CROSS(MA(5), MA(20))', // Golden cross buy signal
661
+ * startDate: '2023-01-01',
662
+ * endDate: '2024-01-01',
663
+ * initialCash: 100000
664
+ * });
665
+ *
666
+ * console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
667
+ * console.log(`Max Drawdown: ${(result.max_drawdown * 100).toFixed(2)}%`);
668
+ * console.log(`Win Rate: ${(result.win_rate * 100).toFixed(2)}%`);
669
+ * ```
670
+ */
671
+ async backtest(params) {
672
+ return this.client.post("/v1/quant/backtest", {
673
+ symbol: params.symbol,
674
+ formula: params.formula,
675
+ start_date: params.startDate,
676
+ end_date: params.endDate,
677
+ market: params.market || "cn",
678
+ initial_cash: params.initialCash ?? 1e5,
679
+ commission: params.commission ?? 0,
680
+ stop_loss: params.stopLoss ?? 0,
681
+ sizer_percent: params.sizerPercent ?? 99,
682
+ auto_close: params.autoClose ?? true
683
+ });
684
+ }
685
+ };
686
+
458
687
  // src/types.ts
459
688
  var ReportifyError = class extends Error {
460
689
  statusCode;
@@ -501,6 +730,7 @@ var Reportify = class {
501
730
  timeline;
502
731
  kb;
503
732
  docs;
733
+ quant;
504
734
  constructor(config) {
505
735
  if (!config.apiKey) {
506
736
  throw new AuthenticationError("API key is required");
@@ -512,6 +742,7 @@ var Reportify = class {
512
742
  this.timeline = new TimelineModule(this);
513
743
  this.kb = new KBModule(this);
514
744
  this.docs = new DocsModule(this);
745
+ this.quant = new QuantModule(this);
515
746
  }
516
747
  /**
517
748
  * Make an HTTP request to the API
@@ -665,6 +896,7 @@ var Reportify = class {
665
896
  DocsModule,
666
897
  KBModule,
667
898
  NotFoundError,
899
+ QuantModule,
668
900
  RateLimitError,
669
901
  Reportify,
670
902
  ReportifyError,
package/dist/index.mjs CHANGED
@@ -420,6 +420,234 @@ var DocsModule = class {
420
420
  }
421
421
  };
422
422
 
423
+ // src/quant.ts
424
+ var QuantModule = class {
425
+ constructor(client) {
426
+ this.client = client;
427
+ }
428
+ // ===========================================================================
429
+ // Indicators
430
+ // ===========================================================================
431
+ /**
432
+ * Get list of available technical indicators
433
+ *
434
+ * @returns Array of indicator definitions
435
+ *
436
+ * @example
437
+ * ```typescript
438
+ * const indicators = await client.quant.listIndicators();
439
+ * indicators.forEach(ind => {
440
+ * console.log(`${ind.name}: ${ind.description}`);
441
+ * console.log(` Fields: ${ind.fields.join(', ')}`);
442
+ * });
443
+ * ```
444
+ */
445
+ async listIndicators() {
446
+ return this.client.get("/v1/quant/indicators");
447
+ }
448
+ /**
449
+ * Compute indicator values for given symbols
450
+ *
451
+ * @param params - Indicator computation parameters
452
+ * @returns Array of indicator data
453
+ *
454
+ * @example
455
+ * ```typescript
456
+ * // RSI indicator
457
+ * const data = await client.quant.computeIndicators({
458
+ * symbols: ['000001'],
459
+ * formula: 'RSI(14)'
460
+ * });
461
+ *
462
+ * // MACD indicator
463
+ * const data = await client.quant.computeIndicators({
464
+ * symbols: ['000001'],
465
+ * formula: 'MACD()'
466
+ * });
467
+ * ```
468
+ */
469
+ async computeIndicators(params) {
470
+ const response = await this.client.post("/v1/quant/indicators/compute", {
471
+ symbols: params.symbols,
472
+ formula: params.formula,
473
+ market: params.market || "cn",
474
+ start_date: params.startDate,
475
+ end_date: params.endDate
476
+ });
477
+ return response.datas || [];
478
+ }
479
+ // ===========================================================================
480
+ // Factors
481
+ // ===========================================================================
482
+ /**
483
+ * Get list of available factors (variables and functions)
484
+ *
485
+ * @returns Array of factor definitions organized by level
486
+ */
487
+ async listFactors() {
488
+ return this.client.get("/v1/quant/factors");
489
+ }
490
+ /**
491
+ * Compute factor values for given symbols
492
+ *
493
+ * Uses Mai-language syntax compatible with TongDaXin/TongHuaShun.
494
+ *
495
+ * @param params - Factor computation parameters
496
+ * @returns Array of factor data
497
+ *
498
+ * @example
499
+ * ```typescript
500
+ * // Simple indicator
501
+ * const data = await client.quant.computeFactors({
502
+ * symbols: ['000001'],
503
+ * formula: 'RSI(14)'
504
+ * });
505
+ *
506
+ * // MACD DIF line
507
+ * const data = await client.quant.computeFactors({
508
+ * symbols: ['000001'],
509
+ * formula: 'MACD().dif'
510
+ * });
511
+ *
512
+ * // Close above 20-day MA
513
+ * const data = await client.quant.computeFactors({
514
+ * symbols: ['000001'],
515
+ * formula: 'CLOSE > MA(20)'
516
+ * });
517
+ * ```
518
+ */
519
+ async computeFactors(params) {
520
+ const response = await this.client.post("/v1/quant/factors/compute", {
521
+ symbols: params.symbols,
522
+ formula: params.formula,
523
+ market: params.market || "cn",
524
+ start_date: params.startDate,
525
+ end_date: params.endDate
526
+ });
527
+ return response.datas || [];
528
+ }
529
+ /**
530
+ * Screen stocks based on factor formula
531
+ *
532
+ * @param params - Screening parameters
533
+ * @returns Array of stocks that passed the filter
534
+ *
535
+ * @example
536
+ * ```typescript
537
+ * // RSI oversold
538
+ * const stocks = await client.quant.screen({
539
+ * formula: 'RSI(14) < 30'
540
+ * });
541
+ *
542
+ * // Golden cross
543
+ * const stocks = await client.quant.screen({
544
+ * formula: 'CROSS(MA(5), MA(10))'
545
+ * });
546
+ *
547
+ * // Uptrend
548
+ * const stocks = await client.quant.screen({
549
+ * formula: '(CLOSE > MA(20)) & (MA(20) > MA(60))'
550
+ * });
551
+ * ```
552
+ */
553
+ async screen(params) {
554
+ const response = await this.client.post("/v1/quant/factors/screen", {
555
+ formula: params.formula,
556
+ market: params.market || "cn",
557
+ check_date: params.checkDate,
558
+ symbols: params.symbols
559
+ });
560
+ return response.datas || [];
561
+ }
562
+ // ===========================================================================
563
+ // Quotes
564
+ // ===========================================================================
565
+ /**
566
+ * Get OHLCV daily data for a single symbol
567
+ *
568
+ * @param params - OHLCV parameters
569
+ * @returns Array of OHLCV data
570
+ *
571
+ * @example
572
+ * ```typescript
573
+ * const data = await client.quant.ohlcv({
574
+ * symbol: '000001',
575
+ * startDate: '2024-01-01'
576
+ * });
577
+ * ```
578
+ */
579
+ async ohlcv(params) {
580
+ const response = await this.client.get("/v1/quant/quotes/ohlcv", {
581
+ symbol: params.symbol,
582
+ market: params.market || "cn",
583
+ start_date: params.startDate,
584
+ end_date: params.endDate
585
+ });
586
+ return response.datas || [];
587
+ }
588
+ /**
589
+ * Get OHLCV data for multiple symbols
590
+ *
591
+ * @param params - Batch OHLCV parameters
592
+ * @returns Array of OHLCV data sorted by date (descending), then by symbol
593
+ *
594
+ * @example
595
+ * ```typescript
596
+ * const data = await client.quant.ohlcvBatch({
597
+ * symbols: ['000001', '600519'],
598
+ * startDate: '2024-01-01'
599
+ * });
600
+ * ```
601
+ */
602
+ async ohlcvBatch(params) {
603
+ const response = await this.client.post("/v1/quant/quotes/ohlcv/batch", {
604
+ symbols: params.symbols,
605
+ market: params.market || "cn",
606
+ start_date: params.startDate,
607
+ end_date: params.endDate
608
+ });
609
+ return response.datas || [];
610
+ }
611
+ // ===========================================================================
612
+ // Backtest
613
+ // ===========================================================================
614
+ /**
615
+ * Execute strategy backtest
616
+ *
617
+ * @param params - Backtest parameters
618
+ * @returns Backtest results
619
+ *
620
+ * @example
621
+ * ```typescript
622
+ * const result = await client.quant.backtest({
623
+ * symbol: '000001',
624
+ * formula: 'CROSS(MA(5), MA(20))', // Golden cross buy signal
625
+ * startDate: '2023-01-01',
626
+ * endDate: '2024-01-01',
627
+ * initialCash: 100000
628
+ * });
629
+ *
630
+ * console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
631
+ * console.log(`Max Drawdown: ${(result.max_drawdown * 100).toFixed(2)}%`);
632
+ * console.log(`Win Rate: ${(result.win_rate * 100).toFixed(2)}%`);
633
+ * ```
634
+ */
635
+ async backtest(params) {
636
+ return this.client.post("/v1/quant/backtest", {
637
+ symbol: params.symbol,
638
+ formula: params.formula,
639
+ start_date: params.startDate,
640
+ end_date: params.endDate,
641
+ market: params.market || "cn",
642
+ initial_cash: params.initialCash ?? 1e5,
643
+ commission: params.commission ?? 0,
644
+ stop_loss: params.stopLoss ?? 0,
645
+ sizer_percent: params.sizerPercent ?? 99,
646
+ auto_close: params.autoClose ?? true
647
+ });
648
+ }
649
+ };
650
+
423
651
  // src/types.ts
424
652
  var ReportifyError = class extends Error {
425
653
  statusCode;
@@ -466,6 +694,7 @@ var Reportify = class {
466
694
  timeline;
467
695
  kb;
468
696
  docs;
697
+ quant;
469
698
  constructor(config) {
470
699
  if (!config.apiKey) {
471
700
  throw new AuthenticationError("API key is required");
@@ -477,6 +706,7 @@ var Reportify = class {
477
706
  this.timeline = new TimelineModule(this);
478
707
  this.kb = new KBModule(this);
479
708
  this.docs = new DocsModule(this);
709
+ this.quant = new QuantModule(this);
480
710
  }
481
711
  /**
482
712
  * Make an HTTP request to the API
@@ -629,6 +859,7 @@ export {
629
859
  DocsModule,
630
860
  KBModule,
631
861
  NotFoundError,
862
+ QuantModule,
632
863
  RateLimitError,
633
864
  Reportify,
634
865
  ReportifyError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reportify-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "TypeScript SDK for Reportify API - Financial data and document search",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",