All Projects → rickyall → Wolfquant

rickyall / Wolfquant

重新造轮子构建投资组合框架,适合大类资产配置和股票交易。

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Wolfquant

Ovilia.github.io
Ovilia's personal site
Stars: ✭ 814 (+2443.75%)
Mutual labels:  portfolio
Reactjs Portfolio Mern Website
My Portfolio | Full Stack MERN Application
Stars: ✭ 25 (-21.87%)
Mutual labels:  portfolio
Masterportfolio
🔥 The Complete Customizable Software Developer Portfolio Template which lets you showcase your work and provides each and every detail about you as Software Developer.
Stars: ✭ 913 (+2753.13%)
Mutual labels:  portfolio
Quantstats
Portfolio analytics for quants, written in Python
Stars: ✭ 823 (+2471.88%)
Mutual labels:  quant
Developer Portfolio
Single page developer portfolio template.
Stars: ✭ 23 (-28.12%)
Mutual labels:  portfolio
Jalpc
🍎Jalpc -- A flexible Jekyll theme, 3 steps to build your website.
Stars: ✭ 859 (+2584.38%)
Mutual labels:  portfolio
Sgx Full Orderbook Tick Data Trading Strategy
Providing the solutions for high-frequency trading (HFT) strategies using data science approaches (Machine Learning) on Full Orderbook Tick Data.
Stars: ✭ 733 (+2190.63%)
Mutual labels:  quant
Hikyuu
Hikyuu Quant Framework 基于C++/Python的开源量化交易研究框架
Stars: ✭ 948 (+2862.5%)
Mutual labels:  quant
Migreyes
The personal site of Mig Reyes, Design Director at Sprout Social.
Stars: ✭ 23 (-28.12%)
Mutual labels:  portfolio
Awesome Ai In Finance
🔬 A curated list of awesome machine learning strategies & tools in financial market.
Stars: ✭ 910 (+2743.75%)
Mutual labels:  quant
Portfolio
My photography portfolio based on PHP Silex micro-framework
Stars: ✭ 16 (-50%)
Mutual labels:  portfolio
Django Photoblog
Photographer portfolio website powered by Django Framework. Features photo gallery with infinite scrolling, tagging, thumbnail generation and CMS for creating pages. Configured for Heroku and S3.
Stars: ✭ 19 (-40.62%)
Mutual labels:  portfolio
Quantaxis spider
QUANTAXIS 爬虫mod python/javascript/mongodb
Stars: ✭ 13 (-59.37%)
Mutual labels:  quant
Sourcerer App
🦄 Sourcerer app makes a visual profile from your GitHub and git repositories.
Stars: ✭ 6,645 (+20665.63%)
Mutual labels:  portfolio
Portfolio
Curate your code and show the world how great you are
Stars: ✭ 21 (-34.37%)
Mutual labels:  portfolio
Strategyease Python Sdk
策略易(StrategyEase)Python SDK,策略自动化交易 API 及量化平台。
Stars: ✭ 741 (+2215.63%)
Mutual labels:  quant
Vngo
golang version of vn.py
Stars: ✭ 25 (-21.87%)
Mutual labels:  quant
Fooltrader
quant framework for stock
Stars: ✭ 960 (+2900%)
Mutual labels:  quant
Blog.hellorusk.net
Tech Blog
Stars: ✭ 28 (-12.5%)
Mutual labels:  portfolio
Portfolio Photo
Jekyll based portfolio using Flickr API.
Stars: ✭ 15 (-53.12%)
Mutual labels:  portfolio

wolfquant

重新构建集成交易、回测、建模的AI投资框架。 期货接口基于pyctp,使用语言python3.6,环境linux64/ubuntu

使用

交易接口调用

1.安装包

$ python setup.py

2.复制配置文件,更新配置信息

$ cp etc/config-default.json config.json

3.使用案例

# 通过以下方式使用期货版API
>>>from wolfquant.api.future import ApiStruct, MdApi, TraderApi

4.运行测试案例

$ cd tests
$ python test_api.py

因子构建并采用机器学习模型训练

import pandas as pd
import numpy as np
import tushare as ts
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis, QuadraticDiscriminantAnalysis
from sklearn.svm import LinearSVC, SVC
from sklearn.metrics import confusion_matrix
from wolfquant.utils.factor_utils import Factor_pipeline
from wolfquant.factors import trade_factors as tf

# 获取数据
datasets = ts.get_k_data('000300', start='2005-01-01', index=True).set_index('date')
datasets.index = pd.to_datetime(datasets.index, format='%Y-%m-%d')

# 构建特征
datasets = Factor_pipeline(datasets).add(tf.SMA, 50)\
                                    .add(tf.EWMA, 200)\
                                    .add(tf.BBANDS, 50)\
                                    .add(tf.CCI, 20)\
                                    .add(tf.ForceIndex, 1)\
                                    .add(tf.EVM, 14)\
                                    .add(tf.ROC, 5)\
                                    .add(tf.LAGRETURN, 0)\
                                    .data.dropna()

# 构建标签
datasets['direction'] = np.sign(datasets['LAGRETURN_0']).shift(-1)
datasets = datasets.dropna()

# 构建训练集和测试集
X = datasets[datasets.columns[6:-2]]
y = datasets['direction']
start_test = '2012-01-01'
X_train = X.loc[:start_test]
X_test = X.loc[start_test:]
y_train = y.loc[:start_test]
y_test = y.loc[start_test:]

# 构建模型
print('Hit rates/Confusion Matrices:\n')
models = [('LR', LogisticRegression()),
          ('LDA', LinearDiscriminantAnalysis()),
          ('QDA', QuadraticDiscriminantAnalysis()),
          ('LSVC', LinearSVC()),
          ('RSVM', SVC()),
          ('RF', RandomForestClassifier(n_estimators=1000))]

# 遍历模型
for m in models:
    # 训练模型
    m[1].fit(X_train, y_train)
    # 预测模型
    pred = m[1].predict(X_test)
    # 输出hit-rate和交叉验证结果
    print("%s:\n%0.3f" % (m[0], m[1].score(X_test, y_test)))
    print("%s\n" % confusion_matrix(pred, y_test))

运行策略回测

import datetime
import numpy as np

from wolfquant.backtest import Backtest
from wolfquant.data import HistoricCSVDataHandler
from wolfquant.event import SignalEvent, OrderEvent
from wolfquant.execution import SimulatedExecutionHandler
from wolfquant.portfolio import NaivePortfolio
from wolfquant.strategy import Strategy

# 创建策略
class BuyAndHoldStrategy(Strategy):
    """一直持有策略
    results:
    Total Return: -2.74%
    Sharpe Ratio: -0.05
    Max Drawdown: 25.00%
    Drawdown Duration: 584
    交易信号数: 1
    下单数: 1
    成交数: 1
    """
    def init(self):
        self.bought = dict([(symbol, False) for symbol in self.symbol_list])

    def handle_bar(self, bar_dict):
        for s in self.symbol_list:
            if self.bought[s] is False:
                self.order_shares(s, 10)
                self.bought[s] = True

# 运行策略
csv_dir = 'data/'
symbol_list = ['hs300']
initial_capital = 100000.0
start_date = datetime.datetime(2015, 4, 8, 0, 0, 0)
end_date = datetime.datetime(2017, 10, 27, 0, 0, 0)
heartbeat = 0.0
backtest = Backtest(csv_dir,
                    symbol_list,
                    initial_capital,
                    heartbeat,
                    start_date,
                    end_date,
                    HistoricCSVDataHandler,
                    SimulatedExecutionHandler,
                    NaivePortfolio,
                    MovingAverageCrossStrategy)
backtest.simulate_trading()

路线图

0.0.0

  • 实现了期货python版的交易接接口
  • 整理交易接口的使用文档

0.0.1

  • 添加交易接口的测试案例

0.0.2

  • 期货交易接口二次开发。
  • 添加feature处理模块。

0.0.3

  • 添加回测模块。
  • 更新策略测试案例。

0.0.4

  • 调整回测功能函数,添加交易接口。
    • order_shares: 按照数据来买
    • order_value: 按照市值来买
    • order_percent: 按照仓位百分比来买
    • order_target_percent: 买到目标仓位
  • 接受并保存期货高频行情数据。

0.0.5

  • 添加tushare数据接口
  • 重新定义回测API

附言

该项目会长期做,有志同道合的小伙伴,欢迎一起入坑,我的微信号wolfquant。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].