reportify-sdk 0.2.0 → 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 CHANGED
@@ -430,125 +430,120 @@ declare class DocsModule {
430
430
  * Quant Module
431
431
  *
432
432
  * Provides quantitative analysis tools including indicators, factors, quotes, and backtesting.
433
+ * Based on Mai-language syntax compatible with TongDaXin/TongHuaShun.
433
434
  */
434
435
 
435
- interface IndicatorParams {
436
- symbols: string[];
437
- indicators: string[];
438
- startDate?: string;
439
- endDate?: string;
440
- interval?: '1d' | '1w' | '1m';
441
- params?: Record<string, unknown>;
442
- }
443
- interface IndicatorDefinition {
436
+ type StockMarket = 'cn' | 'hk' | 'us';
437
+ interface IndicatorMeta {
444
438
  name: string;
445
439
  description: string;
446
- category: string;
447
- parameters: Array<{
448
- name: string;
449
- type: string;
450
- default?: unknown;
451
- description: string;
452
- }>;
440
+ fields: string[];
453
441
  }
454
- interface FactorParams {
442
+ interface IndicatorComputeParams {
455
443
  symbols: string[];
456
- factors: string[];
444
+ formula: string;
445
+ market?: StockMarket;
457
446
  startDate?: string;
458
447
  endDate?: string;
459
- frequency?: 'daily' | 'weekly' | 'monthly';
460
448
  }
461
- interface FactorDefinition {
449
+ interface IndicatorData {
450
+ symbol: string;
451
+ date: string;
452
+ [key: string]: unknown;
453
+ }
454
+ interface FactorMeta {
462
455
  name: string;
463
- category: string;
456
+ type: 'variable' | 'function';
457
+ level: 0 | 1 | 2;
464
458
  description: string;
465
459
  }
466
- interface QuoteParams {
467
- symbols: string[];
468
- fields?: string[];
469
- }
470
- interface QuoteHistoryParams {
460
+ interface FactorComputeParams {
471
461
  symbols: string[];
462
+ formula: string;
463
+ market?: StockMarket;
472
464
  startDate?: string;
473
465
  endDate?: string;
474
- interval?: '1d' | '1w' | '1m';
475
- adjust?: 'forward' | 'backward' | 'none';
476
- limit?: number;
477
- }
478
- interface BacktestStrategy {
479
- type: string;
480
- universe: string[];
481
- rebalance?: 'daily' | 'weekly' | 'monthly' | 'quarterly';
482
- [key: string]: unknown;
483
466
  }
484
- interface BacktestParams {
485
- strategy: BacktestStrategy;
486
- startDate: string;
487
- endDate: string;
488
- initialCapital?: number;
489
- benchmark?: string;
490
- }
491
- interface BacktestMetrics {
492
- totalReturn: number;
493
- annualizedReturn: number;
494
- sharpeRatio: number;
495
- maxDrawdown: number;
496
- winRate: number;
497
- volatility: number;
498
- }
499
- interface BacktestResult {
500
- backtestId: string;
501
- status: 'pending' | 'running' | 'completed' | 'failed';
502
- metrics?: BacktestMetrics;
503
- error?: string;
467
+ interface ScreenParams {
468
+ formula: string;
469
+ market?: StockMarket;
470
+ checkDate?: string;
471
+ symbols?: string[];
504
472
  }
505
- interface IndicatorData {
506
- date: string;
473
+ interface ScreenedStock {
507
474
  symbol: string;
508
- [key: string]: unknown;
475
+ close: number;
476
+ factor_value?: number | boolean;
509
477
  }
510
- interface FactorData {
511
- date: string;
478
+ interface OHLCVParams {
512
479
  symbol: string;
513
- [key: string]: unknown;
480
+ market?: StockMarket;
481
+ startDate?: string;
482
+ endDate?: string;
514
483
  }
515
- interface QuoteData {
484
+ interface BatchOHLCVParams {
485
+ symbols: string[];
486
+ market?: StockMarket;
487
+ startDate?: string;
488
+ endDate?: string;
489
+ }
490
+ interface OHLCVData {
516
491
  symbol: string;
517
- price: number;
518
- change: number;
519
- changePercent: number;
520
- volume: number;
492
+ date: string;
493
+ open: number;
521
494
  high: number;
522
495
  low: number;
523
- open: number;
524
- previousClose: number;
525
- marketCap?: number;
526
- timestamp: number;
496
+ close: number;
497
+ volume: number;
498
+ [key: string]: unknown;
527
499
  }
528
- interface TradeData {
529
- date: string;
500
+ interface BacktestParams {
501
+ startDate: string;
502
+ endDate: string;
530
503
  symbol: string;
531
- action: 'buy' | 'sell';
532
- quantity: number;
533
- price: number;
534
- value: number;
504
+ market?: StockMarket;
505
+ entryFormula: string;
506
+ exitFormula?: string;
507
+ initialCash?: number;
508
+ commission?: number;
509
+ stopLoss?: number;
510
+ sizerPercent?: number;
511
+ autoClose?: boolean;
512
+ labels?: Record<string, string>;
535
513
  }
536
- interface ReturnData {
537
- date: string;
538
- portfolioValue: number;
539
- dailyReturn: number;
540
- cumulativeReturn: number;
541
- benchmarkReturn?: number;
514
+ interface BacktestResult {
515
+ success: boolean;
516
+ initial_cash: number;
517
+ final_cash: number;
518
+ total_return: number;
519
+ total_return_pct: number;
520
+ max_drawdown: number;
521
+ profit_factor: number;
522
+ win_rate: number;
523
+ total_trades: number;
524
+ trades: Array<{
525
+ date: string;
526
+ action: 'buy' | 'sell';
527
+ price: number;
528
+ quantity: number;
529
+ value: number;
530
+ pnl?: number;
531
+ }>;
542
532
  }
543
533
  /**
544
534
  * Quantitative analysis module
545
535
  *
546
536
  * @example
547
537
  * ```typescript
548
- * const indicators = await client.quant.indicators({
549
- * symbols: ['US:AAPL'],
550
- * indicators: ['ma', 'rsi'],
551
- * params: { ma_period: 20 }
538
+ * // Compute RSI indicator
539
+ * const data = await client.quant.computeIndicators({
540
+ * symbols: ['000001'],
541
+ * formula: 'RSI(14)'
542
+ * });
543
+ *
544
+ * // Screen stocks by formula
545
+ * const stocks = await client.quant.screen({
546
+ * formula: 'RSI(14) < 30'
552
547
  * });
553
548
  * ```
554
549
  */
@@ -556,88 +551,175 @@ declare class QuantModule {
556
551
  private client;
557
552
  constructor(client: Reportify);
558
553
  /**
559
- * Get technical indicators for given symbols
554
+ * Get list of available technical indicators
560
555
  *
561
- * @param params - Indicator parameters
562
- * @returns Array of indicator data
556
+ * @returns Array of indicator definitions
557
+ *
558
+ * @example
559
+ * ```typescript
560
+ * const indicators = await client.quant.listIndicators();
561
+ * indicators.forEach(ind => {
562
+ * console.log(`${ind.name}: ${ind.description}`);
563
+ * console.log(` Fields: ${ind.fields.join(', ')}`);
564
+ * });
565
+ * ```
563
566
  */
564
- indicators(params: IndicatorParams): Promise<IndicatorData[]>;
567
+ listIndicators(): Promise<IndicatorMeta[]>;
565
568
  /**
566
- * Get list of available technical indicators
569
+ * Compute indicator values for given symbols
570
+ *
571
+ * @param params - Indicator computation parameters
572
+ * @returns Array of indicator data
573
+ *
574
+ * @example
575
+ * ```typescript
576
+ * // RSI indicator
577
+ * const data = await client.quant.computeIndicators({
578
+ * symbols: ['000001'],
579
+ * formula: 'RSI(14)'
580
+ * });
581
+ *
582
+ * // MACD indicator
583
+ * const data = await client.quant.computeIndicators({
584
+ * symbols: ['000001'],
585
+ * formula: 'MACD()'
586
+ * });
587
+ * ```
567
588
  */
568
- indicatorList(): Promise<IndicatorDefinition[]>;
589
+ computeIndicators(params: IndicatorComputeParams): Promise<IndicatorData[]>;
569
590
  /**
570
- * Get factor data for given symbols
591
+ * Get list of available factors (variables and functions)
571
592
  *
572
- * @param params - Factor parameters
573
- * @returns Array of factor data
593
+ * @returns Array of factor definitions organized by level
574
594
  */
575
- factors(params: FactorParams): Promise<FactorData[]>;
595
+ listFactors(): Promise<FactorMeta[]>;
576
596
  /**
577
- * Get list of available factors
597
+ * Compute factor values for given symbols
598
+ *
599
+ * Uses Mai-language syntax compatible with TongDaXin/TongHuaShun.
600
+ *
601
+ * @param params - Factor computation parameters
602
+ * @returns Array of factor data
603
+ *
604
+ * @example
605
+ * ```typescript
606
+ * // Simple indicator
607
+ * const data = await client.quant.computeFactors({
608
+ * symbols: ['000001'],
609
+ * formula: 'RSI(14)'
610
+ * });
611
+ *
612
+ * // MACD DIF line
613
+ * const data = await client.quant.computeFactors({
614
+ * symbols: ['000001'],
615
+ * formula: 'MACD().dif'
616
+ * });
617
+ *
618
+ * // Close above 20-day MA
619
+ * const data = await client.quant.computeFactors({
620
+ * symbols: ['000001'],
621
+ * formula: 'CLOSE > MA(20)'
622
+ * });
623
+ * ```
578
624
  */
579
- factorList(): Promise<FactorDefinition[]>;
625
+ computeFactors(params: FactorComputeParams): Promise<IndicatorData[]>;
580
626
  /**
581
- * Get factor exposure for given symbols
627
+ * Screen stocks based on factor formula
628
+ *
629
+ * @param params - Screening parameters
630
+ * @returns Array of stocks that passed the filter
582
631
  *
583
- * @param symbols - Stock symbols
584
- * @param date - Specific date (optional)
632
+ * @example
633
+ * ```typescript
634
+ * // RSI oversold
635
+ * const stocks = await client.quant.screen({
636
+ * formula: 'RSI(14) < 30'
637
+ * });
638
+ *
639
+ * // Golden cross
640
+ * const stocks = await client.quant.screen({
641
+ * formula: 'CROSS(MA(5), MA(10))'
642
+ * });
643
+ *
644
+ * // Uptrend
645
+ * const stocks = await client.quant.screen({
646
+ * formula: '(CLOSE > MA(20)) & (MA(20) > MA(60))'
647
+ * });
648
+ * ```
585
649
  */
586
- factorExposure(symbols: string[], date?: string): Promise<FactorData[]>;
650
+ screen(params: ScreenParams): Promise<ScreenedStock[]>;
587
651
  /**
588
- * Get real-time quotes for given symbols
652
+ * Get OHLCV daily data for a single symbol
653
+ *
654
+ * @param params - OHLCV parameters
655
+ * @returns Array of OHLCV data
589
656
  *
590
- * @param params - Quote parameters
591
- * @returns Array of quote data
657
+ * @example
658
+ * ```typescript
659
+ * const data = await client.quant.ohlcv({
660
+ * symbol: '000001',
661
+ * startDate: '2024-01-01'
662
+ * });
663
+ * ```
592
664
  */
593
- quotes(params: QuoteParams): Promise<QuoteData[]>;
665
+ ohlcv(params: OHLCVParams): Promise<OHLCVData[]>;
594
666
  /**
595
- * Get historical quotes data
667
+ * Get OHLCV data for multiple symbols
596
668
  *
597
- * @param params - History parameters
598
- * @returns Array of historical OHLCV data
669
+ * @param params - Batch OHLCV parameters
670
+ * @returns Array of OHLCV data sorted by date (descending), then by symbol
671
+ *
672
+ * @example
673
+ * ```typescript
674
+ * const data = await client.quant.ohlcvBatch({
675
+ * symbols: ['000001', '600519'],
676
+ * startDate: '2024-01-01'
677
+ * });
678
+ * ```
599
679
  */
600
- quotesHistory(params: QuoteHistoryParams): Promise<IndicatorData[]>;
680
+ ohlcvBatch(params: BatchOHLCVParams): Promise<OHLCVData[]>;
601
681
  /**
602
- * Run a backtest for a given strategy
682
+ * Execute strategy backtest
603
683
  *
604
684
  * @param params - Backtest parameters
605
- * @returns Backtest result with job ID and metrics
685
+ * @returns Backtest results
606
686
  *
607
687
  * @example
608
688
  * ```typescript
689
+ * // Simple golden cross strategy
609
690
  * const result = await client.quant.backtest({
610
- * strategy: {
611
- * type: 'momentum',
612
- * universe: ['US:AAPL', 'US:MSFT', 'US:GOOGL'],
613
- * rebalance: 'monthly',
614
- * top_n: 2
615
- * },
616
- * startDate: '2020-01-01',
691
+ * startDate: '2023-01-01',
617
692
  * endDate: '2024-01-01',
618
- * benchmark: 'US:SPY'
693
+ * symbol: '000001',
694
+ * entryFormula: 'CROSS(MA(5), MA(20))', // Buy when MA5 crosses above MA20
695
+ * initialCash: 100000
619
696
  * });
620
- * ```
621
- */
622
- backtest(params: BacktestParams): Promise<BacktestResult>;
623
- /**
624
- * Get backtest result by ID
625
697
  *
626
- * @param backtestId - Backtest job ID
627
- */
628
- backtestResult(backtestId: string): Promise<BacktestResult>;
629
- /**
630
- * Get backtest return series
698
+ * console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
699
+ * console.log(`Max Drawdown: ${(result.max_drawdown * 100).toFixed(2)}%`);
700
+ * console.log(`Win Rate: ${(result.win_rate * 100).toFixed(2)}%`);
631
701
  *
632
- * @param backtestId - Backtest job ID
633
- */
634
- backtestReturns(backtestId: string): Promise<ReturnData[]>;
635
- /**
636
- * Get backtest trade history
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
+ * });
637
710
  *
638
- * @param backtestId - Backtest job ID
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
+ * });
720
+ * ```
639
721
  */
640
- backtestTrades(backtestId: string): Promise<TradeData[]>;
722
+ backtest(params: BacktestParams): Promise<BacktestResult>;
641
723
  }
642
724
 
643
725
  /**
@@ -717,4 +799,4 @@ declare class Reportify {
717
799
  searchTranscripts(query: string, options?: SearchOptions): Promise<Document[]>;
718
800
  }
719
801
 
720
- export { APIError, AuthenticationError, type BacktestMetrics, type BacktestParams, type BacktestResult, type BacktestStrategy, type Chunk, type CompanyInfo, type CompanyOverview, DocsModule, type Document, type EarningsEvent, type FactorData, type FactorDefinition, type FactorParams, type FinancialStatement, type IPOEvent, type IPOStatus, type IndicatorData, type IndicatorDefinition, type IndicatorParams, type Interval, KBModule, type KBSearchOptions, type Market, NotFoundError, type PaginatedResponse, type Period, type PriceAdjust, type PriceData, QuantModule, type Quote, type QuoteData, type QuoteHistoryParams, type QuoteParams, RateLimitError, Reportify, type ReportifyConfig, ReportifyError, type ReturnData, type SearchOptions, type Shareholder, type StockInfo, StockModule, TimelineModule, type TimelineOptions, type TradeData };
802
+ 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 };