reportify-sdk 0.3.25 → 0.3.27
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 -85
- package/dist/index.d.ts +55 -85
- package/dist/index.js +27 -78
- package/dist/index.mjs +27 -78
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -656,33 +656,19 @@ declare class DocsModule {
|
|
|
656
656
|
/**
|
|
657
657
|
* Quant Module
|
|
658
658
|
*
|
|
659
|
-
* Provides quantitative analysis tools including
|
|
659
|
+
* Provides quantitative analysis tools including factors (technical and fundamental), quotes, and backtesting.
|
|
660
660
|
* Based on Mai-language syntax compatible with TongDaXin/TongHuaShun.
|
|
661
|
+
*
|
|
662
|
+
* All technical indicators (RSI, MACD, KDJ, etc.) are now available as factors through the unified factors API.
|
|
661
663
|
*/
|
|
662
664
|
|
|
663
665
|
type StockMarket = 'cn' | 'hk' | 'us';
|
|
664
|
-
interface IndicatorMeta {
|
|
665
|
-
name: string;
|
|
666
|
-
description: string;
|
|
667
|
-
fields: string[];
|
|
668
|
-
}
|
|
669
|
-
interface IndicatorComputeParams {
|
|
670
|
-
symbols: string[];
|
|
671
|
-
formula: string;
|
|
672
|
-
market?: StockMarket;
|
|
673
|
-
startDate?: string;
|
|
674
|
-
endDate?: string;
|
|
675
|
-
}
|
|
676
|
-
interface IndicatorData {
|
|
677
|
-
symbol: string;
|
|
678
|
-
date: string;
|
|
679
|
-
[key: string]: unknown;
|
|
680
|
-
}
|
|
681
666
|
interface FactorMeta {
|
|
682
667
|
name: string;
|
|
683
668
|
type: 'variable' | 'function';
|
|
684
669
|
level: 0 | 1 | 2;
|
|
685
670
|
description: string;
|
|
671
|
+
fields?: string[];
|
|
686
672
|
}
|
|
687
673
|
interface FactorComputeParams {
|
|
688
674
|
symbols: string[];
|
|
@@ -714,6 +700,16 @@ interface BatchOHLCVParams {
|
|
|
714
700
|
startDate?: string;
|
|
715
701
|
endDate?: string;
|
|
716
702
|
}
|
|
703
|
+
interface FactorComputeData {
|
|
704
|
+
symbol: string;
|
|
705
|
+
date: string;
|
|
706
|
+
name?: string;
|
|
707
|
+
name_en?: string;
|
|
708
|
+
close?: number;
|
|
709
|
+
factor_value?: number | boolean;
|
|
710
|
+
indicators?: Record<string, number | boolean>;
|
|
711
|
+
[key: string]: unknown;
|
|
712
|
+
}
|
|
717
713
|
interface OHLCVData {
|
|
718
714
|
symbol: string;
|
|
719
715
|
date: string;
|
|
@@ -797,10 +793,21 @@ interface BacktestResult {
|
|
|
797
793
|
/**
|
|
798
794
|
* Quantitative analysis module
|
|
799
795
|
*
|
|
796
|
+
* Access factors (including technical indicators and fundamental factors), OHLCV quotes, and backtesting functionality.
|
|
797
|
+
* Uses Mai-language syntax for formulas.
|
|
798
|
+
*
|
|
799
|
+
* Technical indicators are now part of the unified factors system:
|
|
800
|
+
* - Level 0: Basic variables (CLOSE, OPEN, HIGH, LOW, VOLUME) and core functions (MA, EMA, REF, etc.)
|
|
801
|
+
* - Level 1: Application functions (CROSS, COUNT, EVERY, etc.)
|
|
802
|
+
* - Level 2: Technical indicators (RSI, MACD, KDJ, BOLL, etc.) and fundamental factors (PE, ROE, etc.)
|
|
803
|
+
*
|
|
800
804
|
* @example
|
|
801
805
|
* ```typescript
|
|
802
|
-
* //
|
|
803
|
-
* const
|
|
806
|
+
* // List all available factors (including technical indicators)
|
|
807
|
+
* const factors = await client.quant.factors();
|
|
808
|
+
*
|
|
809
|
+
* // Compute RSI (now through factors API)
|
|
810
|
+
* const data = await client.quant.factorsCompute({
|
|
804
811
|
* symbols: ['000001'],
|
|
805
812
|
* formula: 'RSI(14)'
|
|
806
813
|
* });
|
|
@@ -815,63 +822,31 @@ declare class QuantModule {
|
|
|
815
822
|
private client;
|
|
816
823
|
constructor(client: Reportify);
|
|
817
824
|
/**
|
|
818
|
-
* Get list of available
|
|
825
|
+
* Get list of available factors (variables, functions, and indicators)
|
|
819
826
|
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
823
|
-
*
|
|
824
|
-
*
|
|
825
|
-
* ```typescript
|
|
826
|
-
* const indicators = await client.quant.indicators();
|
|
827
|
-
* indicators.forEach(ind => {
|
|
828
|
-
* console.log(`${ind.name}: ${ind.description}`);
|
|
829
|
-
* console.log(` Fields: ${ind.fields.join(', ')}`);
|
|
830
|
-
* });
|
|
831
|
-
* ```
|
|
832
|
-
*/
|
|
833
|
-
indicators(): Promise<IndicatorMeta[]>;
|
|
834
|
-
/**
|
|
835
|
-
* Compute indicator values for given symbols
|
|
827
|
+
* Returns factors organized by level:
|
|
828
|
+
* - Level 0 Variables: CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT (price data, no parentheses)
|
|
829
|
+
* - Level 0 Functions: MA(), EMA(), REF(), HHV(), LLV(), STD(), etc. (require parentheses)
|
|
830
|
+
* - Level 1 Functions: CROSS(), COUNT(), EVERY(), etc. (require parentheses)
|
|
831
|
+
* - Level 2 Functions: Technical indicators (MACD(), KDJ(), RSI(), BOLL(), etc.) and fundamental factors (PE(), ROE(), etc.)
|
|
836
832
|
*
|
|
837
833
|
* Variables vs Functions:
|
|
838
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
839
|
-
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20),
|
|
834
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
835
|
+
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
840
836
|
*
|
|
841
|
-
* @
|
|
842
|
-
* @returns Array of indicator data
|
|
837
|
+
* @returns Array of factor definitions with name, type, level, description, and optional fields
|
|
843
838
|
*
|
|
844
839
|
* @example
|
|
845
840
|
* ```typescript
|
|
846
|
-
*
|
|
847
|
-
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
850
|
-
* });
|
|
851
|
-
*
|
|
852
|
-
* // MACD indicator
|
|
853
|
-
* const data = await client.quant.indicatorsCompute({
|
|
854
|
-
* symbols: ['000001'],
|
|
855
|
-
* formula: 'MACD()'
|
|
856
|
-
* });
|
|
857
|
-
*
|
|
858
|
-
* // Standard deviation
|
|
859
|
-
* const data = await client.quant.indicatorsCompute({
|
|
860
|
-
* symbols: ['000001'],
|
|
861
|
-
* formula: 'STD(CLOSE, 20)'
|
|
841
|
+
* const factors = await client.quant.factors();
|
|
842
|
+
* factors.forEach(f => {
|
|
843
|
+
* console.log(`${f.name} (${f.type}, level ${f.level})`);
|
|
844
|
+
* if (f.fields) {
|
|
845
|
+
* console.log(` Fields: ${f.fields.join(', ')}`);
|
|
846
|
+
* }
|
|
862
847
|
* });
|
|
863
848
|
* ```
|
|
864
849
|
*/
|
|
865
|
-
indicatorsCompute(params: IndicatorComputeParams): Promise<IndicatorData[]>;
|
|
866
|
-
/**
|
|
867
|
-
* Get list of available factors (variables and functions)
|
|
868
|
-
*
|
|
869
|
-
* Variables vs Functions:
|
|
870
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, PE_TTM, ROE_TTM, etc.
|
|
871
|
-
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
872
|
-
*
|
|
873
|
-
* @returns Array of factor definitions organized by level
|
|
874
|
-
*/
|
|
875
850
|
factors(): Promise<FactorMeta[]>;
|
|
876
851
|
/**
|
|
877
852
|
* Compute factor values for given symbols
|
|
@@ -879,7 +854,7 @@ declare class QuantModule {
|
|
|
879
854
|
* Uses Mai-language syntax compatible with TongDaXin/TongHuaShun.
|
|
880
855
|
*
|
|
881
856
|
* Variables vs Functions:
|
|
882
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
857
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
883
858
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
884
859
|
*
|
|
885
860
|
* @param params - Factor computation parameters
|
|
@@ -887,37 +862,37 @@ declare class QuantModule {
|
|
|
887
862
|
*
|
|
888
863
|
* @example
|
|
889
864
|
* ```typescript
|
|
890
|
-
* //
|
|
865
|
+
* // Technical indicators (RSI, MACD, etc.)
|
|
891
866
|
* const data = await client.quant.factorsCompute({
|
|
892
867
|
* symbols: ['000001'],
|
|
893
868
|
* formula: 'RSI(14)'
|
|
894
869
|
* });
|
|
895
870
|
*
|
|
896
|
-
* // MACD
|
|
871
|
+
* // MACD indicator
|
|
897
872
|
* const data = await client.quant.factorsCompute({
|
|
898
873
|
* symbols: ['000001'],
|
|
899
874
|
* formula: 'MACD().dif'
|
|
900
875
|
* });
|
|
901
876
|
*
|
|
902
|
-
* //
|
|
877
|
+
* // Core functions
|
|
903
878
|
* const data = await client.quant.factorsCompute({
|
|
904
879
|
* symbols: ['000001'],
|
|
905
|
-
* formula: '
|
|
880
|
+
* formula: 'MA(CLOSE, 20)'
|
|
906
881
|
* });
|
|
907
882
|
*
|
|
908
|
-
* // Fundamental factors
|
|
883
|
+
* // Fundamental factors
|
|
909
884
|
* const data = await client.quant.factorsCompute({
|
|
910
885
|
* symbols: ['000001'],
|
|
911
886
|
* formula: 'PE()'
|
|
912
887
|
* });
|
|
913
888
|
* ```
|
|
914
889
|
*/
|
|
915
|
-
factorsCompute(params: FactorComputeParams): Promise<
|
|
890
|
+
factorsCompute(params: FactorComputeParams): Promise<FactorComputeData[]>;
|
|
916
891
|
/**
|
|
917
892
|
* Screen stocks based on factor formula
|
|
918
893
|
*
|
|
919
894
|
* Variables vs Functions:
|
|
920
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
895
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
921
896
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
922
897
|
*
|
|
923
898
|
* @param params - Screening parameters
|
|
@@ -925,7 +900,7 @@ declare class QuantModule {
|
|
|
925
900
|
*
|
|
926
901
|
* @example
|
|
927
902
|
* ```typescript
|
|
928
|
-
* //
|
|
903
|
+
* // Technical screening
|
|
929
904
|
* const stocks = await client.quant.factorsScreen({
|
|
930
905
|
* formula: 'RSI(14) < 30'
|
|
931
906
|
* });
|
|
@@ -935,12 +910,7 @@ declare class QuantModule {
|
|
|
935
910
|
* formula: 'CROSS(MA(CLOSE, 5), MA(CLOSE, 10))'
|
|
936
911
|
* });
|
|
937
912
|
*
|
|
938
|
-
* //
|
|
939
|
-
* const stocks = await client.quant.factorsScreen({
|
|
940
|
-
* formula: '(CLOSE > MA(CLOSE, 20)) & (MA(CLOSE, 20) > MA(CLOSE, 60))'
|
|
941
|
-
* });
|
|
942
|
-
*
|
|
943
|
-
* // Fundamental screening (note: functions require parentheses)
|
|
913
|
+
* // Fundamental screening
|
|
944
914
|
* const stocks = await client.quant.factorsScreen({
|
|
945
915
|
* formula: '(PE() < 20) & (ROE() > 0.15)'
|
|
946
916
|
* });
|
|
@@ -1049,7 +1019,7 @@ declare class QuantModule {
|
|
|
1049
1019
|
* Execute strategy backtest
|
|
1050
1020
|
*
|
|
1051
1021
|
* Variables vs Functions:
|
|
1052
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
1022
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
1053
1023
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
1054
1024
|
*
|
|
1055
1025
|
* @param params - Backtest parameters
|
|
@@ -1087,7 +1057,7 @@ declare class QuantModule {
|
|
|
1087
1057
|
* for data in datas:
|
|
1088
1058
|
* symbol = data.name
|
|
1089
1059
|
* if not context.portfolio.get_position(symbol):
|
|
1090
|
-
* if data.pe < 20 and data.rsi < 30:
|
|
1060
|
+
* if data.pe < 20 and data.rsi < 30: // Use pre-calculated factors
|
|
1091
1061
|
* context.order_target_percent(symbol, 0.2)
|
|
1092
1062
|
* elif data.rsi > 70:
|
|
1093
1063
|
* context.order_target_percent(symbol, 0)
|
|
@@ -1947,4 +1917,4 @@ declare class Reportify {
|
|
|
1947
1917
|
getBytes(path: string): Promise<ArrayBuffer>;
|
|
1948
1918
|
}
|
|
1949
1919
|
|
|
1950
|
-
export { APIError, type AgentConversation, type AgentMessage, AgentModule, AuthenticationError, type BacktestParams, type BacktestResult, type BatchKline1mParams, type BatchMinuteParams, type BatchOHLCVOutput, type BatchOHLCVParams, type Calendar, type Channel, ChannelsModule, type ChatCompletionOptions, type ChatCompletionResponse, type ChatMode, ChatModule, type Chunk, type ChunkSearchOptions, type CommodityData, type CommodityType, type CompanyInfo, type CompanyOverview, type Concept, type ConceptDoc, type ConceptEvent, type ConceptFeed, type ConceptStock, ConceptsModule, type DocsListOptions, DocsModule, type Document, type DocumentInput, type EarningsEvent, type EarningsSearchOptions, type FactorComputeParams, type FactorMeta, type FinancialStatement, type FollowedCompany, FollowingModule, type IPOEvent, type IPOStatus, type IndexConstituent, type IndexFund, type
|
|
1920
|
+
export { APIError, type AgentConversation, type AgentMessage, AgentModule, AuthenticationError, type BacktestParams, type BacktestResult, type BatchKline1mParams, type BatchMinuteParams, type BatchOHLCVOutput, type BatchOHLCVParams, type Calendar, type Channel, ChannelsModule, type ChatCompletionOptions, type ChatCompletionResponse, type ChatMode, ChatModule, type Chunk, type ChunkSearchOptions, type CommodityData, type CommodityType, type CompanyInfo, type CompanyOverview, type Concept, type ConceptDoc, type ConceptEvent, type ConceptFeed, type ConceptStock, ConceptsModule, type DocsListOptions, DocsModule, type Document, type DocumentInput, type EarningsEvent, type EarningsSearchOptions, type FactorComputeData, type FactorComputeParams, type FactorMeta, type FinancialStatement, type FollowedCompany, FollowingModule, type IPOEvent, type IPOStatus, type IndexConstituent, type IndexFund, type IndustryConstituent, KBModule, type KBSearchOptions, type Kline1mParams, MacroModule, type Market, type MinuteParams, NotFoundError, type OHLCVData, type OHLCVParams, type PaginatedResponse, type Period, type PriceData, QuantModule, type Quote, RateLimitError, Reportify, type ReportifyConfig, ReportifyError, type ScreenParams, type ScreenedStock, SearchModule, type SearchOptions, type Shareholder, type ShareholderType, type StockInfo, type StockMarket, StockModule, TimelineModule, type TimelineOptions, type UploadDocRequest, UserModule };
|
package/dist/index.d.ts
CHANGED
|
@@ -656,33 +656,19 @@ declare class DocsModule {
|
|
|
656
656
|
/**
|
|
657
657
|
* Quant Module
|
|
658
658
|
*
|
|
659
|
-
* Provides quantitative analysis tools including
|
|
659
|
+
* Provides quantitative analysis tools including factors (technical and fundamental), quotes, and backtesting.
|
|
660
660
|
* Based on Mai-language syntax compatible with TongDaXin/TongHuaShun.
|
|
661
|
+
*
|
|
662
|
+
* All technical indicators (RSI, MACD, KDJ, etc.) are now available as factors through the unified factors API.
|
|
661
663
|
*/
|
|
662
664
|
|
|
663
665
|
type StockMarket = 'cn' | 'hk' | 'us';
|
|
664
|
-
interface IndicatorMeta {
|
|
665
|
-
name: string;
|
|
666
|
-
description: string;
|
|
667
|
-
fields: string[];
|
|
668
|
-
}
|
|
669
|
-
interface IndicatorComputeParams {
|
|
670
|
-
symbols: string[];
|
|
671
|
-
formula: string;
|
|
672
|
-
market?: StockMarket;
|
|
673
|
-
startDate?: string;
|
|
674
|
-
endDate?: string;
|
|
675
|
-
}
|
|
676
|
-
interface IndicatorData {
|
|
677
|
-
symbol: string;
|
|
678
|
-
date: string;
|
|
679
|
-
[key: string]: unknown;
|
|
680
|
-
}
|
|
681
666
|
interface FactorMeta {
|
|
682
667
|
name: string;
|
|
683
668
|
type: 'variable' | 'function';
|
|
684
669
|
level: 0 | 1 | 2;
|
|
685
670
|
description: string;
|
|
671
|
+
fields?: string[];
|
|
686
672
|
}
|
|
687
673
|
interface FactorComputeParams {
|
|
688
674
|
symbols: string[];
|
|
@@ -714,6 +700,16 @@ interface BatchOHLCVParams {
|
|
|
714
700
|
startDate?: string;
|
|
715
701
|
endDate?: string;
|
|
716
702
|
}
|
|
703
|
+
interface FactorComputeData {
|
|
704
|
+
symbol: string;
|
|
705
|
+
date: string;
|
|
706
|
+
name?: string;
|
|
707
|
+
name_en?: string;
|
|
708
|
+
close?: number;
|
|
709
|
+
factor_value?: number | boolean;
|
|
710
|
+
indicators?: Record<string, number | boolean>;
|
|
711
|
+
[key: string]: unknown;
|
|
712
|
+
}
|
|
717
713
|
interface OHLCVData {
|
|
718
714
|
symbol: string;
|
|
719
715
|
date: string;
|
|
@@ -797,10 +793,21 @@ interface BacktestResult {
|
|
|
797
793
|
/**
|
|
798
794
|
* Quantitative analysis module
|
|
799
795
|
*
|
|
796
|
+
* Access factors (including technical indicators and fundamental factors), OHLCV quotes, and backtesting functionality.
|
|
797
|
+
* Uses Mai-language syntax for formulas.
|
|
798
|
+
*
|
|
799
|
+
* Technical indicators are now part of the unified factors system:
|
|
800
|
+
* - Level 0: Basic variables (CLOSE, OPEN, HIGH, LOW, VOLUME) and core functions (MA, EMA, REF, etc.)
|
|
801
|
+
* - Level 1: Application functions (CROSS, COUNT, EVERY, etc.)
|
|
802
|
+
* - Level 2: Technical indicators (RSI, MACD, KDJ, BOLL, etc.) and fundamental factors (PE, ROE, etc.)
|
|
803
|
+
*
|
|
800
804
|
* @example
|
|
801
805
|
* ```typescript
|
|
802
|
-
* //
|
|
803
|
-
* const
|
|
806
|
+
* // List all available factors (including technical indicators)
|
|
807
|
+
* const factors = await client.quant.factors();
|
|
808
|
+
*
|
|
809
|
+
* // Compute RSI (now through factors API)
|
|
810
|
+
* const data = await client.quant.factorsCompute({
|
|
804
811
|
* symbols: ['000001'],
|
|
805
812
|
* formula: 'RSI(14)'
|
|
806
813
|
* });
|
|
@@ -815,63 +822,31 @@ declare class QuantModule {
|
|
|
815
822
|
private client;
|
|
816
823
|
constructor(client: Reportify);
|
|
817
824
|
/**
|
|
818
|
-
* Get list of available
|
|
825
|
+
* Get list of available factors (variables, functions, and indicators)
|
|
819
826
|
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
823
|
-
*
|
|
824
|
-
*
|
|
825
|
-
* ```typescript
|
|
826
|
-
* const indicators = await client.quant.indicators();
|
|
827
|
-
* indicators.forEach(ind => {
|
|
828
|
-
* console.log(`${ind.name}: ${ind.description}`);
|
|
829
|
-
* console.log(` Fields: ${ind.fields.join(', ')}`);
|
|
830
|
-
* });
|
|
831
|
-
* ```
|
|
832
|
-
*/
|
|
833
|
-
indicators(): Promise<IndicatorMeta[]>;
|
|
834
|
-
/**
|
|
835
|
-
* Compute indicator values for given symbols
|
|
827
|
+
* Returns factors organized by level:
|
|
828
|
+
* - Level 0 Variables: CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT (price data, no parentheses)
|
|
829
|
+
* - Level 0 Functions: MA(), EMA(), REF(), HHV(), LLV(), STD(), etc. (require parentheses)
|
|
830
|
+
* - Level 1 Functions: CROSS(), COUNT(), EVERY(), etc. (require parentheses)
|
|
831
|
+
* - Level 2 Functions: Technical indicators (MACD(), KDJ(), RSI(), BOLL(), etc.) and fundamental factors (PE(), ROE(), etc.)
|
|
836
832
|
*
|
|
837
833
|
* Variables vs Functions:
|
|
838
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
839
|
-
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20),
|
|
834
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
835
|
+
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
840
836
|
*
|
|
841
|
-
* @
|
|
842
|
-
* @returns Array of indicator data
|
|
837
|
+
* @returns Array of factor definitions with name, type, level, description, and optional fields
|
|
843
838
|
*
|
|
844
839
|
* @example
|
|
845
840
|
* ```typescript
|
|
846
|
-
*
|
|
847
|
-
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
850
|
-
* });
|
|
851
|
-
*
|
|
852
|
-
* // MACD indicator
|
|
853
|
-
* const data = await client.quant.indicatorsCompute({
|
|
854
|
-
* symbols: ['000001'],
|
|
855
|
-
* formula: 'MACD()'
|
|
856
|
-
* });
|
|
857
|
-
*
|
|
858
|
-
* // Standard deviation
|
|
859
|
-
* const data = await client.quant.indicatorsCompute({
|
|
860
|
-
* symbols: ['000001'],
|
|
861
|
-
* formula: 'STD(CLOSE, 20)'
|
|
841
|
+
* const factors = await client.quant.factors();
|
|
842
|
+
* factors.forEach(f => {
|
|
843
|
+
* console.log(`${f.name} (${f.type}, level ${f.level})`);
|
|
844
|
+
* if (f.fields) {
|
|
845
|
+
* console.log(` Fields: ${f.fields.join(', ')}`);
|
|
846
|
+
* }
|
|
862
847
|
* });
|
|
863
848
|
* ```
|
|
864
849
|
*/
|
|
865
|
-
indicatorsCompute(params: IndicatorComputeParams): Promise<IndicatorData[]>;
|
|
866
|
-
/**
|
|
867
|
-
* Get list of available factors (variables and functions)
|
|
868
|
-
*
|
|
869
|
-
* Variables vs Functions:
|
|
870
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, PE_TTM, ROE_TTM, etc.
|
|
871
|
-
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
872
|
-
*
|
|
873
|
-
* @returns Array of factor definitions organized by level
|
|
874
|
-
*/
|
|
875
850
|
factors(): Promise<FactorMeta[]>;
|
|
876
851
|
/**
|
|
877
852
|
* Compute factor values for given symbols
|
|
@@ -879,7 +854,7 @@ declare class QuantModule {
|
|
|
879
854
|
* Uses Mai-language syntax compatible with TongDaXin/TongHuaShun.
|
|
880
855
|
*
|
|
881
856
|
* Variables vs Functions:
|
|
882
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
857
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
883
858
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
884
859
|
*
|
|
885
860
|
* @param params - Factor computation parameters
|
|
@@ -887,37 +862,37 @@ declare class QuantModule {
|
|
|
887
862
|
*
|
|
888
863
|
* @example
|
|
889
864
|
* ```typescript
|
|
890
|
-
* //
|
|
865
|
+
* // Technical indicators (RSI, MACD, etc.)
|
|
891
866
|
* const data = await client.quant.factorsCompute({
|
|
892
867
|
* symbols: ['000001'],
|
|
893
868
|
* formula: 'RSI(14)'
|
|
894
869
|
* });
|
|
895
870
|
*
|
|
896
|
-
* // MACD
|
|
871
|
+
* // MACD indicator
|
|
897
872
|
* const data = await client.quant.factorsCompute({
|
|
898
873
|
* symbols: ['000001'],
|
|
899
874
|
* formula: 'MACD().dif'
|
|
900
875
|
* });
|
|
901
876
|
*
|
|
902
|
-
* //
|
|
877
|
+
* // Core functions
|
|
903
878
|
* const data = await client.quant.factorsCompute({
|
|
904
879
|
* symbols: ['000001'],
|
|
905
|
-
* formula: '
|
|
880
|
+
* formula: 'MA(CLOSE, 20)'
|
|
906
881
|
* });
|
|
907
882
|
*
|
|
908
|
-
* // Fundamental factors
|
|
883
|
+
* // Fundamental factors
|
|
909
884
|
* const data = await client.quant.factorsCompute({
|
|
910
885
|
* symbols: ['000001'],
|
|
911
886
|
* formula: 'PE()'
|
|
912
887
|
* });
|
|
913
888
|
* ```
|
|
914
889
|
*/
|
|
915
|
-
factorsCompute(params: FactorComputeParams): Promise<
|
|
890
|
+
factorsCompute(params: FactorComputeParams): Promise<FactorComputeData[]>;
|
|
916
891
|
/**
|
|
917
892
|
* Screen stocks based on factor formula
|
|
918
893
|
*
|
|
919
894
|
* Variables vs Functions:
|
|
920
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
895
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
921
896
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
922
897
|
*
|
|
923
898
|
* @param params - Screening parameters
|
|
@@ -925,7 +900,7 @@ declare class QuantModule {
|
|
|
925
900
|
*
|
|
926
901
|
* @example
|
|
927
902
|
* ```typescript
|
|
928
|
-
* //
|
|
903
|
+
* // Technical screening
|
|
929
904
|
* const stocks = await client.quant.factorsScreen({
|
|
930
905
|
* formula: 'RSI(14) < 30'
|
|
931
906
|
* });
|
|
@@ -935,12 +910,7 @@ declare class QuantModule {
|
|
|
935
910
|
* formula: 'CROSS(MA(CLOSE, 5), MA(CLOSE, 10))'
|
|
936
911
|
* });
|
|
937
912
|
*
|
|
938
|
-
* //
|
|
939
|
-
* const stocks = await client.quant.factorsScreen({
|
|
940
|
-
* formula: '(CLOSE > MA(CLOSE, 20)) & (MA(CLOSE, 20) > MA(CLOSE, 60))'
|
|
941
|
-
* });
|
|
942
|
-
*
|
|
943
|
-
* // Fundamental screening (note: functions require parentheses)
|
|
913
|
+
* // Fundamental screening
|
|
944
914
|
* const stocks = await client.quant.factorsScreen({
|
|
945
915
|
* formula: '(PE() < 20) & (ROE() > 0.15)'
|
|
946
916
|
* });
|
|
@@ -1049,7 +1019,7 @@ declare class QuantModule {
|
|
|
1049
1019
|
* Execute strategy backtest
|
|
1050
1020
|
*
|
|
1051
1021
|
* Variables vs Functions:
|
|
1052
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
1022
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
1053
1023
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
1054
1024
|
*
|
|
1055
1025
|
* @param params - Backtest parameters
|
|
@@ -1087,7 +1057,7 @@ declare class QuantModule {
|
|
|
1087
1057
|
* for data in datas:
|
|
1088
1058
|
* symbol = data.name
|
|
1089
1059
|
* if not context.portfolio.get_position(symbol):
|
|
1090
|
-
* if data.pe < 20 and data.rsi < 30:
|
|
1060
|
+
* if data.pe < 20 and data.rsi < 30: // Use pre-calculated factors
|
|
1091
1061
|
* context.order_target_percent(symbol, 0.2)
|
|
1092
1062
|
* elif data.rsi > 70:
|
|
1093
1063
|
* context.order_target_percent(symbol, 0)
|
|
@@ -1947,4 +1917,4 @@ declare class Reportify {
|
|
|
1947
1917
|
getBytes(path: string): Promise<ArrayBuffer>;
|
|
1948
1918
|
}
|
|
1949
1919
|
|
|
1950
|
-
export { APIError, type AgentConversation, type AgentMessage, AgentModule, AuthenticationError, type BacktestParams, type BacktestResult, type BatchKline1mParams, type BatchMinuteParams, type BatchOHLCVOutput, type BatchOHLCVParams, type Calendar, type Channel, ChannelsModule, type ChatCompletionOptions, type ChatCompletionResponse, type ChatMode, ChatModule, type Chunk, type ChunkSearchOptions, type CommodityData, type CommodityType, type CompanyInfo, type CompanyOverview, type Concept, type ConceptDoc, type ConceptEvent, type ConceptFeed, type ConceptStock, ConceptsModule, type DocsListOptions, DocsModule, type Document, type DocumentInput, type EarningsEvent, type EarningsSearchOptions, type FactorComputeParams, type FactorMeta, type FinancialStatement, type FollowedCompany, FollowingModule, type IPOEvent, type IPOStatus, type IndexConstituent, type IndexFund, type
|
|
1920
|
+
export { APIError, type AgentConversation, type AgentMessage, AgentModule, AuthenticationError, type BacktestParams, type BacktestResult, type BatchKline1mParams, type BatchMinuteParams, type BatchOHLCVOutput, type BatchOHLCVParams, type Calendar, type Channel, ChannelsModule, type ChatCompletionOptions, type ChatCompletionResponse, type ChatMode, ChatModule, type Chunk, type ChunkSearchOptions, type CommodityData, type CommodityType, type CompanyInfo, type CompanyOverview, type Concept, type ConceptDoc, type ConceptEvent, type ConceptFeed, type ConceptStock, ConceptsModule, type DocsListOptions, DocsModule, type Document, type DocumentInput, type EarningsEvent, type EarningsSearchOptions, type FactorComputeData, type FactorComputeParams, type FactorMeta, type FinancialStatement, type FollowedCompany, FollowingModule, type IPOEvent, type IPOStatus, type IndexConstituent, type IndexFund, type IndustryConstituent, KBModule, type KBSearchOptions, type Kline1mParams, MacroModule, type Market, type MinuteParams, NotFoundError, type OHLCVData, type OHLCVParams, type PaginatedResponse, type Period, type PriceData, QuantModule, type Quote, RateLimitError, Reportify, type ReportifyConfig, ReportifyError, type ScreenParams, type ScreenedStock, SearchModule, type SearchOptions, type Shareholder, type ShareholderType, type StockInfo, type StockMarket, StockModule, TimelineModule, type TimelineOptions, type UploadDocRequest, UserModule };
|
package/dist/index.js
CHANGED
|
@@ -619,80 +619,34 @@ var QuantModule = class {
|
|
|
619
619
|
this.client = client;
|
|
620
620
|
}
|
|
621
621
|
// ===========================================================================
|
|
622
|
-
//
|
|
622
|
+
// Factors (includes technical indicators and fundamental factors)
|
|
623
623
|
// ===========================================================================
|
|
624
624
|
/**
|
|
625
|
-
* Get list of available
|
|
625
|
+
* Get list of available factors (variables, functions, and indicators)
|
|
626
626
|
*
|
|
627
|
-
*
|
|
628
|
-
*
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
632
|
-
* ```typescript
|
|
633
|
-
* const indicators = await client.quant.indicators();
|
|
634
|
-
* indicators.forEach(ind => {
|
|
635
|
-
* console.log(`${ind.name}: ${ind.description}`);
|
|
636
|
-
* console.log(` Fields: ${ind.fields.join(', ')}`);
|
|
637
|
-
* });
|
|
638
|
-
* ```
|
|
639
|
-
*/
|
|
640
|
-
async indicators() {
|
|
641
|
-
return this.client.get("/v1/quant/indicators");
|
|
642
|
-
}
|
|
643
|
-
/**
|
|
644
|
-
* Compute indicator values for given symbols
|
|
627
|
+
* Returns factors organized by level:
|
|
628
|
+
* - Level 0 Variables: CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT (price data, no parentheses)
|
|
629
|
+
* - Level 0 Functions: MA(), EMA(), REF(), HHV(), LLV(), STD(), etc. (require parentheses)
|
|
630
|
+
* - Level 1 Functions: CROSS(), COUNT(), EVERY(), etc. (require parentheses)
|
|
631
|
+
* - Level 2 Functions: Technical indicators (MACD(), KDJ(), RSI(), BOLL(), etc.) and fundamental factors (PE(), ROE(), etc.)
|
|
645
632
|
*
|
|
646
633
|
* Variables vs Functions:
|
|
647
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
648
|
-
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20),
|
|
634
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
635
|
+
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
649
636
|
*
|
|
650
|
-
* @
|
|
651
|
-
* @returns Array of indicator data
|
|
637
|
+
* @returns Array of factor definitions with name, type, level, description, and optional fields
|
|
652
638
|
*
|
|
653
639
|
* @example
|
|
654
640
|
* ```typescript
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
*
|
|
659
|
-
* });
|
|
660
|
-
*
|
|
661
|
-
* // MACD indicator
|
|
662
|
-
* const data = await client.quant.indicatorsCompute({
|
|
663
|
-
* symbols: ['000001'],
|
|
664
|
-
* formula: 'MACD()'
|
|
665
|
-
* });
|
|
666
|
-
*
|
|
667
|
-
* // Standard deviation
|
|
668
|
-
* const data = await client.quant.indicatorsCompute({
|
|
669
|
-
* symbols: ['000001'],
|
|
670
|
-
* formula: 'STD(CLOSE, 20)'
|
|
641
|
+
* const factors = await client.quant.factors();
|
|
642
|
+
* factors.forEach(f => {
|
|
643
|
+
* console.log(`${f.name} (${f.type}, level ${f.level})`);
|
|
644
|
+
* if (f.fields) {
|
|
645
|
+
* console.log(` Fields: ${f.fields.join(', ')}`);
|
|
646
|
+
* }
|
|
671
647
|
* });
|
|
672
648
|
* ```
|
|
673
649
|
*/
|
|
674
|
-
async indicatorsCompute(params) {
|
|
675
|
-
const response = await this.client.post("/v1/quant/indicators/compute", {
|
|
676
|
-
symbols: params.symbols,
|
|
677
|
-
formula: params.formula,
|
|
678
|
-
market: params.market || "cn",
|
|
679
|
-
start_date: params.startDate,
|
|
680
|
-
end_date: params.endDate
|
|
681
|
-
});
|
|
682
|
-
return response.datas || [];
|
|
683
|
-
}
|
|
684
|
-
// ===========================================================================
|
|
685
|
-
// Factors
|
|
686
|
-
// ===========================================================================
|
|
687
|
-
/**
|
|
688
|
-
* Get list of available factors (variables and functions)
|
|
689
|
-
*
|
|
690
|
-
* Variables vs Functions:
|
|
691
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, PE_TTM, ROE_TTM, etc.
|
|
692
|
-
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
693
|
-
*
|
|
694
|
-
* @returns Array of factor definitions organized by level
|
|
695
|
-
*/
|
|
696
650
|
async factors() {
|
|
697
651
|
return this.client.get("/v1/quant/factors");
|
|
698
652
|
}
|
|
@@ -702,7 +656,7 @@ var QuantModule = class {
|
|
|
702
656
|
* Uses Mai-language syntax compatible with TongDaXin/TongHuaShun.
|
|
703
657
|
*
|
|
704
658
|
* Variables vs Functions:
|
|
705
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
659
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
706
660
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
707
661
|
*
|
|
708
662
|
* @param params - Factor computation parameters
|
|
@@ -710,25 +664,25 @@ var QuantModule = class {
|
|
|
710
664
|
*
|
|
711
665
|
* @example
|
|
712
666
|
* ```typescript
|
|
713
|
-
* //
|
|
667
|
+
* // Technical indicators (RSI, MACD, etc.)
|
|
714
668
|
* const data = await client.quant.factorsCompute({
|
|
715
669
|
* symbols: ['000001'],
|
|
716
670
|
* formula: 'RSI(14)'
|
|
717
671
|
* });
|
|
718
672
|
*
|
|
719
|
-
* // MACD
|
|
673
|
+
* // MACD indicator
|
|
720
674
|
* const data = await client.quant.factorsCompute({
|
|
721
675
|
* symbols: ['000001'],
|
|
722
676
|
* formula: 'MACD().dif'
|
|
723
677
|
* });
|
|
724
678
|
*
|
|
725
|
-
* //
|
|
679
|
+
* // Core functions
|
|
726
680
|
* const data = await client.quant.factorsCompute({
|
|
727
681
|
* symbols: ['000001'],
|
|
728
|
-
* formula: '
|
|
682
|
+
* formula: 'MA(CLOSE, 20)'
|
|
729
683
|
* });
|
|
730
684
|
*
|
|
731
|
-
* // Fundamental factors
|
|
685
|
+
* // Fundamental factors
|
|
732
686
|
* const data = await client.quant.factorsCompute({
|
|
733
687
|
* symbols: ['000001'],
|
|
734
688
|
* formula: 'PE()'
|
|
@@ -749,7 +703,7 @@ var QuantModule = class {
|
|
|
749
703
|
* Screen stocks based on factor formula
|
|
750
704
|
*
|
|
751
705
|
* Variables vs Functions:
|
|
752
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
706
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
753
707
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
754
708
|
*
|
|
755
709
|
* @param params - Screening parameters
|
|
@@ -757,7 +711,7 @@ var QuantModule = class {
|
|
|
757
711
|
*
|
|
758
712
|
* @example
|
|
759
713
|
* ```typescript
|
|
760
|
-
* //
|
|
714
|
+
* // Technical screening
|
|
761
715
|
* const stocks = await client.quant.factorsScreen({
|
|
762
716
|
* formula: 'RSI(14) < 30'
|
|
763
717
|
* });
|
|
@@ -767,12 +721,7 @@ var QuantModule = class {
|
|
|
767
721
|
* formula: 'CROSS(MA(CLOSE, 5), MA(CLOSE, 10))'
|
|
768
722
|
* });
|
|
769
723
|
*
|
|
770
|
-
* //
|
|
771
|
-
* const stocks = await client.quant.factorsScreen({
|
|
772
|
-
* formula: '(CLOSE > MA(CLOSE, 20)) & (MA(CLOSE, 20) > MA(CLOSE, 60))'
|
|
773
|
-
* });
|
|
774
|
-
*
|
|
775
|
-
* // Fundamental screening (note: functions require parentheses)
|
|
724
|
+
* // Fundamental screening
|
|
776
725
|
* const stocks = await client.quant.factorsScreen({
|
|
777
726
|
* formula: '(PE() < 20) & (ROE() > 0.15)'
|
|
778
727
|
* });
|
|
@@ -943,7 +892,7 @@ var QuantModule = class {
|
|
|
943
892
|
* Execute strategy backtest
|
|
944
893
|
*
|
|
945
894
|
* Variables vs Functions:
|
|
946
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
895
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
947
896
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
948
897
|
*
|
|
949
898
|
* @param params - Backtest parameters
|
|
@@ -981,7 +930,7 @@ var QuantModule = class {
|
|
|
981
930
|
* for data in datas:
|
|
982
931
|
* symbol = data.name
|
|
983
932
|
* if not context.portfolio.get_position(symbol):
|
|
984
|
-
* if data.pe < 20 and data.rsi < 30:
|
|
933
|
+
* if data.pe < 20 and data.rsi < 30: // Use pre-calculated factors
|
|
985
934
|
* context.order_target_percent(symbol, 0.2)
|
|
986
935
|
* elif data.rsi > 70:
|
|
987
936
|
* context.order_target_percent(symbol, 0)
|
package/dist/index.mjs
CHANGED
|
@@ -575,80 +575,34 @@ var QuantModule = class {
|
|
|
575
575
|
this.client = client;
|
|
576
576
|
}
|
|
577
577
|
// ===========================================================================
|
|
578
|
-
//
|
|
578
|
+
// Factors (includes technical indicators and fundamental factors)
|
|
579
579
|
// ===========================================================================
|
|
580
580
|
/**
|
|
581
|
-
* Get list of available
|
|
581
|
+
* Get list of available factors (variables, functions, and indicators)
|
|
582
582
|
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
* ```typescript
|
|
589
|
-
* const indicators = await client.quant.indicators();
|
|
590
|
-
* indicators.forEach(ind => {
|
|
591
|
-
* console.log(`${ind.name}: ${ind.description}`);
|
|
592
|
-
* console.log(` Fields: ${ind.fields.join(', ')}`);
|
|
593
|
-
* });
|
|
594
|
-
* ```
|
|
595
|
-
*/
|
|
596
|
-
async indicators() {
|
|
597
|
-
return this.client.get("/v1/quant/indicators");
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* Compute indicator values for given symbols
|
|
583
|
+
* Returns factors organized by level:
|
|
584
|
+
* - Level 0 Variables: CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT (price data, no parentheses)
|
|
585
|
+
* - Level 0 Functions: MA(), EMA(), REF(), HHV(), LLV(), STD(), etc. (require parentheses)
|
|
586
|
+
* - Level 1 Functions: CROSS(), COUNT(), EVERY(), etc. (require parentheses)
|
|
587
|
+
* - Level 2 Functions: Technical indicators (MACD(), KDJ(), RSI(), BOLL(), etc.) and fundamental factors (PE(), ROE(), etc.)
|
|
601
588
|
*
|
|
602
589
|
* Variables vs Functions:
|
|
603
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
604
|
-
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20),
|
|
590
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
591
|
+
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
605
592
|
*
|
|
606
|
-
* @
|
|
607
|
-
* @returns Array of indicator data
|
|
593
|
+
* @returns Array of factor definitions with name, type, level, description, and optional fields
|
|
608
594
|
*
|
|
609
595
|
* @example
|
|
610
596
|
* ```typescript
|
|
611
|
-
*
|
|
612
|
-
*
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
* });
|
|
616
|
-
*
|
|
617
|
-
* // MACD indicator
|
|
618
|
-
* const data = await client.quant.indicatorsCompute({
|
|
619
|
-
* symbols: ['000001'],
|
|
620
|
-
* formula: 'MACD()'
|
|
621
|
-
* });
|
|
622
|
-
*
|
|
623
|
-
* // Standard deviation
|
|
624
|
-
* const data = await client.quant.indicatorsCompute({
|
|
625
|
-
* symbols: ['000001'],
|
|
626
|
-
* formula: 'STD(CLOSE, 20)'
|
|
597
|
+
* const factors = await client.quant.factors();
|
|
598
|
+
* factors.forEach(f => {
|
|
599
|
+
* console.log(`${f.name} (${f.type}, level ${f.level})`);
|
|
600
|
+
* if (f.fields) {
|
|
601
|
+
* console.log(` Fields: ${f.fields.join(', ')}`);
|
|
602
|
+
* }
|
|
627
603
|
* });
|
|
628
604
|
* ```
|
|
629
605
|
*/
|
|
630
|
-
async indicatorsCompute(params) {
|
|
631
|
-
const response = await this.client.post("/v1/quant/indicators/compute", {
|
|
632
|
-
symbols: params.symbols,
|
|
633
|
-
formula: params.formula,
|
|
634
|
-
market: params.market || "cn",
|
|
635
|
-
start_date: params.startDate,
|
|
636
|
-
end_date: params.endDate
|
|
637
|
-
});
|
|
638
|
-
return response.datas || [];
|
|
639
|
-
}
|
|
640
|
-
// ===========================================================================
|
|
641
|
-
// Factors
|
|
642
|
-
// ===========================================================================
|
|
643
|
-
/**
|
|
644
|
-
* Get list of available factors (variables and functions)
|
|
645
|
-
*
|
|
646
|
-
* Variables vs Functions:
|
|
647
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, PE_TTM, ROE_TTM, etc.
|
|
648
|
-
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
649
|
-
*
|
|
650
|
-
* @returns Array of factor definitions organized by level
|
|
651
|
-
*/
|
|
652
606
|
async factors() {
|
|
653
607
|
return this.client.get("/v1/quant/factors");
|
|
654
608
|
}
|
|
@@ -658,7 +612,7 @@ var QuantModule = class {
|
|
|
658
612
|
* Uses Mai-language syntax compatible with TongDaXin/TongHuaShun.
|
|
659
613
|
*
|
|
660
614
|
* Variables vs Functions:
|
|
661
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
615
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
662
616
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
663
617
|
*
|
|
664
618
|
* @param params - Factor computation parameters
|
|
@@ -666,25 +620,25 @@ var QuantModule = class {
|
|
|
666
620
|
*
|
|
667
621
|
* @example
|
|
668
622
|
* ```typescript
|
|
669
|
-
* //
|
|
623
|
+
* // Technical indicators (RSI, MACD, etc.)
|
|
670
624
|
* const data = await client.quant.factorsCompute({
|
|
671
625
|
* symbols: ['000001'],
|
|
672
626
|
* formula: 'RSI(14)'
|
|
673
627
|
* });
|
|
674
628
|
*
|
|
675
|
-
* // MACD
|
|
629
|
+
* // MACD indicator
|
|
676
630
|
* const data = await client.quant.factorsCompute({
|
|
677
631
|
* symbols: ['000001'],
|
|
678
632
|
* formula: 'MACD().dif'
|
|
679
633
|
* });
|
|
680
634
|
*
|
|
681
|
-
* //
|
|
635
|
+
* // Core functions
|
|
682
636
|
* const data = await client.quant.factorsCompute({
|
|
683
637
|
* symbols: ['000001'],
|
|
684
|
-
* formula: '
|
|
638
|
+
* formula: 'MA(CLOSE, 20)'
|
|
685
639
|
* });
|
|
686
640
|
*
|
|
687
|
-
* // Fundamental factors
|
|
641
|
+
* // Fundamental factors
|
|
688
642
|
* const data = await client.quant.factorsCompute({
|
|
689
643
|
* symbols: ['000001'],
|
|
690
644
|
* formula: 'PE()'
|
|
@@ -705,7 +659,7 @@ var QuantModule = class {
|
|
|
705
659
|
* Screen stocks based on factor formula
|
|
706
660
|
*
|
|
707
661
|
* Variables vs Functions:
|
|
708
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
662
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
709
663
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
710
664
|
*
|
|
711
665
|
* @param params - Screening parameters
|
|
@@ -713,7 +667,7 @@ var QuantModule = class {
|
|
|
713
667
|
*
|
|
714
668
|
* @example
|
|
715
669
|
* ```typescript
|
|
716
|
-
* //
|
|
670
|
+
* // Technical screening
|
|
717
671
|
* const stocks = await client.quant.factorsScreen({
|
|
718
672
|
* formula: 'RSI(14) < 30'
|
|
719
673
|
* });
|
|
@@ -723,12 +677,7 @@ var QuantModule = class {
|
|
|
723
677
|
* formula: 'CROSS(MA(CLOSE, 5), MA(CLOSE, 10))'
|
|
724
678
|
* });
|
|
725
679
|
*
|
|
726
|
-
* //
|
|
727
|
-
* const stocks = await client.quant.factorsScreen({
|
|
728
|
-
* formula: '(CLOSE > MA(CLOSE, 20)) & (MA(CLOSE, 20) > MA(CLOSE, 60))'
|
|
729
|
-
* });
|
|
730
|
-
*
|
|
731
|
-
* // Fundamental screening (note: functions require parentheses)
|
|
680
|
+
* // Fundamental screening
|
|
732
681
|
* const stocks = await client.quant.factorsScreen({
|
|
733
682
|
* formula: '(PE() < 20) & (ROE() > 0.15)'
|
|
734
683
|
* });
|
|
@@ -899,7 +848,7 @@ var QuantModule = class {
|
|
|
899
848
|
* Execute strategy backtest
|
|
900
849
|
*
|
|
901
850
|
* Variables vs Functions:
|
|
902
|
-
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME
|
|
851
|
+
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
903
852
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
904
853
|
*
|
|
905
854
|
* @param params - Backtest parameters
|
|
@@ -937,7 +886,7 @@ var QuantModule = class {
|
|
|
937
886
|
* for data in datas:
|
|
938
887
|
* symbol = data.name
|
|
939
888
|
* if not context.portfolio.get_position(symbol):
|
|
940
|
-
* if data.pe < 20 and data.rsi < 30:
|
|
889
|
+
* if data.pe < 20 and data.rsi < 30: // Use pre-calculated factors
|
|
941
890
|
* context.order_target_percent(symbol, 0.2)
|
|
942
891
|
* elif data.rsi > 70:
|
|
943
892
|
* context.order_target_percent(symbol, 0)
|