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.
You might also like...
Portfolio Optimization and Quantitative Strategic Asset Allocation in Python
Portfolio Optimization and Quantitative Strategic Asset Allocation in Python

Riskfolio-Lib Quantitative Strategic Asset Allocation, Easy for Everyone. Description Riskfolio-Lib is a library for making quantitative strategic ass

BisQue is a web-based platform designed to provide researchers with organizational and quantitative analysis tools for 5D image data. Users can extend BisQue by implementing containerized ML workflows.
BisQue is a web-based platform designed to provide researchers with organizational and quantitative analysis tools for 5D image data. Users can extend BisQue by implementing containerized ML workflows.

Overview BisQue is a web-based platform specifically designed to provide researchers with organizational and quantitative analysis tools for up to 5D

bt - flexible backtesting for Python

bt - Flexible Backtesting for Python bt is currently in alpha stage - if you find a bug, please submit an issue. Read the docs here: http://pmorissett

Python library for backtesting trading strategies & analyzing financial markets (formerly pythalesians)
Python library for backtesting trading strategies & analyzing financial markets (formerly pythalesians)

finmarketpy (formerly pythalesians) finmarketpy is a Python based library that enables you to analyze market data and also to backtest trading strateg

Python Backtesting library for trading strategies

backtrader Yahoo API Note: [2018-11-16] After some testing it would seem that data downloads can be again relied upon over the web interface (or API v

Trading and Backtesting environment for training reinforcement learning agent or simple rule base algo.
Trading and Backtesting environment for training reinforcement learning agent or simple rule base algo.

TradingGym TradingGym is a toolkit for training and backtesting the reinforcement learning algorithms. This was inspired by OpenAI Gym and imitated th

Scalable, event-driven, deep-learning-friendly backtesting library
Scalable, event-driven, deep-learning-friendly backtesting library

...Minimizing the mean square error on future experience. - Richard S. Sutton BTGym Scalable event-driven RL-friendly backtesting library. Build on

Trading environnement for RL agents, backtesting and training.

TradzQAI Trading environnement for RL agents, backtesting and training. Live session with coinbasepro-python is finaly arrived ! Available sessions: L

This is a simple backtesting framework to help you test your crypto currency trading. It includes a way to download and store historical crypto data and to execute a trading strategy.

You can use this simple crypto backtesting script to ensure your trading strategy is successful Minimal setup required and works well with static TP a

Multi-asset backtesting framework. An intuitive API lets analysts try out their strategies right away
Multi-asset backtesting framework. An intuitive API lets analysts try out their strategies right away

Multi-asset backtesting framework. An intuitive API lets analysts try out their strategies right away. Fast execution of profit-take/loss-cut orders is built-in. Seamless with Pandas.

A script to parse and display buy_tag and sell_reason for freqtrade backtesting trades

freqtrade-buyreasons A script to parse and display buy_tag and sell_reason for freqtrade backtesting trades Usage Copy the buy_reasons.py script into

Backtesting an algorithmic trading strategy using Machine Learning and Sentiment Analysis.
Backtesting an algorithmic trading strategy using Machine Learning and Sentiment Analysis.

Trading Tesla with Machine Learning and Sentiment Analysis An interactive program to train a Random Forest Classifier to predict Tesla daily prices us

A competition for forecasting electricity demand at the country-level using a standard backtesting framework

A competition for forecasting electricity demand at the country-level using a standard backtesting framework

Simple wordle clone + solver + backtesting

Wordle clone + solver + backtesting I created something. Or rather, I found about this game last week and decided that one challenge a day wasn't goin

Certis - Certis, A High-Quality Backtesting Engine

Certis - Backtesting For y'all Certis is a powerful, lightweight, simple backtes

A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.
A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.

AutoTrader AutoTrader is Python-based platform intended to help in the development, optimisation and deployment of automated trading systems. From sim

Easy-to-use data handling for SQL data stores with support for implicit table creation, bulk loading, and transactions.

dataset: databases for lazy people In short, dataset makes reading and writing data in databases as simple as reading and writing JSON files. Read the

Use an air-gapped Raspberry Pi Zero to sign for Bitcoin transactions! (and do other cool stuff)
Use an air-gapped Raspberry Pi Zero to sign for Bitcoin transactions! (and do other cool stuff)

Hello World! Build your own offline, airgapped Bitcoin transaction signing device for less than $35! Also generate seed word 24 or generate a seed phr

Easy-to-use data handling for SQL data stores with support for implicit table creation, bulk loading, and transactions.

dataset: databases for lazy people In short, dataset makes reading and writing data in databases as simple as reading and writing JSON files. Read the

Owner
null
Software engineering course project. Secondhand trading system.

PigeonSale Software engineering course project. Secondhand trading system. Documentation API doumenatation: list of APIs Backend documentation: notes

Harry Lee 1 Sep 1, 2022
Build AGNOS, the operating system for your comma three

agnos-builder This is the tool to build AGNOS, our Ubuntu based OS. AGNOS runs on the comma three devkit. NOTE: the edk2_tici and agnos-firmare submod

comma.ai 21 Dec 24, 2022
Obmovies - A short guide on setting up the system and environment dependencies required for ob's Movies database

Obmovies - A short guide on setting up the system and environment dependencies required for ob's Movies database

null 1 Jan 4, 2022
Generates, filters, parses, and cleans data regarding the financial disclosures of judges in the American Judicial System

This repository contains code that gets data regarding financial disclosures from the Court Listener API main.py: contains driver code that interacts

Ali Rastegar 2 Aug 6, 2022
graphical orbitational simulation of solar system planets with real values and physics implemented so you get a nice elliptical orbits. you can change timestamp value or scale from source code idc.

solarSystemOrbitalSimulation graphical orbitational simulation of solar system planets with real values and physics implemented so you get a nice elli

Mega 3 Mar 3, 2022
Mutual Fund Recommender System. Tailor for fund transactions.

Explainable Mutual Fund Recommendation Data Please see 'DATA_DESCRIPTION.md' for mode detail. Recommender System Methods Baseline Collabarative Fiilte

JHJu 2 May 19, 2022
High-performance TensorFlow library for quantitative finance.

TF Quant Finance: TensorFlow based Quant Finance Library Table of contents Introduction Installation TensorFlow training Development roadmap Examples

Google 3.5k Jan 1, 2023
MRQy is a quality assurance and checking tool for quantitative assessment of magnetic resonance imaging (MRI) data.

Front-end View Backend View Table of Contents Description Prerequisites Running Basic Information Measurements User Interface Feedback and usage Descr

Center for Computational Imaging and Personalized Diagnostics 58 Dec 2, 2022
Empyrial is a Python-based open-source quantitative investment library dedicated to financial institutions and retail investors

By Investors, For Investors. Want to read this in Chinese? Click here Empyrial is a Python-based open-source quantitative investment library dedicated

Santosh 640 Dec 31, 2022