Convert Figma logo to code with AI

bbfamily logoabu

阿布量化交易系统(股票,期权,期货,比特币,机器学习) 基于python的开源量化交易,量化投资架构

11,801
3,734
11,801
3

Top Related Projects

9,713

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)

15,357

Qlib is an AI-oriented quantitative investment platform that aims to realize the potential, empower research, and create value using AI technologies in quantitative investment, from exploring ideas to implementing productions. Qlib supports diverse machine learning modeling paradigms. including supervised learning, market dynamics modeling, and RL.

An Algorithmic Trading Library for Crypto-Assets in Python

13,247

Download market data from Yahoo! Finance's API

Extract data from a wide range of Internet sources into a pandas DataFrame.

17,609

Zipline, a Pythonic Algorithmic Trading Library

Quick Overview

Abu is an open-source quantitative trading system developed in Python. It provides a comprehensive set of tools for algorithmic trading, including data acquisition, strategy development, backtesting, and live trading capabilities. The project aims to offer a flexible and extensible platform for traders and researchers to develop and test trading strategies.

Pros

  • Comprehensive trading ecosystem with support for multiple markets and asset types
  • Extensive documentation and examples to help users get started
  • Active development and community support
  • Integration with popular data sources and brokers

Cons

  • Steep learning curve for beginners in quantitative trading
  • Limited support for non-Chinese markets and exchanges
  • Requires significant computational resources for large-scale backtesting
  • Some documentation and comments are in Chinese, which may be challenging for non-Chinese speakers

Code Examples

  1. Creating a simple moving average crossover strategy:
from abupy import AbuFactorBuyXd, AbuFactorSellXd, AbuFactorAtrNStop
from abupy import AbuPickTimeWorker

class MACrossStrategy(AbuFactorBuyXd):
    def _init_self(self, **kwargs):
        self.short_window = kwargs.pop('short_window', 5)
        self.long_window = kwargs.pop('long_window', 20)

    def fit_day(self, today):
        if len(self.kl_pd) < self.long_window:
            return None
        
        short_ma = self.kl_pd['close'].rolling(window=self.short_window).mean()
        long_ma = self.kl_pd['close'].rolling(window=self.long_window).mean()
        
        if short_ma.iloc[-1] > long_ma.iloc[-1] and short_ma.iloc[-2] <= long_ma.iloc[-2]:
            return self.buy_tomorrow()
        return None

buy_factors = [MACrossStrategy(short_window=5, long_window=20)]
sell_factors = [AbuFactorSellXd()]
stop_loss_factors = [AbuFactorAtrNStop()]

worker = AbuPickTimeWorker(start='2018-01-01', end='2021-12-31', choice_symbols=['AAPL', 'GOOGL', 'MSFT'])
worker.run_pick_time_task(buy_factors, sell_factors, stop_loss_factors)
  1. Fetching and plotting stock data:
from abupy import ABuSymbolPd
import matplotlib.pyplot as plt

kl_pd = ABuSymbolPd.make_kl_df('AAPL', start='2020-01-01', end='2021-12-31')
kl_pd['close'].plot()
plt.title('AAPL Stock Price')
plt.show()
  1. Running a simple backtest:
from abupy import AbuCapital, AbuKLManager, AbuBenchmark, AbuPickTimeWorker

capital = AbuCapital(1000000, benchmark='AAPL')
kl_pd_manager = AbuKLManager(start='2018-01-01', end='2021-12-31')
benchmark = AbuBenchmark()

worker = AbuPickTimeWorker(capital, benchmark, kl_pd_manager, choice_symbols=['AAPL', 'GOOGL', 'MSFT'])
worker.fit(buy_factors, sell_factors)
worker.capital.plot_returns()

Getting Started

  1. Install Abu:

    pip install abupy
    
  2. Import required modules:

    from abupy import AbuFactorBuyXd, AbuFactorSellXd, AbuPickTimeWorker
    
  3. Define your strategy and run a backtest:

    # Define your buy and sell factors
    buy_factors = [AbuFactorBuyXd(...)]
    sell_factors = [AbuFactorSellXd(...)]
    
    # Create a worker and run the backtest
    worker = AbuPickTimeWorker
    

Competitor Comparisons

9,713

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)

Pros of Lean

  • More comprehensive documentation and extensive wiki
  • Larger community and active development with frequent updates
  • Supports multiple programming languages (C#, Python, F#)

Cons of Lean

  • Steeper learning curve for beginners
  • Requires more setup and configuration
  • Less focus on Chinese markets compared to Abu

Code Comparison

Abu (Python):

from abupy import AbuFactorBuyBreak, AbuFactorSellBreak, AbuFactorAtrNStop
from abupy import AbuPickTimeWorker

buy_factors = [{'xd': 60, 'class': AbuFactorBuyBreak},
               {'xd': 42, 'class': AbuFactorBuyBreak}]
sell_factors = [{'xd': 120, 'class': AbuFactorSellBreak},
                {'stop_loss_n': 1.0, 'stop_win_n': 3.0,
                 'class': AbuFactorAtrNStop}]

worker = AbuPickTimeWorker(start='2013-07-10', end='2018-07-10',
                           buy_factors=buy_factors,
                           sell_factors=sell_factors)

Lean (C#):

public class MyAlgorithm : QCAlgorithm
{
    public override void Initialize()
    {
        SetStartDate(2013, 7, 10);
        SetEndDate(2018, 7, 10);
        SetCash(100000);
        AddEquity("SPY", Resolution.Daily);
    }

    public override void OnData(Slice data)
    {
        if (!Portfolio.Invested)
        {
            SetHoldings("SPY", 1);
        }
    }
}
15,357

Qlib is an AI-oriented quantitative investment platform that aims to realize the potential, empower research, and create value using AI technologies in quantitative investment, from exploring ideas to implementing productions. Qlib supports diverse machine learning modeling paradigms. including supervised learning, market dynamics modeling, and RL.

Pros of qlib

  • More comprehensive and feature-rich quantitative investment platform
  • Backed by Microsoft, potentially offering better long-term support and development
  • Extensive documentation and examples for various investment strategies

Cons of qlib

  • Steeper learning curve due to its complexity and extensive features
  • May be overkill for simpler trading strategies or individual investors
  • Requires more computational resources for advanced features

Code comparison

qlib example:

from qlib.contrib.model.gbdt import LGBModel
from qlib.contrib.data.handler import Alpha158
from qlib.workflow import R

model = LGBModel()
dataset = Alpha158()
R.run(model=model, dataset=dataset)

abu example:

from abupy import AbuFactorBuyBreak, AbuFactorSellNDay, AbuFactorAtrNStop
from abupy import AbuPickTimeWorker

buy_factors = [{'factor_class': AbuFactorBuyBreak, 'xd': 60, 'buy_count': 100}]
sell_factors = [
    {'factor_class': AbuFactorSellNDay, 'sell_n': 5},
    {'factor_class': AbuFactorAtrNStop, 'stop_loss_n': 1.0, 'stop_win_n': 3.0}
]

AbuPickTimeWorker.do_symbols_with_factors(buy_factors, sell_factors)

An Algorithmic Trading Library for Crypto-Assets in Python

Pros of Catalyst

  • Focuses on privacy-preserving smart contracts for the Secret Network
  • Provides tools for building and testing Secret Contracts
  • Offers a more specialized ecosystem for privacy-centric blockchain development

Cons of Catalyst

  • Limited to Secret Network development, less versatile than Abu
  • Smaller community and ecosystem compared to Abu's broader quantitative trading focus
  • Steeper learning curve for developers not familiar with Secret Network

Code Comparison

Abu (Python):

from abupy import AbuFactorBuyBreak, AbuFactorSellBreak, AbuFactorAtrNStop
buy_factors = [{'class': AbuFactorBuyBreak, 'xd': 60, 'buy_count': 100}]
sell_factors = [
    {'class': AbuFactorSellBreak, 'xd': 120},
    {'class': AbuFactorAtrNStop, 'stop_loss_n': 1.0, 'stop_win_n': 3.0}
]

Catalyst (Rust):

use cosmwasm_std::{
    to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult,
};
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};

pub fn instantiate(
    deps: DepsMut,
    _env: Env,
    info: MessageInfo,
    msg: InstantiateMsg,
) -> StdResult<Response> {
    // Contract initialization logic
}
13,247

Download market data from Yahoo! Finance's API

Pros of yfinance

  • Simpler and more focused API for fetching Yahoo Finance data
  • Lightweight with minimal dependencies
  • Actively maintained with frequent updates

Cons of yfinance

  • Limited to Yahoo Finance data only
  • Lacks advanced trading and backtesting capabilities
  • Less comprehensive documentation compared to abu

Code Comparison

yfinance:

import yfinance as yf

ticker = yf.Ticker("AAPL")
hist = ticker.history(period="1mo")
print(hist)

abu:

from abupy import ABuSymbolPd

symbol = 'AAPL'
start = '2020-01-01'
end = '2020-12-31'
df = ABuSymbolPd.make_kl_df(symbol, start=start, end=end)
print(df)

Summary

yfinance is a straightforward library for fetching Yahoo Finance data, while abu is a more comprehensive quantitative trading framework. yfinance is easier to use for simple data retrieval tasks, but abu offers more advanced features for trading strategy development and backtesting. The choice between them depends on the specific requirements of your project and the depth of analysis needed.

Extract data from a wide range of Internet sources into a pandas DataFrame.

Pros of pandas-datareader

  • Widely used and well-maintained by the PyData community
  • Integrates seamlessly with pandas for data manipulation
  • Supports a broad range of data sources, including financial APIs

Cons of pandas-datareader

  • Limited to data retrieval, lacks advanced analysis features
  • May require additional libraries for complex financial modeling
  • Less focused on algorithmic trading compared to abu

Code Comparison

pandas-datareader:

import pandas_datareader as pdr
data = pdr.get_data_yahoo('AAPL', start='2020-01-01', end='2021-01-01')
print(data.head())

abu:

from abupy import ABuSymbolPd
data = ABuSymbolPd.make_kl_df('AAPL', start='2020-01-01', end='2021-01-01')
print(data.head())

Both libraries provide methods to fetch stock data, but abu offers more specialized functions for quantitative trading and analysis beyond basic data retrieval.

17,609

Zipline, a Pythonic Algorithmic Trading Library

Pros of Zipline

  • More established and widely used in the quantitative finance community
  • Extensive documentation and educational resources available
  • Supports a broader range of asset classes and data sources

Cons of Zipline

  • Steeper learning curve for beginners
  • Less focus on AI/ML integration compared to Abu
  • Development has slowed down in recent years

Code Comparison

Zipline example:

from zipline.api import order, record, symbol

def initialize(context):
    context.asset = symbol('AAPL')

def handle_data(context, data):
    order(context.asset, 10)
    record(AAPL=data.current(context.asset, 'price'))

Abu example:

from abupy import AbuFactorBuyBreak, AbuFactorSellBreak, AbuFactorAtrNStop
from abupy import AbuPickTimeWorker

buy_factors = [AbuFactorBuyBreak()]
sell_factors = [AbuFactorSellBreak(), AbuFactorAtrNStop()]
worker = AbuPickTimeWorker(start='2018-03-01', end='2019-03-01', choice_symbols=['US.AAPL'])
worker.run()

Both libraries provide frameworks for backtesting trading strategies, but Abu focuses more on AI-driven approaches and ease of use for beginners, while Zipline offers a more traditional and flexible algorithmic trading platform.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

索引

内容位置
阿布量化系统源代码abupy目录
阿布量化使用教程abupy_lecture目录
阿布量化非编程界面操作abupy_ui目录
《量化交易之路》示例代码ipython/python目录
《机器学习之路》示例代码https://github.com/maxmon/abu_ml

🏆 览器访问网址: https://www.abuquant.com

  1. 🇨🇳 沪深市场量化示例分析列表:
  2. 🇺🇸 美股市场量化示例分析列表:
  3. 🚩 港股市场量化示例分析列表:

特点

  • 使用多种机器学习技术智能优化策略
  • 在实盘中指导策略进行交易,提高策略的实盘效果,战胜市场

支持的投资市场:

  • 美股,A股,港股
  • 期货,期权
  • 比特币,莱特币

工程设计目标:

  • 分离基础策略和策略优化监督模块

  • 提高灵活度和适配性

  • 量化系统

阿布量化综合AI大数据系统, K线形态系统, 缠论,波浪理论,谐波理论,突破,整理形态分析(头肩形态,三头,三角,旗形,楔形,矩形), 经典指标系统, 走势趋势分析系统, 时间序列维度系统, 统计概率系统, 传统均线系统对投资品种进行深度量化分析, 彻底跨越用户复杂的代码量化阶段, 更适合普通人群使用, 迈向量化2.0时代.

  • 量化模型

上述系统中结合上百种子量化模型, 如: 金融时间序列损耗模型, 深度形态质量评估模型, 多空形态组合评定模型, 多头形态止损策略模型, 空头形态回补策略模型, 大数据K线形态历史组合拟合模型, 交易持仓心态模型, 多巴胺量化模型, 惯性残存阻力支撑模型, 多空互换报复概率模型, 强弱对抗模型, 趋势角度变化率模型, 联动分析模型, 时间序列的过激反应模型, 迟钝报复反应模型, 趋势启动速度模型, 配对对冲模型等.

  • AI量化

阿布量化针对AI人工智能从底层开发算法, 构建适合量化体系的人工智能AI系统, 训练了数个从不同角度识别量化特征的评分模型,整体上分为三个系别:物理模型组、多巴胺生物模型组、量化形态模型组。不同系别模型群从不同角度(主要物理交易实体分析、人群心理、图表等三个方向)评估走势,系别的模型群是由若干个独有的识别算法和参数遗传淘汰,组成族群,加权投票评分.

  • 量化策略

阿布量化结合了传统基于代码策的量化系统, 对未来择时信号发出时机的预判, 系统基于数百种简单种子交易策略,衍生出更多的量化交易策略新策略在这些种子基础上不断自我学习、自我成长,不断分裂,适者生存,淘汰选择机制下繁衍,目前应用的量化买入卖出信号策略共计18496种。

  • 量化应用

阿布量化结合多种量化分析数据构建了数百种量化应用, 如: AI高能预警, AI高光时刻, 智能预测涨跌幅, 下跌五浪量化, 上涨五浪量化, 缠论,波浪理论,谐波理论,突破,整理形态分析(头肩形态,三头,三角,旗形,楔形,矩形), 阻力支撑强度分析, 上升三角形突破, 下降三角形, 三重底 (头肩底), 三重顶 (头肩顶), 圆弧顶, 圆弧底, 乌云盖顶形态, 上升三部曲形态, 好友反攻形态, 单针探底形态, 射击之星形态, 多方炮形态, 上涨镊子线, 向上突破箱体, 跳空突破缺口, 黄金分割线量化, 趋势跟踪信号, 均值回复信号, 止损风险控制量化, 止盈利润保护量化, 综合指标分析等.

安装

部署

推荐使用Anaconda部署Python环境,详见 量化环境部署

测试

import abupy

使用文档

1:择时策略的开发

第一节界面操作教程视频播放地址

择时策略决定什么时候买入投资品,回测告诉我们这种策略在历史数据中的模拟收益如何。

  1. 买入择时因子的编写
  2. 分解模式一步一步对策略进行回测
  3. 卖出择时因子的实现

在对的时间,遇见对的人(股票),是一种幸福

在对的时间,遇见错的人(股票),是一种悲伤

在错的时间,遇见对的人(股票),是一声叹息

在错的时间,遇见错的人(股票),是一种无奈

详细阅读

2: 择时策略的优化

通过止盈止损保护策略产生的利润,控制风险。

  1. 基本止盈止损策略
  2. 风险控制止损策略
  3. 利润保护止盈策略

详细阅读

3: 滑点策略与交易手续费

考虑应用交易策略时产生的成交价格偏差及手续费。

  1. 滑点买入卖出价格确定及策略实现
  2. 交易手续费的计算以及自定义手续费
typedatesymbolcommission
buy20150423usTSLA8.22
buy20150428usTSLA7.53
sell20150622usTSLA8.22
buy20150624usTSLA7.53
sell20150706usTSLA7.53
sell20150708usTSLA7.53
buy20151230usTSLA7.22
sell20160105usTSLA7.22
buy20160315usTSLA5.57
sell20160429usTSLA5.57

详细阅读

4: 多支股票择时回测与仓位管理

针对多支股票实现择时策略,通过仓位管理策略控制风险。

  1. 多支股票使用相同的因子进行择时
  2. 自定义仓位管理策略的实现
  3. 多支股票使用不同的因子进行择时
  4. 使用并行来提升择时运行效率

详细阅读

5: 选股策略的开发

一个好的策略需要一个好的标的。

  1. 选股因子的编写
  2. 多个选股因子并行执行
  3. 使用并行来提升选股运行效率

详细阅读

6: 回测结果的度量

正确的度量引领着正确的前进方向。

  1. 度量的基本使用方法
  2. 度量的可视化
  3. 扩展自定义度量类

详细阅读

7: 寻找策略最优参数和评分

通过定制的评分机制,寻找一个策略最合理的参数,比如:应该考虑多少天的均线?

  1. 参数取值范围
  2. Grid Search寻找最优参数
  3. 度量结果的评分
  4. 不同权重的评分
  5. 自定义评分类的实现

详细阅读

8: A股市场的回测

  1. A股市场的回测示例
  2. 涨跌停的特殊处理
  3. 对多组交易结果进行分析

详细阅读

9: 港股市场的回测

  1. 港股市场的回测示例
  2. 优化策略,提高系统的稳定性
  3. 将优化策略的'策略'做为类装饰器进行封装

详细阅读

10: 比特币, 莱特币的回测

  1. 比特币, 莱特币的走势数据分析
  2. 比特币, 莱特币的走势可视化分析
  3. 比特币,莱特币市场的回测

详细阅读

11: 期货市场的回测

  1. 期货市场的特点
  2. 看涨合约的回测
  3. 看跌合约的回测
  4. 位移路程比优化策略

详细阅读

12: 机器学习与比特币示例

如何在投资品的量化交易中正确使用机器学习技术?

  1. 比特币特征的提取
  2. abu中内置机器学习模块的使用
  3. 测试集的验证与非均衡技术
  4. 继承AbuMLPd对数据处理进行封装

详细阅读

13: 量化技术分析应用

技术分析三大假设:市场行为涵盖一切;价格沿趋势移动;历史会重演。

  1. 阻力线,支撑线自动绘制
  2. 跳空技术分析
  3. 传统技术指标技术分析

详细阅读

14: 量化相关性分析应用

相似的投资品数据的背后,往往是相似行为模式的投资人群。

  1. 相关相似度的度量
  2. 距离的度量与相似度
  3. 相似相关接口的应用
  4. 自然相关性

详细阅读

15: 量化交易和搜索引擎

搜索策略生成的失败交易,由裁判拦截住冲动的交易者。

  1. 切分训练集交易的回测
  2. 对交易进行人工分析
  3. 主裁系统原理
  4. 角度主裁
  5. 赋予宏观上合理的解释
  6. 最优分类簇筛选

详细阅读

19: 数据源

abu支持股票、期货、数字货币等多种金融投资品的行情和交易,并具有高度可定制性。

  1. 数据模式的切换
  2. 数据存储的切换
  3. 数据源的切换
  4. 全市场数据的更新
  5. 接入外部数据源,股票数据源
  6. 接入外部数据源,期货数据源
  7. 接入外部数据源,比特币,莱特币数据源

详细阅读

关注阿布量化微信公众号: abu_quant

License

GPL