Code Monkey home page Code Monkey logo

high-frequency's Introduction

高频跨期套利策略

Logo GitHub stars GitHub forks GitHub issues

策略说明

交易标的:比特币(BTC)

价差数据:BTC 永续 - BTC 季度(省略协整性检验)

交易周期:1 分钟

头寸匹配:1:1

交易类型:同品种跨期

做多价差开仓条件:如果当前账户没有持仓,并且价差 < (长期价差水平 - 阈值),就做多价差。即:买开 BTC 永续,卖开 BTC 季度。

做空价差开仓条件:如果当前账户没有持仓,并且价差 > (长期价差水平 + 阈值),就做空价差。即:卖开 BTC 永续,买开 BTC 季度。

做多价差平仓条件:如果当前账户持有 BTC 永续多单,并且持有 BTC 季度空单,并且价差 > 长期价差水平,就平多价差。即:卖平 BTC 永续,买平 BTC 季度。

做空价差平仓条件:如果当前账户持有 BTC 永续空单,并且持有 BTC 季度多单,并且价差 < 长期价差水平,就平空价差。即:买平 BTC 永续,卖平 BTC 季度。

举个例子,假设 BTC 永续 和 BTC 当季的价差长期维持在 35 左右。如果某一天价差达到 50 ,我们预计价差会在未来某段时间回归到 35 及以下。那么就可以卖出 BTC 永续,同时买入 BTC 当季,来做空这个价差。反之亦然,注意 BTC 永续 和 BTC 当季 的价差总会回归到0附近(到期交割),所以价差为正的时候,优先做空价差,价差为负的时候,优先做多价差。

KuCoin拥有level3交易数据、强大的撮合引擎、针对api用户提供的手续费折扣,同时提供sandbox环境作为数据测试支撑,帮助你规避风险。

我们仅提供一个简单且不完备的交易策略,使用时请注意规避风险,我们希望你能够在sandbox环境配合其他参数或是策略进行测试调整,我们也不想你成为一个慈善家!!!

当然,如果这个过程中,你遇到任何问题或是有赚钱的策略想要分享,请在ISSUE中反映,我们会努力及时响应。

👉 如果你对该策略有兴趣,请点击右上角star,我们会根据star数来衡量策略的受欢迎程度和后续优化优先级,你也可以点击右上角watching通过接收更新通知来持续关注该项目。

如何使用

  • 安装Python

    • Windows系统请前往Python官网自行安装,64位请选择1,32位请选择2。

      • 在开始安装时请注意将以下选项勾选:

    • MAC OS X安装

      • 打开命令终端,输入以下命令安装Homebrew(安装过程中需要输入电脑密码):

        /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
      • 在命令终端输入以下命令,安装Python3:

        brew install python
      • 在命令终端输入以下命令,确认是否安装成功:

        python3 --version

  • 确保你已经安装git (mac 自带该软件,终端输入which git,查看安装位置),未安装者请前往官网git安装。

  • 在命令终端输入以下命令,安装项目依赖:

    pip3 install python-kumex

    pip_install

  • 在你需要跑策略的位置新建文件夹(例如桌面),右键点击新建的文件夹选择“新建位于文件夹位置的终端窗口”(windows系统:在右键点击文件夹点击git Bash here),在弹出的窗口中输入以下命令,克隆项目至本地,完成后本地会新增文件夹high-frequency

    git clone https://github.com/Kucoin-academy/high-frequency.git

    git_clone

  • 打开克隆好的项目(high-frequency)文件夹,将config.json.example文件重命名为config.json,并用文本编辑器(比如记事本)打开config.json,然后完善相关的配置信息:

    {  
      "api_key": "api key",
      "api_secret": "api secret",
      "api_passphrase": "api pass phrase",
      // 是否是沙盒环境
      "is_sandbox": true,
      // 合约名称,比如:XBTUSDM
      "symbol_a": "contract name",
      // 合约名称,比如:XBTMM20
      "symbol_b": "contract name",
      // 长期价差水平,可取前三天的价差均值  
      "spread_mean": "average closed price for 3 days",
      // 价差阈值,可取前三天的价差2倍标准差左右
      "num_param": "2 * Standard deviation of spread_mean",
      // 杠杆倍数,比如:5
      "leverage": "Leverage of the order",
      // 开仓数量,比如:1
      "size": "Order size. Must be a positive number"
    }
    
  • Mac/Linux 在项目目录下打开命令终端:

    cd high-frequency
    • 用以下命令让你的策略运行起来:

      ./high_frequency.py
  • Windows 在项目目录下打开命令终端:

    cd high-frequency
    • 用以下命令让你的策略运行起来:

      py high_frequency.py

high-frequency's People

Contributors

1bazinga25 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

high-frequency's Issues

symbol_b 季度合约

image
沙盒只有永续合约,没有季度合约,意思说这个策略无法运行了吗?

error..!

r# ./high_frequency.py
Traceback (most recent call last):
File "./high_frequency.py", line 40, in
price_bf = hf.get_symbol_price(hf.symbol_b)
File "./high_frequency.py", line 32, in get_symbol_price
return float(ticker['price'])
KeyError: 'price'

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.