FMZ releases Python native search engine

Author: The Little Dream, Created: 2018-04-13 09:48:31, Updated: 2019-08-19 16:30:05

FMZ releases Python native search engine

FMZ backtest engine python package FMZ retrieval engine python library support python2 and python3, support Windows, Linux, Mac Support for python2 and python3, support for windows systems, Linux systems, Apple Mac OS systems

install

Installed In the command line, enter the following command:

pip install https://github.com/fmzquant/backtest_python/archive/master.zip
  • Please note: When the Apple Mac system is installed, if there are security restrictions, the pip command is preceded by the sudo command, and the entire installation command will require the input of the system password.

simple example

A simple example

'''backtest
start: 2018-02-19 00:00:00
end: 2018-03-22 12:00:00
period: 15m
exchanges: [{"eid":"OKEX","currency":"LTC_BTC","balance":3,"stocks":0}]
'''
from fmz import *
task = VCtx(__doc__) # initialize backtest engine from __doc__
print exchange.GetAccount()
print exchange.GetTicker()
print task.Join() # print backtest result

The config string can be generated automatically by saving the backtest configuration in the strategy edit page. Configuration strings can be automatically generated by saving retrieval configurations in the policy editing interface

meta

documentation

API documentation: (i.e. documentation that calls functions such as GetAccount in the instance)

The Python code has a simple annotation:

'''backtest
start: 2018-02-19 00:00:00
end: 2018-03-22 12:00:00
period: 15m
exchanges: [{"eid":"OKEX","currency":"LTC_BTC","balance":3,"stocks":0}]
'''
from fmz import *                                                  # 引用 发明者量化 库
task = VCtx(__doc__) # initialize backtest engine from __doc__     # 调用 VCtx 函数 根据 __doc__初始化。
print exchange.GetAccount()                                        # 测试 GetAccount 函数,并打印 回测系统测试交易所账户信息
print exchange.GetTicker()                                         # 测试 GetTicker 函数,并打印 回测系统 行情信息
print task.Join() # print backtest result                          # 调用 初始化后的 task 对象 显示回测结果
  • __doc__

    是两个下划线。__doc__用来访问模块,类声明或者函数的声明中第一个未被赋值的字符串,
    可以是被""" ""","" "",' ',括起来的,作用就是把 代码中 '''backtest   ...  ''' 的回测配置信息  传入 VCtx 类构造函数构造对象。
    
  • Modify the test code to see how the specific Log, GetTicker functions are called.

    # coding=UTF-8
    
    '''backtest
    start: 2018-02-19 00:00:00
    end: 2018-03-22 12:00:00
    period: 15m
    exchanges: [{"eid":"OKEX","currency":"LTC_BTC","balance":3,"stocks":0}]
    '''
    
    from fmz import *                                                # 引用 发明者量化 库
    task = VCtx(__doc__) # initialize backtest engine from __doc__     # 调用 VCtx 函数 根据 __doc__初始化。
    print exchange.GetAccount()                                        # 测试 GetAccount 函数,并打印 回测系统测试交易所账户信息
    Log("\n 调用Log")
    Log("调用 exchange.GetTicker() : ", exchange.GetTicker())
    print task.Join() # print backtest result                          # 调用 初始化后的 task 对象 显示回测结果
    
    • Print exchange.GetAccount () code output is displayed as:
    {'Balance': 3.0, 'Stocks': 0.0, 'FrozenBalance': 0.0, 'FrozenStocks': 0.0}
    
    • Log (("\nCall Log") 、 Log (("Call exchange.GetTicker() ":), exchange.GetTicker())

    The output content is in the print task.Join () output data structure:

    {
        "Chart": {
     	   "Cfg": "",
     	   "Datas": []
        },
        "Elapsed": 42000000,
        "Finished": true,
        "Indicators": {},
        "LoadBytes": 441845,
        "LoadElapsed": 24000000,
        "LogsCount": 2,
        "Profit": 0.0,
        "ProfitLogs": [],
        "Progress": 100.0,
        "RuntimeLogs": [                                                  # 调用输出内容在此处
     	   [1, 1518969600200, 5, "", 0, 0.0, 0.0, "\n 调用Log", "", ""],
     	   [2, 1518969600400, 5, "", 0, 0.0, 0.0, "调用 exchange.GetTicker() :  {'Sell': 0.02113476, 'Volume': 519.6953, 'Buy': 0.02113474, 'Last': 0.02113475, 'High': 0.02113476, 'Time': 1518969600000L, 'Low': 0.02113474}", "", ""]
        ],
        "Snapshort": [{
     	   "Balance": 3.0,
     	   "BaseCurrency": "LTC",
     	   "Commission": 0.0,
     	   "FrozenBalance": 0.0,
     	   "FrozenStocks": 0.0,
     	   "Id": "OKEX",
     	   "QuoteCurrency": "BTC",
     	   "Stocks": 0.0,
     	   "Symbols": {
     		   "LTC_BTC_OKEX": {
     			   "Last": 0.01893785
     		   }
     	   },
     	   "TradeStatus": {}
        }],
        "Status": "",
        "Task": {
     	   "Args": null,
     	   "Exchanges": [{
     		   "Balance": 3,
     		   "BaseCurrency": "LTC",
     		   "BasePeriod": 300000,
     		   "BasePrecision": 4,
     		   "DepthDeep": 5,
     		   "FaultTolerant": 0,
     		   "FeeDenominator": 5,
     		   "FeeMaker": 75,
     		   "FeeMin": 0,
     		   "FeeTaker": 80,
     		   "Id": "OKEX",
     		   "Label": "OKEX",
     		   "PriceTick": 1e-08,
     		   "QuoteCurrency": "BTC",
     		   "QuotePrecision": 8,
     		   "SlipPoint": 0,
     		   "Stocks": 0
     	   }],
     	   "Options": {
     		   "DataServer": "q.botvs.net",
     		   "MaxChartLogs": 800,
     		   "MaxProfitLogs": 800,
     		   "MaxRuntimeLogs": 800,
     		   "NetDelay": 200,
     		   "Period": 900000,
     		   "RetFlags": 189,
     		   "SnapshortPeriod": 300000,
     		   "TimeBegin": 1518969600,
     		   "TimeEnd": 1521691200,
     		   "UpdatePeriod": 5000
     	   }
        },
        "TaskStatus": 1,
        "Time": 1521691200000
    }
    
  • How to use a policy to retry in a local retry engine

# !/usr/local/bin/python
# -*- coding: UTF-8 -*-
'''backtest
start: 2018-02-19 00:00:00
end: 2018-03-22 12:00:00
period: 15m
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD","balance":10000,"stocks":3}]
'''
import sys
sys.path.append("/usr/local/lib/python2.7/site-packages")    # 测试时添加了路径,如不需要可以删除

from fmz import *
import math
import talib

task = VCtx(__doc__) # initialize backtest engine from __doc__

# ------------------------------ 策略部分开始 --------------------------
print exchange.GetAccount()     # 调用一些接口,打印其返回值。
print exchange.GetTicker()

def adjustFloat(v):             # 策略中自定义的函数
    v = math.floor(v * 1000)
    return v / 1000

def onTick(e):
    Log("onTick")
    # ....

#
# ...
# 
# 此处省略 自定义函数实现等代码。

def main():
    InitAccount = GetAccount()
    
    while True:
        onTick(exchange)
        Sleep(1000)
# ------------------------------ 策略部分结束 --------------------------

try:
    main()                     # 回测结束时会 raise EOFError() 抛出异常,来停止回测的循环。所以要对这个异常处理,在检测到抛出的异常后调用 task.Join() 打印回测结果。
except:
    print task.Join()          # print backtest result  , 打印回测结果。

More

alextao/Users/taoxing/opt/anaconda3/envs/ai4f/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py:793: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning. Warnings.warn ((FSADeprecationWarning)) Traceback (most recent call last): File "/Users/taoxing/Desktop/quant/trading_api_study/fmz/fmz_extend_api_demo/app.py", line 152, in is also included. db.create_all (()) File "/Users/taoxing/opt/anaconda3/envs/ai4f/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 963, in create_all self._execute_for_all_tables (app, bind, 'create_all') File "/Users/taoxing/opt/anaconda3/envs/ai4f/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 955, in _execute_for_all_tables This is a list of files that are available for use with the.py file op ((bind=self.get_engine ((app, bind), **extra)) File "/Users/taoxing/opt/anaconda3/envs/ai4f/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 896, in get_engine return connector.get_engine File "/Users/taoxing/opt/anaconda3/envs/ai4f/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 556, in get_engine I've been trying to find a way to get rid of this problem. File "/Users/taoxing/opt/anaconda3/envs/ai4f/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 861, in apply_driver_hacks This is a list of all the files in the file "/Users/taoxing" If you are using the OS.path.join app.root_path, info.database AttributeError: can't set attribute Where is the error, ask God for guidance!!!

guanyuwanglei 我想运行实盘机器人,添加Wex.app交易所相当于实盘模拟交易是吧?谢谢

guanyuwangleiBut there's only one bit of real-disc retrieval data, and what other settings can be optimized to get more real-disc data? /upload/asset/105f604eaceb0d3928a90.png /upload/asset/1066714d9a32c82eab7f1.png

guanyuwangleiHi, I want to use the token cash husd/usdt trading pair, I tried exchange.IO (("currency", "HUSD_USDT"), exchange.IO (("currency", "HUSD/USDT"), exchange.IO (("currency", "HUSDUSDT"), not run exit or variety subscription failed, please what is the correct spelling?

Every day is a soft dayI don't understand how to visualize the results of this test.

guanyuwangleiPlease, on windows system, exchange can't find the solution, thank you

woshiyituoshiWith relatively few pairs currently supported by the retesting system, does this open source project allow its developers to add some pairs?

1058715329When can local parameter optimization be supported?

A leaf of knowledge@ChiloChilo Dream Thank you. Did you have a Python 3 template? I downloaded the fmz library, but I got an error when I tried to use it, I couldn't find the package.

weisHow to set up Tick mode? By default it looks like you're using an analog Tick, how to switch to a real Tick

sxiaojianOr not, where should the main function of a policy be in this example?

sxiaojianIs it possible to retest only with LTC_BTC? I switched to the BTC_USDT program and got an error

teddyIs print exchange.GetTicker written as print (exchange.GetTicker)) in Python 3?

yxybyqThere is no problem with the platform retargeting, local retargeting often gives errors.

liputIn fmz, the main function is written by the user, and most policies are written by the user while True, which is then called in a loop. However, using Python's native retrieval engine, while True keeps the program running, cannot stop running at the start and end times specified by __doc__, and gives the output of Log. What should be done? Also, I see on other quantification platforms that generally only specified functions are written by the developer and then called back by the platform. fmz allows direct writing of the main input, is there any design or architectural advantage or consideration?

liputThe interactive input variables in the code, how do you write them in __doc__, or input them as parameters?

liputThe code has been changed to fmz, and the example code in the documentation needs to be renamed to fmz.

YesYesThe main (()) is normal. In a class, call exchange will return errors, why? File "D:/workspace/strategy/strategy_001.py", line 101, in main account = self._exchange.GetAccount (()) File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\botvs.py", line 716, in GetAccount This is a list of all the different ways to get started. EOF ((() File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\botvs.py", line 569, in the EOF raise EOFError ((()

topscienWhat's this thing for?

LizzaI'm not sure how to use it, does this local retargeting also need to communicate with the botvs platform?

The Little DreamTry using the latest fmz package.

The Little DreamThe host is free to use, but a one-key deployment is an automatic rental of Ali Cloud's servers at the cost of the server.

guanyuwangleiThe obvious one is that the custodian pays, the robot running the wexapp can choose to test it, or it can choose to trade on a real exchange, right?

The Little DreamA deployment host, which is deployed on an Ali Cloud server, is paid and will be charged from your account balance. The bot runs only on the wexApp analog drive, the bot fee is not charged, and the deployment host server fee is unrelated.

guanyuwangleiThat is, one key deploys the server, you can choose WexApp, the robot and the analog exchange, and test the simulation effect, right?

The Little DreamThe key to deploying a rental server is another additional charge. The robot's real disk charge has nothing to do with the wexApp analog drive, just that the robot runs for free (the digital currency robot will charge for any non-wexApp analog drive object added).

guanyuwangleiOne-click rental custodian, use the wexApp exchange free of charge? /upload/asset/1066e4b56fa103356dbc1.png

The Little DreamWexApp is an FMZ analogue, free of charge.

The Little DreamI'm not being polite.

The Little DreamThe real disk level retrieval data is relatively large, and the setting on the graph is already optimal.

guanyuwangleiInstead of the most recent timeframe, set it to ok trading pair, exchange.SetCurrency (("BTC_USDT") can be real, thank you very much.

The Little DreamTry switching to the most recent time period.

guanyuwanglei/upload/asset/1063627010637fee333ad.png This is a list of all the different ways Upload/asset is credited in the database. This is how to set up exchange.SetCurrency in the code (("BTC_USDT") But the total suggestion of the subscription failed BTC_USDT_OKEX button or nothing shows, immediately exit

guanyuwangleiThank you.

The Little DreamBoth the real-time, platform-line and local retrieval engines use data from the FMZ data center, providing a limited amount of transaction pairs, not all pairs.

guanyuwangleiThe real deal is getting this deal, right?

The Little DreamThe retesting system does not currently have data on this transaction pair.

The Little DreamThe results of the retest are in the form of data, and if you want to visualize them, you can write your own code to analyze them. If not, you can use an online retest system.

guanyuwangleiA5: = MA ((C,5); A10: = MA (C,10); angle: IF (CROSS) (A5, A10), ATAN (A5/REF) (A5, 1) -1) *100) - ATAN (A10/REF) (A10, 1) -1) *100), 0*180/3.1416; So if you find this formula, you don't know how to implement REF.

The Little DreamThis should be calculated according to the need, in the strategy, the formula can be searched in Baidu and found.

guanyuwangleiCan you tell me how to calculate macd gold fork \ dead fork angle, is there a formula?

guanyuwangleiPlease, import statsmodels in the policy editor is invalid, please where can I import a third-party library? I can import in pycharm, but how do I import in the editor?

The Little DreamThis is the start time of the fixed K-line, which can be synthesized with an hourly K-line if a day K-line starting from zero is needed.

guanyuwangleiCan you please tell me if the closing time in the code and the closing time in the review is 8:00 am Beijing time? If the closing time is not 8:00 am, please ask how to set it, thank you /upload/asset/1067eabe09e92d1610d71.png

The Little DreamYou can find some examples of strategies on Strategy Square, and if you can understand them all, you can start writing some simple strategies by hand.

guanyuwangleiPlease, I've finished reading the basic material, the FMZ how to use, the API documentation, should I look at that knowledge next?

The Little DreamI'm not being polite.

guanyuwangleiThank you.

The Little DreamThis can be run directly from the command line.

guanyuwangleiThis code I'm running in a.py file that needs to be imported into ccxt, otherwise exchange can't recognize it. The Python Consle editor can run normally.

The Little DreamThe code above is a direct command to run a Python program.

guanyuwanglei/upload/asset/106d6ff1919bdac419875.png This is a list of all the different ways Upload/asset/106d6ff1919bdac419875.png is credited in the database. I'm trying to figure out how to import the ccxt from the exchange, but the fmz is using the ccxt?

The Little DreamI've just tested this: File name is testBackTest What's up? from fmz import * task = VCtx ((''' backtest Start: 2018-02-19 00:00:00 This is the latest version of the game. end: 2018-03-22 12:00:00 This is the latest version of the app. period: 15m The following is a list of exchanges: [{"eid":"OKEX","currency":"LTC_BTC","balance":3,"stocks":0}] ''') # create backtest print ((exchange.GetAccount)) Print (exchange.GetTicker) is the most common type of print. What's the matter? /upload/asset/16bea6055e58a9ef7d5c.png This is a list of all the different ways Bea6055e58a9ef7d5c.png is credited in the database.

The Little DreamI've just downloaded the latest version of the fmz python package.

guanyuwanglei/upload/asset/1068d63bc6203599fc1c8.png This is a list of all the different ways Upload/Asset is credited in the database. Modified initialization, but exchange, log still not recognized

The Little DreamWhat's up? from fmz import * task = VCtx ((''' backtest Start: 2018-02-19 00:00:00 This is the latest version of the game. end: 2018-03-22 12:00:00 This is the latest version of the app. period: 15m The following is a list of exchanges: [{"eid":"OKEX","currency":"LTC_BTC","balance":3,"stocks":0}] ''') # Creating a feedback environment What's up? Initialize this as if you were configuring the exchange, trading pair, etc. information when you review online.

guanyuwangleiI've been trying to get a hold of you for a while now. Exchange is not recognized, already installed in Python fmz package

The Little DreamThe following is a screenshot of the specific error report.

The Little DreamThis is temporarily not possible because the retest data is obtained from FMZ. However, the code is open source and can be modified and replaced at will.

The Little DreamWhat's up? /* backtest Start: 2019-09-21 00:00:00 This is the latest version of the game End: 2019-10-20 00:00:00 This is the end of the story. period: 1h The following is a list of exchanges: [{"eid:"Bitfinex","currency:"BTC_USD"}] mode: 1 */ What's up? By using the ``mode`` setting in the configuration information, you can set it on the retrieval page and then directly save the retrieval setting on the policy edit page to access the configuration information string.

PosterioriThe same question?

chujiuRight.

xenideThe top

The Little DreamWell, this recording is currently not supported.

A leaf of knowledgeGood, thank you.

The Little DreamI found a problem, and I'm working on it.

A leaf of knowledgeYes, mac os 10.14.4 is the best.

The Little DreamIs your operating system Mac OSX?

A leaf of knowledgeI'm using conda to manage the python version, and I've confirmed that I've downloaded the python version of fmz, which is also available locally. But I looked on the website and found that it supports python3, but when I tried it, I had this problem. Did I write the code wrong?

The Little DreamIf you have multiple versions of Python, check where this package is installed.

The Little DreamThe post has been updated, you can check the example at the end of the post.

The Little DreamThe main function is written correctly, and the call is done.

sxiaojian https://github.com/fmzquant/backtest_python/issues/4,看看这个有没有帮助

The Little DreamThe wrong information, in particular, can be seen in the screenshot.

sxiaojianThe example code is changed to BTC_USDT and it's wrong.

The Little DreamThis depends on which exchange you choose to review.

The Little DreamTo see more specifically, the error message is in the wrong place.

The Little DreamFMZ uses a consultation architecture, which gives a little more control over the process and more flexibility in writing policies.

The Little Dream'' backtested Start: 2018-02-19 00:00:00 This is the latest version of the game. End: 2018-03-22 12:00:00 This is my last post. period: 15m The following is a list of exchanges: [{"eid:"OKEX","currency":"LTC_BTC","balance":3,"stocks":0}] '" These are:

The Little DreamI'm not sure what you mean.

The Little DreamFile Start Loading This simulated account configuration, if it is written in the class, is not loaded.

YesYesThis configuration should be correct. Why can't I write a class reference?

YesYesDo you want to check the account data, the lines below? There is a normal reference in the global function main. But I made a mistake in class. '' backtested Start: 2018-02-19 00:00:00 This is the latest version of the game. End: 2018-03-22 12:00:00 This is my last post. period: 15m The following is a list of exchanges: [{"eid:"OKEX","currency":"LTC_BTC","balance":3,"stocks":0}] '" from botvs import * task = VCtx ((__doc__) # initialize backtest engine from __doc__

The Little DreamWhat's up? def GetAccount ((self): r = _ACCOUNT (()) ret = self.lib.api_Exchange_GetAccount ((self.ctx, self.idx, ctypes.byref))) If ret == API_ERR_SUCCESS: If ret == If ret == If ret == If ret == If ret == If ret == If ret == If ret == If ret == If ret == If ret == return r.toObj (()) If you have a problem with this, please contact us. return None EOF ((() What's up? Looking at the code below, it looks like api_Exchange_GetAccount. This is an interface for a DLL, and you have an error message that says no return, call success or call failure, and then you run EOF.

The Little DreamThis is a Python library that allows the local Python to run the re-test policy.

The Little DreamThere will be communication, when the retest is requested, but the retest system is running locally. What's up? '' backtested Start: 2018-02-19 00:00:00 This is the latest version of the game. end: 2018-03-22 12:00:00 This is the latest version of the app. period: 15m The following is a list of exchanges: [{"eid":"OKEX","currency":"LTC_BTC","balance":3,"stocks":0}] '" from botvs import * task = VCtx ((__doc__) # initialize backtest engine from __doc__ Print exchange.GetAccount Print exchange.GetTicker is a print task.Join ((() # print backtest result What's up? The code is similar to a policy, where the retrieval system is wrapped in a library, and the test calls the retrieval system function at run time. The above '' 'backtest... '' is the backtest parameter setting, which can be generated in the BotVS policy backtest page.