avatar of FMZ~Lydia FMZ~Lydia
关注 私信
0
关注
42
关注者

Visualization Module to Build Trading Strategy - First Acquaintance

创建于: 2022-12-12 16:50:29, 更新于: 2024-12-23 18:00:35
comments   0
hits   840

Visualization Module to Build Trading Strategy - First Acquaintance

Visualization Module to Build Trading Strategy - First Acquaintance

Visual programming has always been an aspirational goal of software developers, even in the field of quantitative trading. Because the method of “what you see is what you get” in visualization reduces the technical threshold of programming development greatly. Users no longer have to deal with a pile of boring codes. They just use their imagination and logical thinking to focus on the business itself. You can realize a program you want. Isn’t it amazing?

Let’s get into the visual programming field of quantitative trading strategy together!

Visual programming of the initial FMZ Quant

After logging in to https://www.fmz.com, register your account (if you are already registered, log in directly) and click: Dashboard ->Strategy ->Add Strategy.

Visualization Module to Build Trading Strategy - First Acquaintance

We can see an initial visualization strategy. It is only used to output the account asset information of the default configured exchange (the first exchange object added on the backtest or robot). (See the figure below)

Visualization Module to Build Trading Strategy - First Acquaintance

Before we start learning how to use visualization, we can understand some design concepts of visualization.

  1. Splicing If you look carefully, you can see that modules have tenon (concave) and mortise (convex), i.e. modules can “connect” and “be connected”. If two modules represent functional codes that can be connected, then the tenons and mortises of the two modules will be attracted together when you bring them close.

Visualization Module to Build Trading Strategy - First Acquaintance

  1. Module setting and adjustment Some modules have some special settable areas, for example:

Visualization Module to Build Trading Strategy - First Acquaintance

You can drag the “Item” module on the left to the “Add” module, so that you can add a tenon (concave) position, thus adding a position for splicing text. In this way, click the pinion to adjust and set the module.

  1. Default input parameters of the module Some modules need to input some parameters, which may be numeric values or strings. If you do not add variables as input parameters of the module, the module will execute according to the default input parameters.

Visualization Module to Build Trading Strategy - First Acquaintance

The square root calculation module like this outputs the calculation results of this module.

Visualization Module to Build Trading Strategy - First Acquaintance

As you can see, if the input parameter position defaults, the default value 9 will be used as the input parameter to calculate the square root of 9.

Visualization Module to Build Trading Strategy - First Acquaintance

Of course, if you want to use a variable module as the input parameter, you can splice the variable module into the tenon (concave) position directly.

Visualization Module to Build Trading Strategy - First Acquaintance

  1. Operation The module can be clicked and dragged with the left mouse button. Modules can be copied with ctrl+c and pasted with ctrl+v, just as convenient as copying and pasting code or text. The operation area can be scaled with the mouse wheel, and all modules will be scaled larger or smaller. Click and drag the blank position in the operation area to move the operation area. The trash bin on the right side records the recently deleted modules. The most important thing is that after splicing the module strategy, don’t forget to click “Save”.

Introduction to visualization tool module

You can see that there are many module classifications on the left side of the visual editing area, and there are many visual modules available in each classification project.

There are 11 categories.

Visualization Module to Build Trading Strategy - First Acquaintance

Util module:

Visualization Module to Build Trading Strategy - First Acquaintance Visualization Module to Build Trading Strategy - First Acquaintance Visualization Module to Build Trading Strategy - First Acquaintance

  1. Output information: This module is usually used together with the module of text class, as shown below:

Visualization Module to Build Trading Strategy - First Acquaintance

You can enter a string in the text module, so that when you run the Output Information module, the string content in the text module will be printed.

Visualization Module to Build Trading Strategy - First Acquaintance

Backtesting:

Visualization Module to Build Trading Strategy - First Acquaintance Visualization Module to Build Trading Strategy - First Acquaintance

Like JavaScript language code:

function main(){
    Log("Hello, Blockly!")
}
  1. WeChat push: This module has the same appearance as the “output information”, which is different from the one that pushes information to WeChat bound to the current account at the same time.

Visualization Module to Build Trading Strategy - First Acquaintance

Like JavaScript language code:

function main () {
Log("WeChat Push!@")
}
  1. Throw exception Throwing exception module causes the program to issue an error, and then the program stops execution (without writing the exception handling code).

Visualization Module to Build Trading Strategy - First Acquaintance

Similarly, in the JavaScript strategy, the main function executes the throw “string to output” function directly.

function main () {
    throw "The first sentence throws an exception to stop the program!"
}

Backtesting results:

Visualization Module to Build Trading Strategy - First Acquaintance Visualization Module to Build Trading Strategy - First Acquaintance

Generally, it is used more when debugging. For example, if you want the program to stop under certain conditions and print some data at that time for observation. Or you can place an exception module in the code flow where problems may occur, let the program report errors, and find some errors.

  1. Sleep Sleep module

Visualization Module to Build Trading Strategy - First Acquaintance

As in JavaScript strategy:

function main () {
    Sleep(1000 * 5)
}

Test the sleep module:

Visualization Module to Build Trading Strategy - First Acquaintance

Backtesting results:

Visualization Module to Build Trading Strategy - First Acquaintance

  1. Print returns

Visualization Module to Build Trading Strategy - First Acquaintance

This module, just like the API function LogProfit on FMZ Quant Trading Platform, which prints the returns log and draws the return curve according to the input parameters automatically.

For example: Visualization Module to Build Trading Strategy - First Acquaintance The execution of the backtesting is shown in the figure below:

Visualization Module to Build Trading Strategy - First Acquaintance

The corresponding JavaScript strategy code is as follows:

function main () {
    LogProfit(1)
    Sleep(1000 * 5)
    LogProfit(2)
    Sleep(1000 * 5)
    LogProfit(3)
    Sleep(1000 * 5)
    LogProfit(2)
    Sleep(1000 * 5)
    LogProfit(5)
}

It can be spliced at any position where you want to output return information.

  1. Loop Visualization Module to Build Trading Strategy - First Acquaintance Loop module can wrap a series of spliced module combinations, allowing the module combinations to execute the loop.

Test: Visualization Module to Build Trading Strategy - First Acquaintance Backtesting results:

Visualization Module to Build Trading Strategy - First Acquaintance

We can see that the module combination consisting of “print returns” and “sleep” will be executed continuously after the loop module is wrapped.

  1. Loop execution every N seconds Visualization Module to Build Trading Strategy - First Acquaintance The usage of this module is basically the same as that of the loop module. The only difference is that the module has its own sleep. Visualization Module to Build Trading Strategy - First Acquaintance

  2. Precision processing Visualization Module to Build Trading Strategy - First Acquaintance This module can be used when the variable module or numerical value needs to control the precision. The numerical value of the input parameter part will be output as the numerical value of the specified decimal place according to the settings.

For example, precision processing is performed on the value 3.1415926535897.

Visualization Module to Build Trading Strategy - First Acquaintance

Backtesting display:

Visualization Module to Build Trading Strategy - First Acquaintance

  1. Clear Log Visualization Module to Build Trading Strategy - First Acquaintance

It is used to clear logs. Some logs can be retained according to the input parameters. As in the API document:

LogReset()
  1. Clear return log Visualization Module to Build Trading Strategy - First Acquaintance

It is used to clear the return log. Some logs can be retained according to the input parameters. As in the API document:

LogProfitReset()

The next are some frequently used tool modules

  1. Function module for obtaining a certain attribute of the market Visualization Module to Build Trading Strategy - First Acquaintance This tool module needs to be used together with the quotation module in the “Transaction Module Type”, as shown in the figure: Visualization Module to Build Trading Strategy - First Acquaintance Use the output information module to output the latest transaction price of the latest ticker market: Visualization Module to Build Trading Strategy - First Acquaintance Backtesting display: Visualization Module to Build Trading Strategy - First Acquaintance

Like JavaScript strategy code:

function main () {
    Log(exchange.GetTicker().Last)
}
  1. The module that obtains the attribute of a bar of K-line data Visualization Module to Build Trading Strategy - First Acquaintance This module also needs to be used together with the K-line data acquisition module in the “Transaction Module Type”.

First, we create a variable module named K-line. Visualization Module to Build Trading Strategy - First Acquaintance Then we obtain the K-line data, use the K-line data module to obtain it, and assign the value to the variable module: “K-line”. Visualization Module to Build Trading Strategy - First Acquaintance Then we use the list length module in the “List Module Type” to obtain the length of the K-line variable module, which is used to specify which bar on the K-line to obtain the data. Visualization Module to Build Trading Strategy - First Acquaintance Splice them together, as shown in the figure: Visualization Module to Build Trading Strategy - First Acquaintance

The timestamp of the last K-line bar is printed when the backtest runs. Visualization Module to Build Trading Strategy - First Acquaintance

  1. The module that obtains the data of an order in the order book Visualization Module to Build Trading Strategy - First Acquaintance It also needs to be used together with the “Get Depth Data module” in the “Transaction Module Type”. Visualization Module to Build Trading Strategy - First Acquaintance The index is set to 0 and the selling order is set to obtain the information of the selling one order.

Visualization Module to Build Trading Strategy - First Acquaintance

Like JavaScript strategy code:

function main () {
    Log(exchange.GetDepth().Asks[0])
}
  1. Module for obtaining an attribute in asset information Visualization Module to Build Trading Strategy - First Acquaintance This module needs to be used together with the module of obtaining asset information. Visualization Module to Build Trading Strategy - First Acquaintance For example: print the available currency of the current account Visualization Module to Build Trading Strategy - First Acquaintance Backtesting display: Visualization Module to Build Trading Strategy - First Acquaintance

Like JavaScript strategy code:

function main () {
    Log(exchange.GetAccount().Stocks)
}
  1. Module for obtaining an attribute in order data Visualization Module to Build Trading Strategy - First Acquaintance This module is used to obtain the value of an attribute in the order data, such as the price or quantity of selling one in the order book (example of No.13). Visualization Module to Build Trading Strategy - First Acquaintance

Backtesting results: Visualization Module to Build Trading Strategy - First Acquaintance

Like JavaScript strategy code:

function main () {
    Log(exchange.GetDepth().Asks[0].Price)
}

It can also be used to obtain an attribute in the order information returned by the “Query Order Details Module” (to be explained in the advanced chapter).

  1. The module to obtain the attributes of a position in the position information Visualization Module to Build Trading Strategy - First Acquaintance Similarly, it should be used together with the “Get Futures Position Module”. Note that the position data returned by the “Get Futures Position Module” is an array (list) that contains positions in different contracts and directions. Therefore, the index should be specified when using.

Having learned so much, let’s combine a hedging operation, that is, hedging both short-term and forward contracts.

We make a positive arbitrage hedge, that is, open a short position contract for the forward contract, and open a long position contract for the recent contract.

Visualization Module to Build Trading Strategy - First Acquaintance

Backtesting results:

Visualization Module to Build Trading Strategy - First Acquaintance

Examples of visualization strategies:

https://www.fmz.com/strategy/121404 https://www.fmz.com/strategy/129895 https://www.fmz.com/strategy/123904 https://www.fmz.com/strategy/122318 For more strategies, please refer to: https://www.fmz.com/square

Other articles in this series

-Visualization Module to Build Trading Strategies - In-depth (https://www.fmz.com/digest-topic/9509) -Visualization Module to Build Trading Strategy - Advanced Understanding (https://www.fmz.com/bbs-topic/9815)

The boring programming can be easily completed by building blocks. It’s very interesting to try!

相关推荐
更多内容