Giter Club home page Giter Club logo

xlib's Introduction

xlib-quant

  • 一个简单的量化研究框架,具备基本的数据获取、因子分析、机器学习、回测及结果分析功能。
  • 框架具体思路与内容请参考公众号FinHack炼金术《从零开始卷量化(25)-脱离Qlib,手撸一个属于自己的量化投资框架! 》
  • 当且该框架并不稳定,预计本系列文章全部更新完(预计65篇,5月底前更新完)后会出一个稳定版的分支。

公众号

扫码_搜索联合传播样式-标准色版

框架整体思路

image

一把梭代码

import pandas as pd
from xlib import data
from xlib import factors
from xlib import model
from xlib.strategies import Top10Strategy
from xlib import backtest

df=data.get_all_index_data()
bench=data.get_index_data(index="000300",start_date="20200101",end_date="20220330",renew=False)

df=factors.getTA(df)
df['label']=df.groupby('symbol')['close'].shift(10)
df['label']=df['close']/df['label']

df_train,df_valid,df_pred=model.datasplit(df,train_end='2019-01-01',valid_end='2020-01-01')
model.lgbtrain(df_train,df_valid,label='label')  
preds=model.lgbpred(df_pred,label='label') 
preds['score']=preds['pred']
preds['rank']=preds.groupby('date')['pred'].rank()
preds['signal']=preds.apply(lambda x: 1 if x['rank']<=10 else 0 ,axis=1)

returns=backtest.test(preds,Top10Strategy)
backtest.analysis(returns,bench)

结果演示

image

image

image image image image

image image image image image image image image image

xlib's People

Contributors

woldy avatar

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.