Code Monkey home page Code Monkey logo

abquant-data's Introduction

abquant

Description

A&B professional platform for quantitative finance. God is asking & bidding Me. ABQ.

abquant 分为三大模块 a) 数据获取 b) 策略回测 c) 模拟/实盘交易

abquant-data
开源项目
abquant-strategy
闭源项目,基于 zeromg/nanomsg
abquant-trade
xtrade 闭源项目

Note

[WIP] 开发中 …

ABQuant is an early developer preview, and is not suitable for general usage yet. Features and implementation are subject to change.

构建

作者本人是在 x86_64 Linux 4.19.105-1-MANJARO 上构建本项目,暂时不支持 Windows.
你需要安装好 clang++/llvm python pip conan cmake/qmake 等基础开发工具

cpp 依赖

ORM 层 treefrog-framework
git clone -b feature/withConan https://github.com/yssource/treefrog-framework.git
cd treefrog-framework && mkdir -v qbuild && cd qbuild
conan install .. --build missing
conan build ..
sudo make install
sudo ldconfig
DataFrame 层 DataFrame
git clone https://github.com/hosseinmoein/DataFrame.git
cd DataFrame && cmake -H. -Bbuild -GNinja
ninja -C build
sudo ninja -C build install
sudo ldconfig
abquant 核心应用层
git clone https://github.com/yssource/abquant-data.git
cd abquant-data && mkdir -v qbuild && cd qbuild
conan install .. --build missing --pr ../abquant.profile
conan build ..
sudo make install
sudo ldconfig

# binding
cd abquant-data && mkdir -v cbuild && cd cbuild
conan install .. --build missing --pr ../abquant.profile
conan build ..

# todo:: qbuild, cbuild 将来会直接放在 setup.py 中作为 ext_modules 完成。
# 用户只需 pip install -e .

python 依赖安装

pip install -r requirements-dev.txt
pip install -e .

环境变量

export ABQ_HOME=${PWD}
export ABQ_CXX_HOME="${ABQ_HOME}/cxx"
export LD_LIBRARY_PATH="${ABQ_HOME}/lib:${LD_LIBRARY_PATH}"
export PYTHONPATH="${ABQ_HOME}/lib:${PYTHONPATH}"

Usage

abquant config

# 当前项目根目录下,拷贝 config 文件夹
mkdir -pv ~/.config/abquant && cp -rfv $PWD/cxx/config ~/.config/abquant/

abquant 数据获取

  • python 层获取数据源,支持 mongodb
    # 保存所有数据
    # 但是不包含除权数据,除权数据不是经常更新,请手动 "abquant stock xdxr"
    abquant save base
    
    # 股票除权除息
    abquant stock xdxr
    abquant stock xdxr --add '["000001", "300001", "600001"]'
    
    # 保存所有股票日线,日线指数
    abquant stock day
    abquant stock day --add '["000001", "300001", "600001"]'
    
    # 保存所有股票分钟线,分钟指数
    # Default 保存所有频率 (1min, 5min, 15min, 30min, 60min)
    abquant stock min
    abquant stock min --add '["000001", "300001", "600001"]'
    
    # 保存股票分钟线,分钟指数不同频率数据 (1min, 5min, 15min, 30min, 60min)
    # 1min 一分钟
    abquant stock min "1min"
    abquant stock min -f '["1min"]' --add '["000001", "300001", "600001"]'
    # 5min 五分钟
    abquant stock min -f '["5min"]'
    abquant stock min -f '["5min"]' --add '["000001", "300001", "600001"]'
    # ...
    # 1min 一分钟和 5min 五分钟
    abquant stock min -f '["1min", "5min"]'
    abquant stock min -f '["1min", "5min"]' --add '["000001", "300001", "600001"]'
    # ...
        
    # 查看保存数据后的错误信息
    bat ~/.config/abquant/log/error_codes.json
        
    {"Stock_index_day": ["395005"], "Stock_index_min": ["395041", "395005"], "Stock_stock_min": ["300822", "603949", "603353", "300819", "300821", "002976", "688051"], "Stock_xdxr": ["002976", "603949", "300822", "688051", "603353"]}
        
    # 如果在保存数据后,发现数据错误,可以使用
    abquant stock day --add '["395005"]'
    abquant stock min --add '["395041", "395005", "300822", "603949", "603353", "300819", "300821", "002976", "688051"]'
    abquant stock xdxr --add '["002976", "603949", "300822", "688051", "603353"]'
    
    # 注意:这些数据错误可能是退市,已经不存在的数据。也有可能是网络原因,数据不完整,你需要具体分析。
    # 在下一次保存数据时,最好先
    echo "" 1> ~/.config/abquant/log/error_codes.json
        

abquant 数据使用

#include <chrono>
#include "abquant/actions/abquant.hpp"
#include "abquant/actions/stockmin.hpp"
#include "abquant/actions/utils.hpp"

using namespace abq;

int main(int argc, char* argv[])
{
    // abq entry_point
    Abquant::start();

    // QStringList codes = {"000001", "000002", "000003"};
    QStringList codes = {"000001"};
    const char* start = "2017-01-01";
    const char* end   = "2019-12-01";

    MIN_FREQ freq = MIN_FREQ::FIVE;
    StockMinAction sma(codes, start, end, freq);
    int N      = 10;
    auto begin = std::chrono::high_resolution_clock::now();
    for (int i = 0; i < N; ++i) {
        // 分钟前复权
        sma.toFq(FQ_TYPE::PRE);
        // 分钟后复权
        // sma.toFq(FQ_TYPE::POST);
    }
    auto finish_ = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> elapsed = finish_ - begin;
    qDebug() << "Elapsed time: " << elapsed.count() << " s\n";

    return 0;
}

binding 层

python ./bind11/test/test_plot.py

plotting

./screenshot/abqstockday.png

开发初衷

作者本人专业是理论物理,工作经验则是程序开发,对金融知识知之甚少,一点点股票交易经 验。很偶然在网上了解到了量化交易,觉得可以利用上以前的知识和经验,于是乎喜欢上 了量化交易。

交易三部曲,a) 数据获取 b) 策略回测 c) 模拟/实盘交易
市面上开源的 a,b,c 项目大部分都是 python 开发,但是在实践过程中性能都不理想,于是想 到站在巨人肩上利用 C++ 造轮子。核心模块 C++,通过中间层 binding 交给用户 python 层。

感谢

  • QUANTAXIS abquant-data 数据获取借鉴了很多 pytdx/quantaxis 代码,并兼容 quantaxis 数据库

打赏

欢迎请作者喝杯咖啡 👍

微信支付宝
./screenshot/jimmy.wechat.png./screenshot/jimmy.alipay.png

LICENSE

Copyright (c) 2020-2016 Jimmy M. Gong
All rights reserved.

除非遵守当前许可,否则不得使用本软件。

非商业用途(非商业用途指个人出于非商业目的使用本软件,或者高校、研究所等非营利机构出于教育、科研等目的使用本软件):

遵守 GPL3LGPL3

除非法律有要求或以书面形式达成协议,否则本软件分发时需保持当前许可“原样”不变,且不得附加任何条件。

商业用途(商业用途指个人出于任何商业目的使用本软件,或者法人或其他组织出于任何目的使用本软件):

未经原作者授权,任何个人不得出于任何商业目的使用本软件(包括但不限于向第三方 提供、销售、出租、出借、转让本软件、本软件的衍生产品、引用或借鉴了本软件功能 或源代码的产品或服务),任何法人或其他组织不得出于任何目的使用本软件,否则原 作者有权追究相应的知识产权侵权责任。
在此前提下,对本软件的使用同样需要遵守 GPL3LGPL3 许可, GPL3LGPL3 许可与本 许可冲突之处,以本许可为准。

详细的授权流程,请联系 [email protected] 获取。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.