Quantization strategy generation method, apparatus, device, and medium
Patent Information
- Application Number
- CN202611137849.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-29
- Publication Date
- 2026-10-30
AI Technical Summary
但是,目前量化策略生成方案存在不支持可视化的低代码操作,纯代码展示导致理解成本高、上手门槛高;部分方案支持可视化操作,但生成的功能基本不可运行或运行存在问题;大部分应用基于纯Prompt方式直接生成策略代码,耗时长等问题
[0008]第五方面,本申请实施例提供了一种计算机程序产品,包括计算机程序,其特征在于,该计算机程序被处理器执行时实现如本申请实施例描述的方法。
Smart Images

Figure CN123011211A_ABST
Abstract
Description
Technical Field
[0001] This disclosure generally relates to the field of natural language processing technology, and specifically to a method, apparatus, device, and medium for generating quantization strategies. Background Technology
[0002] With the widespread application of artificial intelligence technology in the financial field, the automated generation of quantitative trading strategies has become an important research direction. Users describe their trading ideas in natural language, and the system automatically generates corresponding strategy code using large models. However, current quantitative strategy generation solutions suffer from several drawbacks, including a lack of support for low-code visualization, resulting in high comprehension costs and a high learning curve for pure code display; some solutions support visualization, but the generated functions are often unusable or have operational issues; and most applications generate strategy code directly using a pure prompt method, which is time-consuming. Therefore, how to better achieve quantitative strategy generation has become an urgent problem to be solved. Summary of the Invention
[0003] In view of the above-mentioned defects or deficiencies in the prior art, it is desirable to provide a method, apparatus, device and medium for generating quantization strategies, which effectively realizes the automatic conversion from natural language description to a visual quantization strategy canvas, thereby improving the efficiency and accuracy of quantization strategy development.
[0004] In a first aspect, embodiments of this application provide a method for generating a quantization strategy, including: Obtain the quantization strategy description input by the user in natural language; According to the quantization strategy description, a target quantization function is determined from a pre-set quantization function library, and the target quantization function is instantiated with parameters to generate a function instance object; Based on the function instance object and the preset graph node function set, executable strategy code is generated. The strategy code is the program code of the logical flow described by the strategy flowchart corresponding to the quantization strategy description. The strategy code is converted into a class abstract syntax tree representation at runtime, and the canvas protocol data of the strategy flowchart is generated based on the class abstract syntax tree representation. A visual quantization strategy canvas is generated based on the canvas protocol data rendering.
[0005] Secondly, embodiments of this application provide a quantization strategy generation apparatus, comprising: The acquisition module is used to acquire the quantization strategy description input by the user in natural language; The filtering module is used to determine the target quantization function from the preset quantization function library according to the quantization strategy description, and to instantiate the parameters of the target quantization function to generate a function instance object; The first generation module is used to generate executable strategy code based on the function instance object and the preset graph node function set. The strategy code is the program code of the logical flow described by the strategy flowchart corresponding to the quantization strategy description. The second generation module is used to convert the strategy code into a class abstract syntax tree representation at runtime, and generate the canvas protocol data of the strategy flowchart based on the class abstract syntax tree representation. The third generation module is used to render and generate a visualization quantization strategy canvas based on the canvas protocol data.
[0006] Thirdly, embodiments of this application provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in embodiments of this application.
[0007] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in embodiments of this application.
[0008] Fifthly, embodiments of this application provide a computer program product, including a computer program, characterized in that, when the computer program is executed by a processor, it implements the method described in embodiments of this application.
[0009] The quantization strategy generation method provided in this application embodiment obtains a quantization strategy description input by the user in natural language; based on the quantization strategy description, a target quantization function is determined from a preset quantization function library, and the target quantization function is instantiated with parameters to generate a function instance object; based on the function instance object and a preset set of graph node functions, executable strategy code is generated, whereby the strategy code is the program code describing the logical flow of the strategy flowchart corresponding to the quantization strategy description; the strategy code is converted into a class abstract syntax tree representation at runtime, and canvas protocol data for the strategy flowchart is generated based on the class abstract syntax tree representation; and a visual quantization strategy canvas is generated by rendering based on the canvas protocol data. This process involves acquiring a quantization strategy description from the user's natural language input, then sequentially using metadata-driven function instantiation to determine the target quantization function and generate a function instance object. Based on this function instance object and the graph node function set, executable strategy code is generated. At runtime, this strategy code is converted into a class abstract syntax tree representation, generating canvas protocol data for the strategy flowchart. Finally, a visual quantization strategy canvas is rendered based on the canvas protocol data. This effectively and efficiently transforms quantization strategies expressed in natural language into a runnable and draggable editable visual canvas, significantly reducing the development threshold for quantization strategies and improving generation efficiency and accuracy.
[0010] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description
[0011] Other features, objects, and advantages of this application will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings: Figure 1A This illustration shows an application scenario diagram of the quantization strategy canvas provided in an embodiment of this application; Figure 1B The implementation environment architecture diagram of the quantization strategy generation method provided in the embodiments of this application is shown; Figure 2 A flowchart illustrating a quantization strategy generation method provided in an embodiment of this application is shown; Figure 3 This illustration shows a schematic diagram of the disassembly structure of a quantization strategy canvas provided in an embodiment of this application; Figure 4 A schematic diagram of the structure of a quantization strategy generation device provided in an embodiment of this application is shown; Figure 5 A schematic diagram of the structure of a computer system suitable for implementing an electronic device or server according to embodiments of this application is shown. Detailed Implementation
[0012] The present application will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings.
[0013] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0014] Quantitative trading refers to the process of using computer technology to complete trades based on pre-defined quantitative strategies. Quantitative trading greatly reduces the impact of investor sentiment fluctuations and avoids making irrational investment decisions in situations of extreme market euphoria or pessimism.
[0015] Quantitative trading strategies, or quantitative strategies in general, specifically include the driving object, pre-defined trading conditions, and the trading operations triggered when the trading conditions are met. The trading conditions include, but are not limited to, the requirement that the market data and / or related technical indicators of the driving object meet specific conditions. Trading operations include, but are not limited to, order placement and order cancellation. For example, taking a moving average golden cross entry strategy as an example, when the K-line data of the driving object specified in the quantitative strategy crosses above its moving average over a certain long period (i.e., the quantitative condition is met), a buy order for the driving object is executed.
[0016] For example, the strategy logic of a quantitative trading strategy can be: when the technical indicator of the driving object specified in the quantitative trading strategy meets the preset condition, an order is placed on the specified object. Taking the moving average golden cross opening strategy as an example, when the moving average of the driving object specified in the quantitative trading strategy meets the golden cross within a certain period, a buy order is placed on the driving object, thereby helping investors better seize trading opportunities, achieve more accurate and efficient trading operations, and improve trading efficiency and speed.
[0017] Investors can define the strategy logic of preset quantitative trading strategies based on the visual interactive interface provided by the client-side. Specifically, investors can directly specify preset trading conditions and the trading operations to be executed after these conditions are met. The visual interactive interface can include a quantitative strategy canvas, which provides card controls, including start card controls, condition card controls, and action card controls. Users can edit and connect these card controls in a specific order to form a strategy flowchart. See, for example... Figure 1A Users can edit the condition card control to set the trading conditions of the quantitative trading strategy, edit the action card control to set the trading operations of the quantitative trading strategy, and connect the start card control, condition card control and action card control in sequence to generate a strategy flowchart.
[0018] Understandably, the card control encapsulates code functions that implement its functional logic. When the user triggers the execution of the quantitative trading strategy canvas, the code functions corresponding to the card controls can be executed sequentially according to the logical order of the card controls in the strategy flowchart, so as to realize the trading operation according to the strategy logic of the corresponding quantitative trading strategy.
[0019] During the execution of the quantitative trading strategy, the client obtains the market data of the trading object specified by the start card control in real time, and determines whether the market data of the trading object meets the preset trading conditions specified by the condition card control. When the preset trading conditions specified by the condition card control are met, the client can automatically execute the trading operation indicated by the action card control to send the corresponding trading request to the corresponding trading request interface of the server to realize the transaction.
[0020] However, when quantitative strategies involve numerous trading conditions, and the trading operations triggered by the fulfillment of different trading conditions vary, the difficulty of creating quantitative strategies on the quantitative strategy canvas increases significantly.
[0021] For the specific implementation environment of the quantitative strategy generation method proposed in this application, please refer to [link / reference needed]. Figure 1B . Figure 1B The implementation environment architecture diagram of the quantization strategy generation method provided in the embodiments of this application is shown.
[0022] like Figure 1B As shown, the implementation environment architecture includes: terminal device 101, server 102 and multiple quantization strategy execution servers 103.
[0023] Terminal device 101 is used to run an application client and provide an interactive interface to the user. This interface receives a quantitative strategy description input by the user in natural language, displays AI-guided question-and-answer information, and presents a generated visual quantitative strategy canvas. Terminal device 101 can be a desktop computer, laptop computer, smartphone, tablet computer, e-book reader, smart glasses, smartwatch, in-vehicle device, ultra-mobile personal computer (UMPC), netbook, cellular phone, personal digital assistant (PDA), augmented reality (AR), virtual reality (VR) device, etc., but is not limited to these.
[0024] Server 102 is connected to terminal device 101 and multiple quantitative strategy execution servers 103. Server 102 executes the quantitative strategy generation method proposed in the application embodiment. It performs intent recognition, function filtering, code generation, AST-like transformation, and canvas protocol data generation based on the quantitative strategy description input by the user on terminal device 101, and finally returns visualized quantitative strategy canvas data to terminal device 101. The multiple quantitative strategy execution servers 103 execute user-generated quantitative strategies, including tasks such as strategy backtesting, simulated trading, and live trading, and provide server 102 with strategy execution results and required market data, indicator data, etc.
[0025] Server 102 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. Server 102 is used to provide quantization strategy generation services to terminal device 101 and execute core processing logic such as intent recognition, function filtering, large model code generation, runtime instrumentation, and AST-like transformation of user-input quantization strategy descriptions.
[0026] Server 102 is directly or indirectly connected to terminal device 101 and multiple quantization strategy execution servers 103 via wired or wireless communication. Optionally, the aforementioned wireless or wired network uses standard communication technologies and / or protocols. The network is typically the Internet, but can also be any network, including but not limited to any combination of Local Area Network (LAN), Metropolitan Area Network (MAN), Wide Area Network (WAN), mobile, wired or wireless network, private network, or virtual private network.
[0027] The quantization strategy generation method proposed in this application can be implemented by a quantization strategy generation device, which can be installed on a terminal device or a server.
[0028] To further illustrate the technical solutions provided in the embodiments of this application, a detailed description is provided below in conjunction with the accompanying drawings and specific implementation methods. Although the embodiments of this application provide method operation instruction steps as shown in the following embodiments or drawings, the method may include more or fewer operation instruction steps based on conventional or non-creative effort. In steps where there is no logically necessary causal relationship, the execution order of these steps is not limited to the execution order provided in the embodiments of this application. In actual processing or when the device executes the method, it may be executed sequentially or in parallel according to the method shown in the embodiments or drawings.
[0029] It should be noted that the acquisition or use of data in the embodiments of this application requires the user's consent. The relevant data can only be obtained after the user's authorization and permission, and the acquisition or use of the data complies with the laws and regulations of the relevant regions.
[0030] Please refer to Figure 2 , Figure 2 A flowchart illustrating a quantization strategy generation method according to an embodiment of this application is shown. Figure 2 As shown, the method includes: Step 201: Obtain the quantization strategy description input by the user in natural language.
[0031] Among them, the front-end interface can receive quantitative strategy descriptions input by users in natural language, such as: "If the MACD of stock A's daily K is a golden cross, then buy 100 shares at the market price; if a stock's MACD is a death cross, then liquidate the position."
[0032] Specifically, the user's natural language input can be obtained. The natural language input can be classified into intents to determine whether the user's natural language input is a quantization strategy description of a clear quantization intent category. When it is determined that the natural language input is a quantization strategy description of a clear quantization intent category, subsequent steps S202 to S205 can be executed to convert the natural language input into a visual quantization strategy canvas.
[0033] Optionally, intent classification also includes non-quantitative intent categories and fuzzy quantitative intent categories. If the user's natural language input is other inputs of the non-quantitative intent category, it can trigger a transition to the normal AI question-and-answer process. If the user's natural language input is a quantitative strategy description of the fuzzy quantitative intent category, it can trigger an AI question-and-answer process to guide the user to supplement the missing strategy elements until a quantitative strategy description of the clear quantitative intent category is obtained.
[0034] Specifically, a lightweight classifier can be used to classify the natural language input entered by the user through regular expression matching (such as regular expression matching keywords such as "quantitative", "trading", and "strategy") or by using the BERT model. If the classification result output by the BERT model indicates that the probability of the natural language input being related to quantitative strategy is lower than a preset threshold, then the natural language input entered by the user is marked as other inputs that are not related to quantitative intent. If the classification result output by the BERT model indicates that the probability of the natural language input being related to quantitative strategy is greater than or equal to the preset threshold, then the natural language input entered by the user is marked as natural language input related to quantitative strategy.
[0035] Furthermore, when the user's natural language input is related to a quantitative strategy (i.e., a quantitative strategy description), intent recognition can be performed on the quantitative strategy description. By determining whether the quantitative strategy description fully includes key elements such as the target, conditions, and actions, and whether the logical relationships between these key elements are clear, the intent corresponding to the quantitative strategy description can be determined. For example, through slot extraction technology, the set of elements for constructing a quantitative strategy can be identified and extracted: the target (i.e., the trading object), conditions (i.e., trading conditions, used to indicate under what circumstances it is triggered), and actions (i.e., trading actions, used to indicate what operation to perform). Based on the total extracted elements, it can be analyzed whether the quantitative strategy description fully includes these three key slots.
[0036] Among them, the quantitative strategy description of the clear quantitative intent category fully includes the three key elements of target, condition, and action, and the logical relationship between the elements is clear; the quantitative strategy description of the fuzzy quantitative intent category partially includes or does not include the key elements required for the quantitative strategy, or the key elements of the input are complete but the logical expression is unclear.
[0037] For example, when a quantitative strategy description is determined to fall under an ambiguous quantitative intent category, a guided question-and-answer process can be initiated. This process includes: targeted follow-up questions, intent confirmation and solution provision, and multi-round dialogue management. Specifically, for targeted follow-up questions, based on the missing slots, specific follow-up questions are generated; for example, when a user lacks a target stock, the system might ask, "Which stock do you want to create a strategy for?". For intent confirmation and solution provision, when intent is ambiguous, possible intent directions are listed for the user to choose from, or several typical strategy templates are provided for selection. For multi-round dialogue management, key information extracted and still missing in each round of dialogue is recorded and tracked until all elements are gathered to form a complete and clear strategy description. This guided mechanism improves the user experience, enabling non-professional users to gradually complete strategy descriptions with system assistance, thus lowering the barrier to entry for quantitative trading.
[0038] Step 202: Based on the quantization strategy description, determine the target quantization function from the preset quantization function library, and instantiate the parameters of the target quantization function to generate a function instance object.
[0039] As shown in the quantization strategy canvas above, the quantization strategy is presented in the form of a strategy flowchart. Its storage and organization within the computer employ a graph data structure, recording the logical topological relationships of the quantization strategy in a "node-connection" manner. However, this graph data structure focuses on low-level encoding of connections, and its control flow semantics (such as sequential execution and conditional branching) are implicitly distributed within the topological relationships of nodes and edges, resulting in low semantic density. When a quantization strategy description input by a user in natural language is obtained and converted into a corresponding graph data structure of the strategy flowchart, large language models often need to simultaneously perform natural language semantic understanding and graph topology generation, making it difficult to guarantee the accuracy and robustness of the generated results, especially when dealing with quantization strategies containing complex branching logic.
[0040] To output a policy flowchart on a quantization policy canvas based on natural language input quantization policy descriptions, the large, heterogeneous quantization policy canvas can be pre-abstracted into atomic, structured metadata, forming a component library that can be directly referenced by large language models and programs. When a user inputs a quantization policy description, the large language model does not need to directly generate complex business code or a graph topology. Instead, it quickly and accurately determines the target quantization function corresponding to the user's intent by retrieving and matching these high semantic density metadata definitions corresponding to preset functions. Then, based on the target quantization function, it generates the corresponding quantization policy code. This policy code inherits the semantics of the quantization policy description input from natural language and is backward compatible with the generation of policy flowcharts in existing quantization policy canvases.
[0041] Specifically, during system initialization, the following metadata-driven preparations need to be completed: As mentioned above, refer to Figure 3 The quantization strategy canvas can be broken down into card controls and the connections between them. Each card control can be further broken down into at least one quantization function, through which the functional logic corresponding to the card control can be defined. For example, a condition card control may include an lvalue function, a comparison operator, and an rvalue function to define the conditional judgments involved in the quantization strategy; an action card control may include an rvalue function to define the strategy action in the quantization strategy; and a start card control may include a function for creating global variables. Quantization functions can be constructed based on function code and parameters. Therefore, a library of quantization functions and a set of graph node functions can be pre-built to generate the quantization strategy canvas.
[0042] The quantitative function library includes multiple quantitative functions and their corresponding metadata definitions. For example, quantitative functions may include the order placement function func_order for performing order placement operations, the magic nine-turn function func_nine for determining whether K-line data conforms to the magic nine-turn structure, the position query function func_posiqty for querying the current user's position quantity for the driving object, and so on. These will not be listed one by one here. The graph node function set includes card node functions for constructing card nodes such as condition card controls, action card controls, and start card controls, as well as connection functions for connecting different card nodes. In addition, the graph node function set may also include canvas construction functions, which are used to aggregate all generated card nodes and the connections between card nodes to form a strategy flowchart.
[0043] Understandably, the card node function is used to implement the logical functions of the card controls in the quantization strategy canvas, and the connection function is used to define the execution flow and branch logic of the card controls corresponding to the card node function.
[0044] Specifically, the quantization function library includes metadata definitions for all quantization functions, and each quantization function's metadata definition can be stored in a structured format (JSON / YAML). The metadata definition of a quantization function includes at least the function name, function description, parameter list and parameter information for each parameter, and a function usage example. Parameter information includes, but is not limited to, parameter name, parameter type, default value, parameter value range, whether a parameter is required, and parameter enumeration values.
[0045] The graph node function set includes the metadata definitions of the card node functions and connection functions corresponding to all card controls (condition card controls, action card controls, and start card controls). The metadata definitions of card node functions include the card node function name, card node description, and the function combinations contained therein. The metadata definitions of connection functions include the connection function name, connection description, and condition judgment logic.
[0046] Taking conditional card node functions as an example, the metadata definition of a conditional card node function may include the card node function name, card node function description, lvalue function information, rvalue function information, comparison operator information, and card node usage examples; Taking the connection function as an example, the metadata definition of the connection function may include the connection function name, connection function description, starting card node information, ending card node information, connection type, and connection function usage examples.
[0047] In addition, function libraries can be preloaded. Specifically, the quantization functions in the quantization function library, as well as the Python functions (such as the implementation code of func_order) corresponding to the card node functions and connection functions in the graph node function set, are registered in memory to establish a mapping between function names and function code objects so that they can be called during subsequent instantiation.
[0048] In one embodiment, determining the target quantization function from a pre-set quantization function library includes: performing semantic analysis on the quantization strategy description using a large language model to obtain the strategy logic flow corresponding to the quantization strategy description; using the metadata definitions of all quantization functions in the quantization function library as context, and calling the large language model to determine one or more target quantization functions involved in each of the strategy logic flows from the quantization function library.
[0049] After obtaining the quantization strategy description, semantic analysis can be performed on the quantization strategy description using a large model (such as an LLM model) to obtain the strategy logic flow corresponding to the quantization strategy description. Based on the strategy logic flow, the large model is called to select the most matching quantization function (i.e., the target quantization function) from the pre-built quantization function library, without the large model directly generating any code corresponding to the quantization strategy. This effectively improves the accuracy of converting the quantization strategy description input from natural language into a strategy flowchart on the quantization strategy canvas.
[0050] Specifically, the system uses the function names, descriptions, parameter lists, and usage examples of all quantization functions in the quantization function library as context (system prompt), and the user-inputted quantization strategy description as input. Based on preset prompt words, the system calls a large model to obtain the strategy logic flow corresponding to the quantization strategy description, and determines one or more of the most relevant target quantization functions involved in each strategy logic flow from the preset quantization function library. For any target quantization function, a corresponding function instance object to be executed can be generated based on the semantic information of the strategy logic flow and the metadata definition of the target quantization function.
[0051] It is understandable that a function instance object is a computational unit to be executed, used to implement a specific data processing logic under the quantization strategy.
[0052] For example, the quantitative strategy description entered by the user is: "Create a Magic Nine-Turn Strategy for Stock A, buy one lot when a downward nine-turn pattern appears, and sell the position when an upward nine-turn pattern appears." Through semantic analysis of the quantitative strategy description using a large model, the strategy logic flow can be obtained as follows: S1: Create the driving object stock A; S2: Create a holdings assessment card; S3: Implement the sell branch: If you have a position, sell your position when the nine-upward structure appears; S4: Buy branch: No position, buy one lot when a downward nine structure appears.
[0053] Once the strategy logic flow is determined, for any given strategy logic flow, the quantization functions involved in that flow can be determined from a pre-built quantization function library based on the semantic information of the strategy logic flow. Simultaneously, for any determined target quantization function, a corresponding function instance object to be executed can be generated based on the semantic information of the strategy logic flow and the target quantization function. Taking the above strategy logic flow example, the quantitative functions involved in the above quantitative strategy description include at least: the order placement function func_order, the magic nine-turn function func_nine, and the position query function func_posiqty.
[0054] In one embodiment, given a target quantization function, instantiating the target quantization function to generate a function instance object includes the following steps: Step 2021: Obtain the metadata definition of the target quantization function. The metadata definition shall include at least the function name, parameter list and parameter information.
[0055] Step 2022: Extract the parameter values corresponding to the parameter list from the quantization strategy description.
[0056] Specifically, a large model can perform semantic analysis on the quantization strategy description based on preset prompts to obtain the strategy logic flow corresponding to the quantization strategy description. Based on the semantic information of the strategy logic flow, the target quantization function required by the strategy logic flow and the parameter values required by the target quantization function can be determined from a preset quantization function library.
[0057] Taking the strategy logic flow "implementing the buy branch" as an example, the target quantitative functions corresponding to this strategy logic flow include: the order placement function func_order and the magic nine-turn function func_nine; For the order placement function func_order, the parameter list of func_order includes the driver object code, the order direction trd_side, the order quantity qty, and the order quantity unit qty_type. At this time, the parameter descriptions corresponding to each parameter are obtained from the quantitative strategy description and mapped to the parameter values. For example, if the parameter description of the driver object is stock A, it can be mapped to the stock identifier of stock A. If the parameter description of the order direction is "buy", it can be mapped to "BUY". If the parameter description of the order quantity and the order quantity unit is "1 lot", the order quantity can be mapped to "1" and the order quantity unit can be mapped to "LOT".
[0058] Taking the Magic Nine Turns function func_nine as an example, the parameter list of the Magic Nine Turns function func_nine includes the driving object code and the market data unit k_type. At this time, the parameter descriptions corresponding to each parameter are obtained from the quantitative strategy description and mapped to the parameter values. For example, if the parameter description of the driving object is stock A, it can be mapped to the stock identifier of stock A. The parameter description of the market data unit is empty. At this time, the default value "K_DAY" can be obtained from the parameter information of the market data unit k_type and filled in.
[0059] Taking the strategy logic flow "creating a position judgment card" as an example, the target quantitative function corresponding to this strategy logic flow includes: the position query function func_posiqty; the parameter list of the position query function func_posiqty includes the driver object code. At this time, the parameter descriptions corresponding to each parameter are obtained from the quantitative strategy description and mapped to the parameter values. For example, if the parameter description of the driver object is stock A, it can be mapped to the stock identifier of stock A.
[0060] Step 2023: Perform type validation on the extracted parameter values according to the parameter type.
[0061] As mentioned above, the parameter information in the metadata definition of the quantization function includes parameter name, parameter type, parameter default value, parameter value range, and parameter mandatory field. The system can verify the extracted parameter values based on the parameter default value, parameter value range, and parameter mandatory field of each parameter in the metadata definition of the quantization function.
[0062] For example, taking the order placement function func_order under the above strategy logic flow "implementing the buy branch" as an example, it can verify whether the parameter value qty "1" of the order quantity is an integer type, and verify whether the parameter value "BUY" of the order direction is within the enumeration values ("BUY" / "SELL") in its metadata definition.
[0063] If the user does not provide the required parameters for the target quantization function (such as code for func_order), the user can be guided to supplement them through a question-and-answer format, or the default values of the parameter information in the metadata definition can be used.
[0064] Step 2024: Encapsulate the validated parameter values into a parameter value object.
[0065] For example, the system encapsulates the validated parameter values into a parameter value object.
[0066] Continuing with the example of the order placement function `func_order` under the "implementing the buy branch" strategy logic flow described above, the parameter value object of the order placement function `func_order` can be represented as follows: {"code":"symbolA","trd_side":"BUY","qty":1,"qty_type":"LOT"}.
[0067] Step 2025: Call the target quantization function and take the parameter value object as input to generate an executable function instance object.
[0068] After obtaining the parameter value object, it can be injected into the function code of the target quantization function to generate an executable function instance object. Furthermore, based on the semantic information of the strategy logic flow corresponding to the quantization strategy description, the parameter value object can be injected into the function code of the target quantization function to generate a function instance object corresponding to the strategy logic flow.
[0069] Taking the order placement function mentioned above as an example, the system calls the Python function of the pre-defined order placement function func_order, passing the parameter value object generated in the previous step as the parameter. This generates a specific, executable function instance object in memory. This instance object encapsulates the specific operation logic and parameters, but it has not yet been packaged into the node control and placed in the flowchart.
[0070] Furthermore, taking the above strategy logic flow as an example, we can see the steps of "implementing the sell branch", "implementing the buy branch" and "creating the holding judgment card". For the strategy logic flow "implementing the buy branch", its target quantification function can be determined to include the order placement function func_order and the magic nine-turn function func_nine, as well as the parameter value object corresponding to the target quantification function; Specifically, the function code and parameter value object of the order placement function `func_order` under this strategy logic flow can be used as parameters to generate a function instance object under this strategy logic flow, which can be represented as the buy action function instance object `buy_order_func`, i.e.: buy_order_func==func_order(code=symbolA,trd_side="BUY",qty=1,qty_type="LOT")"; Similarly, based on the function code and parameter value object of the "magic nine-turn" function `func_nine` under this strategy logic flow, a function instance object under this strategy logic flow can be generated, which can be represented as the "downward nine-turn structure judgment function object `nine_down_func`, i.e.: nine_down_func=func_nine(code= symbolA,k_type="K_DAY")".
[0071] For the strategy logic flow "implementing the sell branch", its target quantization function can be determined to include the order placement function func_order and the magic nine-turn function func_nine, as well as the parameter value object corresponding to the target quantization function; Among them, the function code and parameter value object of the order placement function func_order under the strategy logic flow can be used as parameters to generate a function instance object under the strategy logic flow, which can be represented as the sell action function instance object sell_order_func, that is, "sell_order_func=func_order(code=symbolA,trd_side="SELL",qty=1,qty_type="MAX_SELL")". Similarly, based on the function code and parameter value objects of the magic nine-turn function func_nine under this strategy logic flow, a function instance object under this strategy logic flow can be generated, which can be represented as the upward nine-turn structure judgment function object nine_up_func, that is: "nine_up_func=func_nine(code= symbolA,k_type="K_DAY")".
[0072] For the strategy logic flow "Creating a Position Judgment Card", the function code of the position query function func_posiqty under this strategy logic flow and its parameter value object can be used as parameters to generate a function instance object under this strategy logic flow. This can include the no-position judgment function object no_position_func and the position judgment function object has_position_func, which are represented as follows: no_position_func==func_posiqty(code= symbolA) has_position_func==func_posiqty(code= symbolA ) Based on the aforementioned metadata-driven function instantiation approach, large models do not need to understand the complete quantization business code. They only need to learn from the limited and clearly structured metadata definitions of quantization functions to select and match target quantization functions, resulting in fast inference speed and high accuracy. The explicit parameter types and constraints in the metadata definitions enable the system to automatically verify and correct the user-input quantization strategy descriptions, reducing strategy failures caused by parameter errors. When adding a new quantization function, only its metadata definition needs to be added and the implementation code registered, without modifying the core inference logic, greatly reducing maintenance costs. The generated function instance objects are standardized memory objects that can be seamlessly encapsulated as card node instances to build a complete strategy flowchart.
[0073] Step 203: Based on the function instance object and the pre-defined graph node function set, generate executable strategy code. The strategy code is the program code that quantizes the logical flow described by the strategy flowchart corresponding to the strategy description.
[0074] The graph node function set contains global functions, which may include card node functions and connection functions. These functions are used to create start card controls, condition card controls, action card controls, and to connect different card controls. In one embodiment, the card node functions include start card node functions, condition card node functions, and action card node functions.
[0075] In one embodiment, to achieve efficient interaction between graph node functions and a large language model, and to ensure the accuracy of subsequent strategy code generation, this application associates structured metadata definitions with each type of function in the graph node function set. These metadata definitions are stored in a structured format (such as JSON or YAML) and describe the static properties of the corresponding functions, enabling the system or large model to perform function matching, parameter validation, and code generation based on this metadata.
[0076] Specifically, the metadata definitions for various graph node functions include the following: For a conditional card node function, its metadata definition includes at least: a function name (e.g., "graph_conditional_card"), used to uniquely identify the function; a function description, used to summarize the function of the card in natural language (e.g., "create a conditional judgment card"); lvalue function information, used to specify the core quantitative function on which the condition judgment depends (e.g., referencing a function instance for judging position quantity); rvalue function information, used to specify the benchmark value or another reference function for the condition judgment; and comparison operator information, used to specify the comparison rules between the lvalue and the rvalue (e.g., "greater than", "equal to", "IS", etc.). Through the combination of the above information, the complete judgment logic of a conditional card node can be clearly defined and indexed at the metadata level.
[0077] For an action card node function, its metadata definition includes at least: a function name (e.g., "graph_action_card"), used to uniquely identify the function; a function description, used to summarize the function's purpose in natural language (e.g., "create a card to perform a transaction operation"); and action function information, used to specify the specific operation function encapsulated by the card (e.g., referencing an instance of a buy order function). This definition clarifies the core execution logic of the action card.
[0078] For a connection function, its metadata definition includes at least: a function name (e.g., "graph_line"), used to uniquely identify the function; a function description, used to summarize the function of the connection in natural language (e.g., "create a logical connection between two card nodes"); starting card node information, used to specify the starting card of the connection; ending card node information, used to specify the ending card of the connection; connection type, used to distinguish the nature of the connection (e.g., "sequential connection" or "conditional branch connection"); and condition judgment logic, used to clarify the branch conditions corresponding to the connection when the connection is a conditional branch type (e.g., "condition satisfied" branch or "condition not satisfied" branch).
[0079] By predefining the aforementioned structured metadata for various functions in the graph node function set, this application abstracts the construction logic of the policy canvas from hard-coded graph operations and transforms it into a standardized interface that can be dynamically parsed and invoked by the program. On the one hand, the large language model can accurately map the logical elements in the user's natural language description (such as "if...then...otherwise...") to the corresponding card node function and connection function calls based on these semantically rich metadata definitions. On the other hand, when the system executes these function calls, it can automatically verify them based on the parameter types and constraints in the metadata definitions, thereby avoiding logical errors during the code generation stage and significantly improving the accuracy and robustness of the quantization policy generation process.
[0080] The strategy code, in the form of function calls, expresses all the topological information of the strategy flowchart corresponding to the quantization strategy description, and realizes the direct generation of programming code with equivalent structured semantics from the strategy flowchart semantics implicit in the quantization strategy description input by the user in natural language.
[0081] Specifically, the target quantization function is used to implement single data processing. After obtaining the function instance object of the target quantization function, based on the semantic information of the strategy logic flow corresponding to the quantization strategy description, the card node functions required to implement each strategy logic flow and the target quantization functions required by the card node functions are determined. Then, the function instance objects of the target quantization functions required by the card node functions are injected into the card node functions to generate card node instances corresponding to the strategy logic flow. At the same time, based on the strategy logic flow corresponding to the quantization strategy description, the logical order between different card node instances is determined, and connection instances between card node instances are generated. Finally, based on the card node instances and connection entities, the strategy flowchart corresponding to the quantization strategy description and the strategy code corresponding to the strategy flowchart are determined.
[0082] Based on function instance objects and a pre-defined set of graph node functions, executable strategy code is generated, including the following steps: Step 2031: Based on the card node function, encapsulate the function instance object into the corresponding card node instance, where the card node instance includes condition card node instance and action card instance.
[0083] Specifically, based on the semantic information of the strategy logic flow corresponding to the quantization strategy description, the card node functions required for each strategy logic flow and the target quantization functions involved in the card node functions are determined. Then, the function instance objects of the target quantization functions are injected into the card node functions to generate card node instances corresponding to each strategy logic flow.
[0084] Step 2032: Based on the logical relationships in the quantization strategy description, construct connection instances that connect different card node instances using the connection function.
[0085] Specifically, based on the semantic information of the corresponding strategy logic flow described by the quantization strategy, the connection relationships between each card node instance are determined, and the graph_line function is called to create connection instances between the card node instances. For example, this includes connection instances connecting the "start card node instance" to the "condition card node instance", and connection instances connecting the "condition card node instance" to the "action card node instance". Each connection can be accompanied by conditions (such as the output port identifier of the conditional branch).
[0086] Step 2033: Encapsulate the card node instance and the connection instance into a strategy flowchart instance object to obtain executable strategy code.
[0087] Specifically, the top-level construction function `build_graph` can be called to aggregate all generated card node instances (start card control, condition card control, action card control) and connection instances to form a strategy graph object that can actually run in memory. This object can fully represent the strategy graph semantics implied by the quantized strategy description input in natural language.
[0088] Understandably, the executable strategy code implicitly contains the graph structure information of the strategy flowchart contained in the quantization strategy description. For example, it is composed of card controls and connections, which can clearly show the execution order, conditional branches, action triggers and other control flow semantics of the quantization strategy corresponding to the quantization strategy description. The strategy code acts as a bridge between the graph structure of the quantization strategy description input by natural language and the strategy flowchart, which improves the accuracy of the subsequent generation of the quantization strategy canvas.
[0089] Taking the above strategy logic flow "implementing the sell branch" as an example, based on the semantic information of the strategy logic flow corresponding to the quantitative strategy description, the required card node functions are determined to include condition card node functions and action card node functions. Specifically, a card node instance for judging the upward nine-turn structure can be generated through a conditional card node function. The function instance object of the target quantization function corresponding to this conditional card node function is the upward nine-turn structure judgment function object `nine_up_func`. Then, based on the semantic information of the strategy logic flow, the upward nine-turn structure judgment function object `nine_up_fun` is determined as the l-value function information of the conditional card node function, "UP" is determined as the r-value function information of the conditional card node function, and "IS" is determined as the comparison operator information. The `graph_conditional_card` function is then called to generate the card node instance, thus obtaining the conditional card node instance used to judge the upward nine-turn structure. Specifically, this card node instance can be represented as follows: nine_up_card = graph_conditional_card( card_desc="Judging the Nine Structures of the Magical Nine Turns Rise", card_func_left=nine_up_func, comparator="IS", card_func_right="UP") Specifically, the action card node function generates the sell position, and the corresponding target quantification function's function instance object is the sell action function instance object `sell_order_func`. Then, based on the semantic description of the strategy logic flow, the sell action function instance object `sell_order_func` is determined as the rvalue function information of the action card node function, and "UP" is determined as the rvalue function information of the condition card node function. The `graph_action_card` function is called to generate a card node instance, resulting in the action card instance used for selling the position. Specifically, this card node instance can be represented as follows: sell_action_card = graph_action_card( card_desc="Sold Positions", action=sell_order_func) Taking the above strategy logic flow "creating a position judgment card" as an example, based on the semantic information of the strategy logic flow corresponding to the quantitative strategy description, the required card node functions are determined to include condition card node functions; among them, card node instances for judging the position quantity of the driving object can be generated through the condition card node functions, and the function instance objects of the target quantitative function corresponding to the condition card node function include no position judgment function object no_position_func and position judgment function object has_position_func; Furthermore, based on the semantic information of the strategy logic flow, the no-position judgment function object `no_position_func` is determined as the lvalue function information of the condition card node function, zero value is determined as the rvalue function information of the condition card node function, and "equal" is determined as the comparison operator information. The `graph_conditional_card` function is then called to generate a card node instance, resulting in a condition card node instance used to determine the number of no-position positions. Specifically, this card node instance can be represented as follows: no_position_card = graph_conditional_card( card_desc="No holdings" card_func_left=no_position_func, comparator="EQUAL", card_func_right=0) Similarly, based on the semantic information of the strategy logic flow, the `has_position_func` function object for determining the position is identified as the lvalue function information of the condition card node function, zero is identified as the rvalue function information of the condition card node function, and "GREATER_THAN" is identified as the comparison operator information. The `graph_conditional_card` function is then called to obtain the card node instance, generating a condition card node instance used to determine the number of no open positions. Specifically, this card node instance can be represented as follows: has_position_card = graph_conditional_card( card_desc="Have a holding decision", card_func_left=has_position_func, comparator="GREATER_THAN", card_func_right=0) Once the corresponding card node instances for each strategy logic flow are identified, the connection relationships between the card node instances can be determined based on the semantic information of the corresponding strategy logic flow described in the quantitative strategy description. The graph_line function is then called to create connection instances between the card node instances. Taking the strategy logic flow "implementing the sell branch" as an example, its semantic information is represented as: has_position_car (holding judgment) → nine-stage upward structure judgment → sell holdings. Correspondingly, the connection instances created by calling the graph_line function can be represented as: has_position_to_nine_up_line = graph_line( start=has_position_card, end=nine_up_card, condition="1") Understandably, as in the quantization strategy canvas described above, the quantization strategy is presented in the form of a strategy flowchart. Its storage and organization within the computer employ a graph data structure, recording the logical topological relationships of the quantization strategy in a "node-connection" manner. However, this graph data structure focuses on low-level encoding of connections, and its control flow semantics (such as sequential execution and conditional branches) are implicitly distributed within the topological relationships of nodes and edges, resulting in low semantic density. When a quantization strategy description input by the user in natural language is obtained, and this description is converted into a graph data structure of the corresponding strategy flowchart, the model is forced to simultaneously perform natural language semantic understanding and graph topology generation. This makes it difficult to guarantee the accuracy and robustness of the generated results, especially when dealing with quantization strategies containing complex branching logic. In the above embodiment, the strategy code acts as a crucial intermediate bridge, both inheriting the semantics of the quantization strategy description input in natural language and being compatible with the generation of strategy flowcharts in existing quantization strategy canvases.
[0090] Specifically, the control flow semantics in the strategy flowchart are explicitly encoded through a set of graph node functions using structured function calls and parameter passing. For example, for the strategy logic "If there is a position and a nine-upward structure appears, then sell," which includes conditional branches, the strategy code does not simply describe two nodes and a labeled edge. Instead, it establishes a programmatic association between the condition-satisfied branches (such as the connection condition="1") and specific action card instances through precise function calls. This coded representation extracts the control flow semantics of the strategy flowchart, such as execution order, branch paths, and triggering conditions, from the implicit graph topology, transforming them into structured statements that can be directly used by program parsing and large models. This allows the logical flow contained in the quantitative strategy description input in natural language to be accurately and unambiguously mapped into a code structure.
[0091] Furthermore, unlike graph data structures where nodes merely serve as abstract endpoints in topological relationships, the strategy code in this embodiment encapsulates the parameterized target quantization function instance object into a card node instance through card node functions. This upgrades each graph node from a "graph element" to a "reasonable semantic unit." For example, a "conditional card node instance" is declared in the strategy code as a complete conditional judgment semantic block, explicitly defining its logical input (such as the target quantization function instance object referenced by card_func_left), operation rules (such as comparator="IS"), and expected judgment benchmark (such as card_func_right="UP"). This structured encapsulation allows the strategy code to accurately correspond to each strategy element in the natural language description when moving upwards; and when moving downwards, it provides complete semantic annotations for each node in the graph data structure, rather than just a node identifier.
[0092] In the strategy code of this embodiment, the connection relationships between nodes are visualized as graph construction instructions, rather than reference pointers directly embedded within node objects. When a connection instance generation function (such as `graph_line`) is called, the strategy code expresses the constructive semantics of "establishing a connection between the output port of node A and the input port of node B according to specific conditions." This expression method, on the one hand, tightly binds the connection relationships with the conditional logic, making it easy for large models to be directly generated based on the logical relationships described in natural language; on the other hand, it also maintains a clear one-to-one correspondence between the strategy code and the final graph data structure. In subsequent steps, only these graph construction instructions need to be parsed and executed to accurately construct the corresponding graph data structure and generate the strategy flowchart seen by the user on the visualization interface.
[0093] This application's embodiments introduce structured policy code as an intermediate representation layer, addressing the conversion problem from natural language description to policy flowcharts. Leveraging the powerful parsing and generation capabilities of large language models for structured program code, the quantization policy description input in natural language is converted into structured policy code, achieving accurate capture of complex semantics. Subsequently, based on the policy code, the deterministic mapping relationship between the structured policy code and graph construction instructions ensures the accuracy of the final output policy flowchart in terms of topological structure and control flow semantics. This effectively overcomes the problem of insufficient semantic expression capabilities when large models directly generate graph data structures, significantly improving the accuracy and robustness of automatically generating complex quantization policies.
[0094] In other words, the strategy code uses programming syntax to express the structured semantics of the strategy flowchart, which can be understood as using the syntax structure of a high-level programming language (Python) to equivalently express the flowchart. Specifically, this is reflected in: Structured node semantics: Each process node (i.e., card) is modeled in the code as an independent function call statement, which explicitly declares the node's type and business parameters. For example, the statement creating a condition card explicitly specifies the lvalue function (e.g., "current holding quantity"), comparison operator (e.g., "greater than"), and rvalue (e.g., "0"); the statement creating an action card explicitly specifies the action function (e.g., "buy") and its parameters (e.g., stock code, quantity); the statement creating a start card requires no additional parameters. In this way, each node is upgraded from a graph element to a reasonable semantic unit. Connections are embedded in the control structure: the direction and conditions of edges are no longer implicitly stored in a separate edge list, but are explicitly expressed through variable references and condition labels in the code. For example: first create node A, then node B, and then create a connection from A to B, specifying a condition identifier (such as "condition satisfied" or "condition not satisfied") in the connection. For branching structures, the code creates multiple condition cards and corresponding connections, each connection bound to a different branch condition. This representation makes path selection directly understandable by static analysis or large models. Order and dependencies are expressed through code order: during strategy construction, the order in which nodes and connections are created naturally reflects the dependencies in the strategy flow. Large models can accurately express the flowchart structure by maintaining a reasonable statement order when generating code.
[0095] For example, the generated strategy code logically includes the following: defining the trading target; creating the strategy's starting card; creating condition cards based on strategy branches, where each condition card specifies its left-hand function (such as the position quantity function or the Magic AA function), comparison operator (such as "greater than" or "equal to"), and right-hand value (such as 0 or "UP"); creating action cards: defining the operation to be performed when the condition is met (such as buying one lot or selling all); creating connections between cards: each connection specifies the starting card, ending card, and the branch condition it represents (such as "condition met" or "condition not met"); and aggregating all cards and connections to construct a complete strategy canvas object.
[0096] This application elevates the storage problem of graph structures to a programmatic expression problem of process semantics, enabling large models to leverage their powerful code understanding and generation capabilities to construct quantization strategies, significantly improving generation success rate and logical accuracy.
[0097] In one embodiment, to accurately transform the quantization strategy described in natural language into a subsequently renderable visualization canvas, this application employs a specific programming syntax to express the structured semantics of the strategy flowchart. The core of this syntax lies in explicitly encoding the control flow logic in the flowchart into structured program statements through card node functions and connection functions in a predefined set of graph node functions.
[0098] Optionally, the control flow semantics in the strategy flowchart are explicitly encoded into structured program statements using card node functions and connection functions from a predefined set of graph node functions. Based on the card node functions, function instance objects are encapsulated into card node instances, and corresponding program statements are generated. These program statements explicitly declare the node type of the card node instance, its associated function instance object, and parameter information. Based on the connection functions and the logical relationships in the quantization strategy description, connection instances connecting different card node instances are generated, and corresponding program statements are generated. These program statements explicitly declare the starting card node, ending card node, and branch conditions of the connection instances. The program statements corresponding to the card node functions and connection functions are executed sequentially to generate a strategy flowchart instance object that aggregates card node instances and connection instances, serving as executable strategy code.
[0099] Specifically, the implementation of this programming syntax is as follows: First, the generated function instance objects are encapsulated using card node functions. For example, when a conditional judgment node needs to be created, the system calls the `graph_conditional_card` function, passing in the function instance object representing the specific judgment logic (such as `nine_up_func` used to judge the "nine-up structure") as a parameter. This operation generates a corresponding program statement. This program statement is not a simple function call, but explicitly declares the type of the created card node (such as "conditional card"), the associated core function instance object (such as `nine_up_func`), the comparison operator (such as "IS"), and the comparison benchmark value (such as "UP"), among other key parameter information. Thus, a previously implicit graph node is explicitly declared at the code level as a code entity containing complete business semantics that can be independently parsed.
[0100] Secondly, the graph function is used to construct the logical relationships between nodes. Based on the logical relationships (such as sequential execution, conditional branching, etc.) parsed from the quantization strategy description, the system calls the `graph_line` function. This function generates another piece of code to create connection instances that link different card node instances. This code explicitly declares the starting and ending card node instances of the connection, and most importantly, the branch condition represented by the connection. For example, in a branch structure of "condition satisfied" and "condition not satisfied", the system generates two different connection statements, carrying the labels `condition="1"` and `condition="0"` respectively, clearly defining the path selection rules for program execution.
[0101] Finally, by executing the program statements generated by the card node function and the connection function in sequence, the system aggregates all generated card node instances and connection instances, encapsulating them into a complete strategy flowchart instance object. This object itself is an executable strategy code. The advantage of this representation is that it elevates the semantics of the flowchart from the implicit graph topology to the explicit code structure level. This allows both the large model and the subsequent program parser to directly and unambiguously understand the logical flow of the strategy, thus providing a foundation for the subsequent stable conversion of the strategy code into a visual canvas.
[0102] Through the programming syntax described in this embodiment, this application realizes the "code-based" expression of flowchart logic, ensuring high accuracy and robustness of the transformation link from natural language description to the final visualization canvas.
[0103] Step 204: Convert the strategy code into a class abstract syntax tree representation at runtime, and generate canvas protocol data for the strategy flowchart based on the class abstract syntax tree representation.
[0104] The class abstract syntax tree representation can include multiple nodes, each of which can be used to map the strategy flowchart to node controls on the quantized strategy canvas. Specifically, the strategy code is transformed into a structured class abstract syntax tree representation. Through the class abstract syntax tree representation, key information such as the card control type, hierarchical relationship, parameters of the card control, and the calling order and connection relationship between card controls corresponding to the card node instances in the strategy code are represented. The control flow that was originally implicit in the strategy code is expressed in a structured way, and the unstructured and ambiguous nature of the code is significantly reduced, thereby greatly reducing the difficulty of parsing the subsequent generation of the strategy flowchart.
[0105] Specifically, the strategy code can be pre-instrumented, and each function call during the execution of the strategy code can be extracted and transformed in real time into a standardized class abstract syntax tree representation containing rich business semantics. Then, for all nodes in the class abstract syntax tree representation, canvas protocol data for drawing strategy flowcharts can be generated based on the node type and attribute information of the node.
[0106] It should be noted that step 204 above aims to solve the automatic conversion of executable policy code into a visualized policy flowchart in the quantitative policy canvas. Since the code itself is unstructured information, it is difficult and unstable to directly extract graph topology information from it. It is also difficult and inaccurate to directly convert the policy code into a policy flowchart with graph data structure. Therefore, the policy code is first converted into a class-Abstract Syntax Tree (AST) representation, and then canvas protocol data for constructing the policy flowchart is generated based on the class-Abstract Syntax Tree representation. The unstructuredness and ambiguity of the policy code are significantly reduced, and the parsing difficulty of the subsequent generation of the policy flowchart is greatly reduced.
[0107] After obtaining the abstract syntax tree (AST) representation, nodes in the AST representation can be converted into canvas protocol data for the policy flowchart based on preset graph generation rules. The graph generation rules record the mapping relationship between various nodes in the AST representation (each node corresponds to a card node instance in the policy code) and their corresponding primitives (nodes and edges) in the policy flowchart. They also convert control structures such as sequential dependencies, conditional branches, and call chains between nodes into visual topological connections and branch paths, while supplementing node attribute information (such as parameters, inputs, and outputs in card node instances). The same AST representation can produce the same canvas protocol output, ensuring the stability and semantic consistency of the policy code to policy flowchart conversion process.
[0108] In one embodiment, step 204 specifically includes the following steps: Step S2041: In the execution environment of the strategy code, the card node instance of the strategy code is instrumented so that card metadata is automatically recorded each time the card node instance of the strategy code is called. The card metadata includes card node type, card node parameters and the calling order between card nodes.
[0109] The meaning of instrumentation here is that when any canvas construction function (such as creating cards or creating connections) is called, in addition to executing its original function, it will automatically record the function name, input parameters, return value, and calling order of this call. After the strategy code has finished executing, a structured intermediate representation similar to an AST is generated based on the recorded information.
[0110] This type of AST data contains all the component information of the canvas: a list of cards (each card's type, associated function, and parameter values) and a list of connections (each connection's starting card identifier, ending card identifier, and branch condition label). AST data is highly structured and unambiguous. That is, by reducing the unstructured and ambiguous nature of the code, the difficulty of subsequent parsing is significantly reduced.
[0111] In other words, the system instrumentes or proxies graph node functions such as `graph_conditional_card` and `graph_action_card` within the Python runtime environment. When these functions are called, metadata such as the type of card node generated, parameters, and call order is automatically recorded.
[0112] For example, this application pre-instruments the canvas construction functions in the Python runtime environment. Specifically, all functions used to create cards, lines, and the canvas (such as creating condition cards, action cards, and lines) are replaced with wrapper functions that include logging functionality. These wrapper functions, while executing the original logic, perform the following operations: generate a globally unique card or line identifier; record the function name, input parameters (after serialization), and returned card / line objects in a sequential list; and record the current call's sequence number within the entire execution flow.
[0113] Step S2042: Run the strategy code in the runtime environment and generate a class abstract syntax tree representation corresponding to the program execution path of the target strategy code based on the card metadata. The class abstract syntax tree includes multiple nodes and node metadata.
[0114] In other words, the strategy code generated in step S203 is executed. Because the code calls graph node functions with instrumentation, the execution path dynamically generates a structured intermediate representation, i.e., an AST-like representation. This AST-like representation differs from the traditional static AST; it is closer to the actual execution semantics of the program and records the actual construction relationships between nodes.
[0115] After the strategy code completes execution, a complete time series table is obtained, containing detailed information for each operation. This time series table is then converted into structured AST-like data. This AST-like data contains two main sets: a card set, where each card entry records the card type (start / condition / action), associated function identifier, function parameter values, descriptive text, etc.; and a connection set, where each connection entry records the start card identifier, end card identifier, and condition identifier (e.g., "0" represents a false branch, "1" represents a true branch, or empty represents a sequential connection). Because this type of AST data is obtained during runtime through actual execution, it accurately reflects the true semantics of the code and is unaffected by coding style.
[0116] In this embodiment, by pre-inserting the canvas construction function in the strategy code runtime environment, the type, parameters, and call order of each function call are automatically recorded during the actual execution of the strategy code. Based on the method of obtaining runtime information, the actual execution path of the code and the actual parameter binding results can be captured. The generated class abstract syntax tree representation is closer to the actual execution semantics of the strategy code, effectively avoiding the limitations of static analysis methods that are affected by coding style and dynamic characteristics.
[0117] Furthermore, by introducing an AST-like intermediate representation, this application decouples code generation from canvas rendering. On one hand, the large model only needs to focus on generating policy code that conforms to the specification, without needing to worry about the specific protocol format; on the other hand, the canvas protocol only needs to process structured AST-like data, without needing to process the raw code text. This two-stage transformation significantly improves the stability and maintainability of the system, and can adapt to future additions of function types and card types, thus improving the stability, maintainability, and scalability of the transformation while ensuring semantic consistency.
[0118] Step S2043: Based on the preset graph generation rules, the nodes of the class abstract syntax tree are mapped to the canvas protocol data of the strategy flowchart.
[0119] The system defines a set of deterministic parsing and mapping rules. These rules define a set of explicit transformation rules. For example, for each card entry in the card set, a corresponding protocol message is generated based on its type, and function parameters are filled into the corresponding fields of the message; for each connection entry in the connection set, a LineMessage is generated, containing the starting card ID, ending card ID, and condition fields; finally, all messages are encapsulated in a GraphMessage. This parsing and mapping rule is deterministic, meaning that the same AST-like input always produces the same canvas protocol output, ensuring the stability of the transformation. The system iterates through the AST generated in the previous step, mapping it to canvas protocol data in Protocol Buffers (PB) format agreed upon by the front-end and back-end, based on node type (e.g., "condition card node," "action card node") and connection relationship (e.g., "connection node"). This data describes the coordinates, style, internal function logic, and connection paths between each card on the canvas.
[0120] Step 205: Render and generate a visual quantization strategy canvas based on the canvas protocol data.
[0121] After receiving the canvas protocol data generated in step S204, the front-end (client) calls the rendering engine to present a visual, drag-and-drop editable quantization strategy canvas on the user interface. This canvas is semantically equivalent to the user's initial natural language description, and the generated Python code is completely consistent with the canvas display.
[0122] Specifically, after generating the canvas protocol data, the following steps are performed to complete the visualization rendering: Parse the canvas protocol data: deserialize it into an object model that can be manipulated by the front end; Calculate the layout: automatically calculate the position coordinates of each card on the canvas based on the number of cards and the connection relationship (avoiding overlap and keeping the connection clear); Generate graphic elements: draw card nodes of different shapes and colors according to the card type, and draw connections with arrows; Bind interactive events: support card dragging and moving, connection editing, parameter modification, deletion / addition and other operations; Real-time synchronization: the canvas edited by the user can generate new protocol data in reverse, which can be used for saving or generating code.
[0123] Therefore, the quantization strategy generation method provided in this application obtains a quantization strategy description input by the user in natural language; based on the quantization strategy description, a target quantization function is determined from a pre-set quantization function library, and the target quantization function is instantiated with parameters to generate a function instance object; based on the function instance object and a pre-set set of graph node functions, executable strategy code is generated, where the strategy code is the program code describing the logical flow of the strategy flowchart corresponding to the quantization strategy description; the strategy code is converted into a class abstract syntax tree representation at runtime, and canvas protocol data for the strategy flowchart is generated based on the class abstract syntax tree representation; and a visual quantization strategy canvas is generated by rendering based on the canvas protocol data. This method achieves low-threshold and high-efficiency quantization strategy generation through a complete link from natural language to executable code to a visual canvas, significantly reducing the development threshold of quantization strategies, improving generation efficiency and accuracy, and solving problems such as high pure code understanding cost, long pure prompt time, and unavailability of visualization function in the prior art.
[0124] Figure 4 A schematic diagram of the structure of a quantization strategy generation device provided in an embodiment of this application is shown.
[0125] like Figure 4 As shown, the quantization strategy generation device 10 includes: The acquisition module 11 is used to acquire the quantization strategy description input by the user in natural language; The filtering module 12 is used to determine the target quantization function from the preset quantization function library according to the quantization strategy description, and to instantiate the parameters of the target quantization function to generate a function instance object; The first generation module 13 is used to generate executable strategy code based on the function instance object and the preset graph node function set. The strategy code is the program code of the logical flow described by the strategy flowchart corresponding to the quantization strategy description. The second generation module 14 is used to convert the strategy code into a class abstract syntax tree representation at runtime, and generate the canvas protocol data of the strategy flowchart based on the class abstract syntax tree representation. The third generation module 15 is used to render and generate a visualization quantization strategy canvas based on the canvas protocol data.
[0126] In some embodiments, the filtering module 12 is specifically used for: Obtain the metadata definition of the target quantization function, wherein the metadata definition includes at least the function name, parameter list, and parameter types; Extract the parameter values corresponding to the parameter list from the quantization strategy description; The extracted parameter values are validated according to the parameter type. The validated parameter values are encapsulated into a parameter value object; The target quantization function is invoked, and the parameter value object is used as input to generate an executable function instance object.
[0127] The graph node function set includes card node functions and connection functions; In some embodiments, the first generation module 13 is specifically used for: Based on the card node function, the function instance object is encapsulated into a corresponding card node instance, wherein the card node instance includes a condition card node instance and an action card instance; Based on the logical relationships in the quantization strategy description, connection instances connecting different card node instances are constructed using connection functions; The card node instance and the connection instance are encapsulated into a strategy flowchart instance object to obtain executable strategy code.
[0128] In some embodiments, the first generation module 13 is further configured to: The structured semantics of the strategy flowchart are expressed using programming syntax, where: The control flow semantics in the strategy flowchart are explicitly encoded into structured program statements through the card node functions and connection functions in the preset graph node function set. Based on the card node function, the function instance object is encapsulated into the card node instance, and corresponding program statements are generated. The program statements explicitly declare the node type, associated function instance object, and parameter information of the card node instance. Based on the connection function and the logical relationship in the quantization strategy description, a connection instance connecting different card node instances is generated, and a corresponding program statement is generated. The program statement explicitly declares the starting card node, ending card node, and branching conditions of the connection instance. The program statements corresponding to the card node function and the connection function are executed sequentially to generate a strategy flowchart instance object that aggregates the card node instance and the connection instance, which serves as the executable strategy code.
[0129] In some embodiments, the second generation module 14 is specifically used for: In the runtime environment where the strategy code is executed, the card node instance of the strategy code is instrumented so that card metadata is automatically recorded each time the card node instance of the strategy code is called. The card metadata includes card node type, card node parameters, and the calling order between card nodes. The strategy code is run in the runtime environment, and a class abstract syntax tree representation corresponding to the program execution path of the target strategy code is generated based on the card metadata. The class abstract syntax tree includes multiple nodes and meta-information. Based on preset graph generation rules, the nodes of the class abstract syntax tree are mapped to the canvas protocol data of the strategy flowchart.
[0130] In some embodiments, the graph node functions in the graph node function set are each associated with a corresponding metadata definition; wherein, The metadata definition of a condition card node function should include at least the function name, card node function description, lvalue function information, rvalue function information, and comparison operator information. The metadata definition of an action card node function should include at least: function name, card node function description, and action function information; The metadata definition of a connection function should include at least the following: function name, function description, starting card node information, ending card node information, connection type, and condition judgment logic.
[0131] It should be understood that the modules or modules described in the quantization strategy generation device 10 and the reference Figure 2 The steps in the described method correspond accordingly. Therefore, the operations and features described above for the method also apply to the quantization strategy generation device 10 and its included modules, and will not be repeated here. The quantization strategy generation device 10 can be pre-implemented in the browser or other security applications of an electronic device, or it can be loaded into the browser or its security applications of an electronic device through download or other means. The corresponding modules in the quantization strategy generation device 10 can cooperate with the modules in the electronic device to implement the solutions of the embodiments of this application.
[0132] The division of modules or units mentioned in the detailed description above is not mandatory. In fact, according to the embodiments of this disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0133] The following is for reference. Figure 5 , Figure 5 A schematic diagram of the structure of a computer system suitable for implementing the embodiments of this application is shown. like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 502 or programs loaded from storage section 508 into random access memory (RAM) 503. RAM 503 also stores various programs and data required for the system's operating instructions. CPU 501, ROM 502, and RAM 503 are interconnected via bus 504. Input / output (I / O) interface 505 is also connected to bus 504.
[0134] The following components are connected to I / O interface 505: an input section 506 including a keyboard, mouse, etc.; an output section 507 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to I / O interface 505 as needed. A removable medium 511, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 510 as needed so that computer programs read from it can be installed into storage section 508 as needed.
[0135] Specifically, according to embodiments of this application, the flowchart above refers to... Figure 2 The described process can be implemented as a computer software program. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowchart. In such an embodiment, the computer program contains program code for performing the methods shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via communication section 509, and / or installed from removable medium 511. When the computer program is executed by central processing unit (CPU) 501, it performs the functions defined in the system of this application.
[0136] It should be noted that the computer-readable medium shown in this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0137] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operational instructions of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two connected blocks may actually be executed substantially in parallel, or they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified functions or operational instructions, or using a combination of dedicated hardware and computer instructions.
[0138] The units or modules described in the embodiments of this application can be implemented in software or hardware. The described units or modules can also be housed in a processor; for example, a processor can be described as including an acquisition module, a determination module, an update module, a matching module, and a recommendation module. The names of these units or modules do not necessarily limit the unit or module itself; for example, the acquisition module can also be described as "acquiring a quantization strategy description input by the user in natural language."
[0139] In another aspect, this application also provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiments, or may exist independently and not assembled into the electronic device. The aforementioned computer-readable storage medium stores one or more programs that, when used by one or more processors, execute the quantization strategy generation method described in this application.
[0140] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the foregoing disclosed concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.
Claims
1. A method for generating a quantization strategy, characterized in that, include: Obtain the quantization strategy description input by the user in natural language; According to the quantization strategy description, a target quantization function is determined from a pre-set quantization function library, and the target quantization function is instantiated with parameters to generate a function instance object; Based on the function instance object and the preset graph node function set, executable strategy code is generated. The strategy code is the program code of the logical flow described by the strategy flowchart corresponding to the quantization strategy description. The strategy code is converted into a class abstract syntax tree representation at runtime, and the canvas protocol data of the strategy flowchart is generated based on the class abstract syntax tree representation. A visual quantization strategy canvas is generated based on the canvas protocol data rendering.
2. The quantization strategy generation method according to claim 1, characterized in that, The step of determining the target quantization function from a pre-set quantization function library includes: Semantic analysis of the quantization strategy description is performed using a large language model to obtain the strategy logic flow corresponding to the quantization strategy description. Using the metadata definitions of all quantization functions in the quantization function library as context, the large language model is invoked to determine one or more target quantization functions involved in each of the strategy logic flows from the quantization function library; wherein, the metadata definitions include at least the function name, parameter list, and parameter type.
3. The quantization strategy generation method according to claim 1, characterized in that, Instantiating the parameters of the target quantization function to generate a function instance object includes: Obtain the metadata definition of the target quantization function, wherein the metadata definition includes at least the function name, parameter list, and parameter types; Extract the parameter values corresponding to the parameter list from the quantization strategy description; The extracted parameter values are validated according to the parameter type. The validated parameter values are encapsulated into a parameter value object; The target quantization function is invoked, and the parameter value object is used as input to generate an executable function instance object.
4. The quantization strategy generation method according to claim 1, characterized in that, The graph node function set includes card node functions and connection functions; the generation of executable strategy code based on the function instance object and the preset graph node function set includes: Based on the card node function, the function instance object is encapsulated into a corresponding card node instance, wherein the card node instance includes a condition card node instance and an action card instance; Based on the logical relationships in the quantization strategy description, connection instances connecting different card node instances are constructed using connection functions; The card node instance and the connection instance are encapsulated into a strategy flowchart instance object to obtain executable strategy code.
5. The quantization strategy generation method according to claim 4, characterized in that, The process of generating executable strategy code based on the function instance object and the preset set of graph node functions also includes: The structured semantics of the strategy flowchart are expressed using programming syntax, where: The control flow semantics in the strategy flowchart are explicitly encoded into structured program statements through the card node functions and connection functions in the preset graph node function set. Based on the card node function, the function instance object is encapsulated into the card node instance, and corresponding program statements are generated. The program statements explicitly declare the node type, associated function instance object, and parameter information of the card node instance. Based on the connection function and the logical relationship in the quantization strategy description, a connection instance connecting different card node instances is generated, and a corresponding program statement is generated. The program statement explicitly declares the starting card node, ending card node, and branching conditions of the connection instance. The program statements corresponding to the card node function and the connection function are executed sequentially to generate a strategy flowchart instance object that aggregates the card node instance and the connection instance, which serves as the executable strategy code.
6. The quantization strategy generation method according to claim 4, characterized in that, The strategy code is converted into a class abstract syntax tree representation at runtime, and canvas protocol data for the strategy flowchart is generated based on the class abstract syntax tree representation, including: In the runtime environment where the strategy code is executed, the card node instance of the strategy code is instrumented so that card metadata is automatically recorded each time the card node instance of the strategy code is called. The card metadata includes card node type, card node parameters, and the calling order between card nodes. The strategy code is run in the runtime environment, and a class abstract syntax tree representation corresponding to the program execution path of the target strategy code is generated based on the card metadata. The class abstract syntax tree includes multiple nodes and node metadata. Based on preset graph generation rules, the nodes of the class abstract syntax tree are mapped to the canvas protocol data of the strategy flowchart.
7. The quantization strategy generation method according to claim 1, characterized in that, Each graph node function in the graph node function set is associated with a corresponding metadata definition; among them, The metadata definition of a condition card node function should include at least the function name, card node function description, lvalue function information, rvalue function information, and comparison operator information. The metadata definition of an action card node function should include at least: function name, card node function description, and action function information; The metadata definition of a connection function should include at least the following: function name, function description, starting card node information, ending card node information, connection type, and condition judgment logic.
8. A quantization strategy generation device, characterized in that, include: The acquisition module is used to acquire the quantization strategy description input by the user in natural language; The filtering module is used to determine the target quantization function from the preset quantization function library according to the quantization strategy description, and to instantiate the parameters of the target quantization function to generate a function instance object; The first generation module is used to generate executable strategy code based on the function instance object and the preset graph node function set. The strategy code is the program code of the logical flow described by the strategy flowchart corresponding to the quantization strategy description. The second generation module is used to convert the strategy code into a class abstract syntax tree representation at runtime, and generate the canvas protocol data of the strategy flowchart based on the class abstract syntax tree representation. The third generation module is used to render and generate a visualization quantization strategy canvas based on the canvas protocol data.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the quantization strategy generation method as described in any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the program implements the quantization strategy generation method as described in any one of claims 1-7.
11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the quantization strategy generation method as described in any one of claims 1-7.
