reportify-sdk 0.2.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 +199 -139
- package/dist/index.d.ts +199 -139
- package/dist/index.js +160 -97
- package/dist/index.mjs +160 -97
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -430,125 +430,118 @@ 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
|
-
|
|
436
|
-
|
|
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
|
-
|
|
447
|
-
parameters: Array<{
|
|
448
|
-
name: string;
|
|
449
|
-
type: string;
|
|
450
|
-
default?: unknown;
|
|
451
|
-
description: string;
|
|
452
|
-
}>;
|
|
440
|
+
fields: string[];
|
|
453
441
|
}
|
|
454
|
-
interface
|
|
442
|
+
interface IndicatorComputeParams {
|
|
455
443
|
symbols: string[];
|
|
456
|
-
|
|
444
|
+
formula: string;
|
|
445
|
+
market?: StockMarket;
|
|
457
446
|
startDate?: string;
|
|
458
447
|
endDate?: string;
|
|
459
|
-
frequency?: 'daily' | 'weekly' | 'monthly';
|
|
460
448
|
}
|
|
461
|
-
interface
|
|
449
|
+
interface IndicatorData {
|
|
450
|
+
symbol: string;
|
|
451
|
+
date: string;
|
|
452
|
+
[key: string]: unknown;
|
|
453
|
+
}
|
|
454
|
+
interface FactorMeta {
|
|
462
455
|
name: string;
|
|
463
|
-
|
|
456
|
+
type: 'variable' | 'function';
|
|
457
|
+
level: 0 | 1 | 2;
|
|
464
458
|
description: string;
|
|
465
459
|
}
|
|
466
|
-
interface
|
|
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
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
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
|
|
506
|
-
date: string;
|
|
473
|
+
interface ScreenedStock {
|
|
507
474
|
symbol: string;
|
|
508
|
-
|
|
475
|
+
close: number;
|
|
476
|
+
factor_value?: number | boolean;
|
|
509
477
|
}
|
|
510
|
-
interface
|
|
511
|
-
date: string;
|
|
478
|
+
interface OHLCVParams {
|
|
512
479
|
symbol: string;
|
|
513
|
-
|
|
480
|
+
market?: StockMarket;
|
|
481
|
+
startDate?: string;
|
|
482
|
+
endDate?: string;
|
|
514
483
|
}
|
|
515
|
-
interface
|
|
484
|
+
interface BatchOHLCVParams {
|
|
485
|
+
symbols: string[];
|
|
486
|
+
market?: StockMarket;
|
|
487
|
+
startDate?: string;
|
|
488
|
+
endDate?: string;
|
|
489
|
+
}
|
|
490
|
+
interface OHLCVData {
|
|
516
491
|
symbol: string;
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
changePercent: number;
|
|
520
|
-
volume: number;
|
|
492
|
+
date: string;
|
|
493
|
+
open: number;
|
|
521
494
|
high: number;
|
|
522
495
|
low: number;
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
timestamp: number;
|
|
496
|
+
close: number;
|
|
497
|
+
volume: number;
|
|
498
|
+
[key: string]: unknown;
|
|
527
499
|
}
|
|
528
|
-
interface
|
|
529
|
-
date: string;
|
|
500
|
+
interface BacktestParams {
|
|
530
501
|
symbol: string;
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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;
|
|
535
511
|
}
|
|
536
|
-
interface
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
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
|
+
}>;
|
|
542
530
|
}
|
|
543
531
|
/**
|
|
544
532
|
* Quantitative analysis module
|
|
545
533
|
*
|
|
546
534
|
* @example
|
|
547
535
|
* ```typescript
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
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'
|
|
552
545
|
* });
|
|
553
546
|
* ```
|
|
554
547
|
*/
|
|
@@ -556,88 +549,155 @@ declare class QuantModule {
|
|
|
556
549
|
private client;
|
|
557
550
|
constructor(client: Reportify);
|
|
558
551
|
/**
|
|
559
|
-
* Get
|
|
552
|
+
* Get list of available technical indicators
|
|
560
553
|
*
|
|
561
|
-
* @
|
|
562
|
-
*
|
|
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
|
+
* ```
|
|
563
564
|
*/
|
|
564
|
-
|
|
565
|
+
listIndicators(): Promise<IndicatorMeta[]>;
|
|
565
566
|
/**
|
|
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
|
+
* ```
|
|
567
586
|
*/
|
|
568
|
-
|
|
587
|
+
computeIndicators(params: IndicatorComputeParams): Promise<IndicatorData[]>;
|
|
569
588
|
/**
|
|
570
|
-
* Get
|
|
589
|
+
* Get list of available factors (variables and functions)
|
|
571
590
|
*
|
|
572
|
-
* @
|
|
573
|
-
* @returns Array of factor data
|
|
591
|
+
* @returns Array of factor definitions organized by level
|
|
574
592
|
*/
|
|
575
|
-
|
|
593
|
+
listFactors(): Promise<FactorMeta[]>;
|
|
576
594
|
/**
|
|
577
|
-
*
|
|
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
|
+
* ```
|
|
578
622
|
*/
|
|
579
|
-
|
|
623
|
+
computeFactors(params: FactorComputeParams): Promise<IndicatorData[]>;
|
|
580
624
|
/**
|
|
581
|
-
*
|
|
625
|
+
* Screen stocks based on factor formula
|
|
626
|
+
*
|
|
627
|
+
* @param params - Screening parameters
|
|
628
|
+
* @returns Array of stocks that passed the filter
|
|
582
629
|
*
|
|
583
|
-
* @
|
|
584
|
-
*
|
|
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
|
+
* ```
|
|
585
647
|
*/
|
|
586
|
-
|
|
648
|
+
screen(params: ScreenParams): Promise<ScreenedStock[]>;
|
|
587
649
|
/**
|
|
588
|
-
* Get
|
|
650
|
+
* Get OHLCV daily data for a single symbol
|
|
651
|
+
*
|
|
652
|
+
* @param params - OHLCV parameters
|
|
653
|
+
* @returns Array of OHLCV data
|
|
589
654
|
*
|
|
590
|
-
* @
|
|
591
|
-
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```typescript
|
|
657
|
+
* const data = await client.quant.ohlcv({
|
|
658
|
+
* symbol: '000001',
|
|
659
|
+
* startDate: '2024-01-01'
|
|
660
|
+
* });
|
|
661
|
+
* ```
|
|
592
662
|
*/
|
|
593
|
-
|
|
663
|
+
ohlcv(params: OHLCVParams): Promise<OHLCVData[]>;
|
|
594
664
|
/**
|
|
595
|
-
* Get
|
|
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
|
|
596
669
|
*
|
|
597
|
-
* @
|
|
598
|
-
*
|
|
670
|
+
* @example
|
|
671
|
+
* ```typescript
|
|
672
|
+
* const data = await client.quant.ohlcvBatch({
|
|
673
|
+
* symbols: ['000001', '600519'],
|
|
674
|
+
* startDate: '2024-01-01'
|
|
675
|
+
* });
|
|
676
|
+
* ```
|
|
599
677
|
*/
|
|
600
|
-
|
|
678
|
+
ohlcvBatch(params: BatchOHLCVParams): Promise<OHLCVData[]>;
|
|
601
679
|
/**
|
|
602
|
-
*
|
|
680
|
+
* Execute strategy backtest
|
|
603
681
|
*
|
|
604
682
|
* @param params - Backtest parameters
|
|
605
|
-
* @returns Backtest
|
|
683
|
+
* @returns Backtest results
|
|
606
684
|
*
|
|
607
685
|
* @example
|
|
608
686
|
* ```typescript
|
|
609
687
|
* const result = await client.quant.backtest({
|
|
610
|
-
*
|
|
611
|
-
*
|
|
612
|
-
*
|
|
613
|
-
* rebalance: 'monthly',
|
|
614
|
-
* top_n: 2
|
|
615
|
-
* },
|
|
616
|
-
* startDate: '2020-01-01',
|
|
688
|
+
* symbol: '000001',
|
|
689
|
+
* formula: 'CROSS(MA(5), MA(20))', // Golden cross buy signal
|
|
690
|
+
* startDate: '2023-01-01',
|
|
617
691
|
* endDate: '2024-01-01',
|
|
618
|
-
*
|
|
692
|
+
* initialCash: 100000
|
|
619
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)}%`);
|
|
620
698
|
* ```
|
|
621
699
|
*/
|
|
622
700
|
backtest(params: BacktestParams): Promise<BacktestResult>;
|
|
623
|
-
/**
|
|
624
|
-
* Get backtest result by ID
|
|
625
|
-
*
|
|
626
|
-
* @param backtestId - Backtest job ID
|
|
627
|
-
*/
|
|
628
|
-
backtestResult(backtestId: string): Promise<BacktestResult>;
|
|
629
|
-
/**
|
|
630
|
-
* Get backtest return series
|
|
631
|
-
*
|
|
632
|
-
* @param backtestId - Backtest job ID
|
|
633
|
-
*/
|
|
634
|
-
backtestReturns(backtestId: string): Promise<ReturnData[]>;
|
|
635
|
-
/**
|
|
636
|
-
* Get backtest trade history
|
|
637
|
-
*
|
|
638
|
-
* @param backtestId - Backtest job ID
|
|
639
|
-
*/
|
|
640
|
-
backtestTrades(backtestId: string): Promise<TradeData[]>;
|
|
641
701
|
}
|
|
642
702
|
|
|
643
703
|
/**
|
|
@@ -717,4 +777,4 @@ declare class Reportify {
|
|
|
717
777
|
searchTranscripts(query: string, options?: SearchOptions): Promise<Document[]>;
|
|
718
778
|
}
|
|
719
779
|
|
|
720
|
-
export { APIError, AuthenticationError, type
|
|
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 };
|