BakTst_Org is a backtesting system for quantitative transactions.

Overview

BakTst_Org

中文reademe:传送门

Introduction: BakTst_Org is a prototype of the backtesting system used for BTC quantitative trading.


mind Mapping This readme is mainly divided into the following parts:

  • What kind of person is suitable for studying BakTst_Org?
  • import library
  • BakTst_Org's framework and various modules of the framework
  • How to use BakTst_Org?
  • Extension
  • Question
  • Results map
  • Some ideas for the future
  • Thanks list

What kind of person is suitable for studying BakTst_Org?

BakTst_Org is just a prototype, so the rows of code is not large. It's about four hundred lines. But it also has all the features you need, such as: multi-process, simulation, a crawler that obtain trading data.

So it is suitable for these people:

  • Python enthusiast
  • Script developer
  • Financial enthusiasts
  • Quantify traders

Library to be imported

Talib, multiprocessing, pandas, json, numpy, time, requests

BakTst framework and introduction to each module of the framework

BakTst_Org mainly divides six modules:

  • craw (crawler module)
  • Feed (data acquisition module)
  • Strategy (strategy module)
  • Portfollio (position management module)
  • Execution (order execution module)
  • main function

craw

This module is a separate module, and the API called is the bittrex api, which is mainly used to obtain transaction data and then write to the txt file.

Api: https://api.bittrex.com/api/v1.1/public/getmarkethistory?market=usdt-btc If you want to obtain a transaction data of a currency, you only need to modify the last usdt-btc transaction pair. For example: 'usdt to ltc', you can modify it to usdt-ltc.

The time limit for getting is 60 requests per minute, so a time.sleep(1) is added.

The data that I obtained is divided into two files, one is the complete transaction data that includes details of each transaction, and the other is consisted of a time period information that includes the highest price, the lowest price, the opening price, the closing price, the transaction volume and the time.

For the format of the data, please checking the value of the two txt files in the ‘craw/’ path.

Feed

This module is used to transfer the transaction data and the initialized data into BakTst.

The initialized data includes these parameters:

  • data: The highest price, lowest price, opening price, closing price, time, and the transaction volume in a period of time. And the format is dataframe.
  • coin_number: The number of coins already owned by us.
  • principal: The principal already owned by us.

Strategy

This module is used to analyze the transaction data to predict the trend of price. Firstly it receives the transaction data from the Feed module. Secondly, it will analyze the transaction data through some function in Strategy module. Thirdly, it will sets buy_index (buy index) and sell_index (sell index). Lastly, it will transport the buy_index and the sell_index to Portfollio module.

The total structure of the Strategy module includes two parts. The one is 'Strategy.py' that is writed Strategic judgment, and the other one is 'Strategy_fun.py' file that writed two strategic functions, and a format conversion function.

Portfollio

This module is used to manage position. Although we have judged the buying and selling trend, we need to limit the position. For example, we can set a limiting that the proportion of the position must less than 0.5. So, this module plays a limiting role. Then, the opening and selling signals will be sent to the next one--Execution module.

There are the meaning of some parameters:

  • buy_amount and sell_amount: It is a fixed rate to trade. The fixed rate may not be same in the real situation, but we just use a software to trade.
  • trade_sigle: It is a trading signal. The ‘sell’ is for sale. The ‘buy’ is for purchase. The ‘None’ is for inaction. In the subsequent code, that is a judgment basis.
  • judge_position: It is standard to judge position, and the value is less than 1.

Execution

This module is used to execute an order to simulate the real situation about trading. And it will eventually return a total profit and loss. There are the meaning of some parameters:

  • tip: Handling fee.
  • buy_flap: The slippage of buying.
  • sell_flap: The slippage of selling.
  • buy_last_price and sell_last_price: the last price of trading.

Main function

This module is used to convert the data of the txt document into the data of the dataframe format and send it to the whole system. Finally, the system will return a final number of the coin and the number of the principal. Then, it will compares the initial price and final price to calculate profit and loss. There are the meaning of some parameters:

  • earn: earn.
  • lose: loss.
  • balance: no loss, no profit.

How to use BakTst_Org

  • Firstly, you need to collect data by using the craw.py file in the craw module.
  • Secondly, you need to run the BakTst_Org.py file to see the output.

Extension

  • Dynamic variable: Some values is fixed, such as principal, position and handling fee. But there are some values ​​that can be dynamically changed, such as slippage, single billing amount.
  • Function of the 'Strategy_fun.py' in Strategy module: I just wrote two functions, but you can add more.

Question

There are two questions that I met:

  • I have met a problem about naming coverage. The open is a function in python, and I use with open (addr , 'w') as w: already, so there was a mistake when I use 'open' to representative the 'open price'.
  • It is a problem acout Multi-process. I used the Multi-process pool. But when I add the method in class to the Multi-process pool, I found out that I can't call them. Finally, I can call these methods, but I need to run multiple processes on the outside of class.

Results map

result1 result2

Some ideas for the future

I published BakTst_Org, and everyone can reference from it. But if it is used to trade in the real quantitative transaction, it can't. I will develop a quantitative trading system that can be used to trade in the real quantitative transaction based on BakTst_Org.

Thanks list

  • Thanks to everyone in 慢雾区远不止狗币技术群, helped me solve some programming problems.
  • Thanks to greatshi. Greatshi,a master in the field of quantitative trading. He patiently answered some questions that I met. Thank you.
Autolookup GUI Plugin for Plover

Word Tray for Plover Word Tray is a GUI plugin that automatically looks up efficient outlines for words that start with the current input, much like a

Kathy 3 Jun 08, 2022
A powerful Sphinx changelog-generating extension.

What is Releases? Releases is a Python (2.7, 3.4+) compatible Sphinx (1.8+) extension designed to help you keep a source control friendly, merge frien

Jeff Forcier 166 Dec 29, 2022
The mitosheet package, trymito.io, and other public Mito code.

Mito Monorepo Mito is a spreadsheet that lives inside your JupyterLab notebooks. It allows you to edit Pandas dataframes like an Excel file, and gener

Mito 1.4k Dec 31, 2022
Resource hub for Obsidian resources.

Obsidian Community Vault Welcome! This is an experimental vault that is maintained by the Obsidian community. For best results we recommend downloadin

Obsidian Community 320 Jan 02, 2023
Data science Python notebooks: Deep learning (TensorFlow, Theano, Caffe, Keras), scikit-learn, Kaggle, big data (Spark, Hadoop MapReduce, HDFS), matplotlib, pandas, NumPy, SciPy, Python essentials, AWS, and various command lines.

Data science Python notebooks: Deep learning (TensorFlow, Theano, Caffe, Keras), scikit-learn, Kaggle, big data (Spark, Hadoop MapReduce, HDFS), matplotlib, pandas, NumPy, SciPy, Python essentials, A

Donne Martin 24.5k Jan 09, 2023
Visualizacao-dados-dell - Repositório com as atividades desenvolvidas no curso de Visualização de Dados

📚 Descrição Neste curso da Dell trabalhamos com a visualização de dados. 🖥️ Aulas 1.1 - Explorando conjuntos de dados 1.2 - Fundamentos de visualiza

Claudia dos Anjos 1 Dec 28, 2021
learn python in 100 days, a simple step could be follow from beginner to master of every aspect of python programming and project also include side project which you can use as demo project for your personal portfolio

learn python in 100 days, a simple step could be follow from beginner to master of every aspect of python programming and project also include side project which you can use as demo project for your

BDFD 6 Nov 05, 2022
Spin-off Notice: the modules and functions used by our research notebooks have been refactored into another repository

Fecon235 - Notebooks for financial economics. Keywords: Jupyter notebook pandas Federal Reserve FRED Ferbus GDP CPI PCE inflation unemployment wage income debt Case-Shiller housing asset portfolio eq

Adriano 825 Dec 27, 2022
API spec validator and OpenAPI document generator for Python web frameworks.

API spec validator and OpenAPI document generator for Python web frameworks.

1001001 249 Dec 22, 2022
Simple yet powerful CAD (Computer Aided Design) library, written with Python.

Py-MADCAD it's time to throw parametric softwares out ! Simple yet powerful CAD (Computer Aided Design) library, written with Python. Installation

jimy byerley 124 Jan 06, 2023
Loudchecker - Python script to check files for earrape

loudchecker python script to check files for earrape automatically installs depe

1 Jan 22, 2022
AiiDA plugin for the HyperQueue metascheduler.

aiida-hyperqueue WARNING: This plugin is still in heavy development. Expect bugs to pop up and the API to change. AiiDA plugin for the HyperQueue meta

AiiDA team 3 Jun 19, 2022
A fast time mocking alternative to freezegun that wraps libfaketime.

python-libfaketime: fast date/time mocking python-libfaketime is a wrapper of libfaketime for python. Some brief details: Linux and OS X, Pythons 3.5

Simon Weber 68 Jun 10, 2022
Course materials for: Geospatial Data Science

Course materials for: Geospatial Data Science These course materials cover the lectures for the course held for the first time in spring 2022 at IT Un

Michael Szell 266 Jan 02, 2023
My solutions to the Advent of Code 2021 problems in Go and Python 🎄

🎄 Advent of Code 2021 🎄 Summary Advent of Code is an annual Advent calendar of programming puzzles. This year I am doing it in Go and Python. Runnin

Orfeas Antoniou 16 Jun 16, 2022
The project that powers MDN.

Kuma Kuma is the platform that powers MDN (developer.mozilla.org) Development Code: https://github.com/mdn/kuma Issues: P1 Bugs (to be fixed ASAP) P2

MDN Web Docs 1.9k Dec 26, 2022
Sphinx theme for readthedocs.org

Read the Docs Sphinx Theme This Sphinx theme was designed to provide a great reader experience for documentation users on both desktop and mobile devi

Read the Docs 4.3k Dec 31, 2022
Numpy's Sphinx extensions

numpydoc -- Numpy's Sphinx extensions This package provides the numpydoc Sphinx extension for handling docstrings formatted according to the NumPy doc

NumPy 234 Dec 26, 2022
An open-source script written in python just for fun

Owersite Owersite is an open-source script written in python just for fun. It do

大きなペニスを持つ少年 7 Sep 21, 2022
A next-generation curated knowledge sharing platform for data scientists and other technical professions.

Knowledge Repo The Knowledge Repo project is focused on facilitating the sharing of knowledge between data scientists and other technical roles using

Airbnb 5.2k Dec 27, 2022