{"id":19844585,"url":"https://github.com/tigerfintech/tiger_quant","last_synced_at":"2025-06-10T22:03:30.070Z","repository":{"id":37305839,"uuid":"206763197","full_name":"tigerfintech/tiger_quant","owner":"tigerfintech","description":"Java 实盘量化框架","archived":false,"fork":false,"pushed_at":"2023-12-05T22:41:06.000Z","size":1750,"stargazers_count":89,"open_issues_count":2,"forks_count":67,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-01T20:37:31.620Z","etag":null,"topics":["framework","java","quantitative","quantitative-finance","quantitative-trading","trading"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tigerfintech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-09-06T09:44:17.000Z","updated_at":"2025-04-26T03:22:31.000Z","dependencies_parsed_at":"2025-05-01T20:42:49.113Z","dependency_job_id":null,"html_url":"https://github.com/tigerfintech/tiger_quant","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigerfintech%2Ftiger_quant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigerfintech%2Ftiger_quant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigerfintech%2Ftiger_quant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigerfintech%2Ftiger_quant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tigerfintech","download_url":"https://codeload.github.com/tigerfintech/tiger_quant/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigerfintech%2Ftiger_quant/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259159621,"owners_count":22814490,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["framework","java","quantitative","quantitative-finance","quantitative-trading","trading"],"created_at":"2024-11-12T13:04:44.754Z","updated_at":"2025-06-10T22:03:30.025Z","avatar_url":"https://github.com/tigerfintech.png","language":"Java","readme":"# Tiger Quant\n\n该量化框架是基于`vnpy`的一个java 版本实现，里面集成了一些量化基础功能，同时接入了老虎证券API接口。\n\n## 环境准备\n\n* 支持Windows、Linux、Mac等常见操作系统。\n* JDK 1.8 及以上。\n\n## 快速上手\n### 1. 导出项目到本地\n首先要把`tiger_quant`项目导入到本地IDE中(比如Idea)，导入成maven项目。\n\n### 2. 编写策略\n在`tquant-algorithm` 模块下实现自己的策略类（也可以直接运行示例策略）。一个简单的策略大致如下：\n```java\n    public class BestLimitAlgo extends AlgoTemplate {\n\n      public BestLimitAlgo() {\n      }\n\n      public BestLimitAlgo(Map\u003cString, Object\u003e settings) {\n        super(settings);\n      }\n\n      @Override\n      public void init() {\n        this.direction = (String) settings.get(\"direction\");\n        this.volume = (Integer) settings.get(\"volume\");\n        this.symbol = (String) settings.get(\"symbol\");\n      }\n\n      @Override\n      public void onStart() {\n        //\n        barGenerator = new BarGenerator(bar -\u003e onBar(bar));\n        //订阅 AAPL 行情\n        List\u003cString\u003e symbols = new ArrayList\u003c\u003e();\n        symbols.add(\"AAPL\");\n        subscribe(symbol);\n      }\n    \n      @Override\n      public void onTick(Tick tick) {\n    \n      }\n    \n      private void buyBestLimit() {\n        int orderVolume = volume - traded;\n        orderPrice = lastTick.getBidPrice();\n        if (orderPrice \u003c 10) {\n          buy(symbol, orderPrice, orderVolume, OrderType.LMT);\n        }\n      }\n    \n      private void sellBestLimit() {\n        int orderVolume = volume - traded;\n        orderPrice = lastTick.getAskPrice();\n        if (orderPrice \u003e 12) {\n          sell(symbol, orderPrice, orderVolume, OrderType.LMT);\n        }\n      }\n    \n      @Override\n      public void onOrder(Order order) {\n        \n      }\n    \n      @Override\n      public void onTrade(Trade trade) {\n      }\n    \n      @Override\n      public void onBar(Bar bar) {\n        log(\"onBar {}\", bar);\n      }\n}\n```\n实现的策略类需要继承 `AlgoTemplate`类，这样即可调用封装好的一些方法，同时自动注入策略配置项。常用的封装方法包括：buy，sell等下单功能，onBar（K线），onOrder（订单），onTick（实时行情）等实时事件，还有一些券商封装的api接口以及日志功能等。\n   \n### 3. 完成对应的策略配置及券商接入配置\n可以拷贝根目录下的2个配置模板，一个是`algo_setting.json`，对应的是策略参数。另一个是`gateway_setting.json`，对应老虎API的账号信息，完成对应配置即可（下面有详细的配置说明）。\n\n### 4. 编译运行策略\n\n在项目的根目录下执行如下mvn命令即可完成打包工作：\n```shell script\nmvn -U clean install  -Dmaven.test.skip=true\n```\n等命令执行完成后，会在 `tquant-bootstrap`的`target`目录下生成可执行jar包：`tquant-bootstrap-1.0.0-jar-with-dependencies.jar`，\n把该jar包以及`algo_setting.json`，`gateway_setting.json`拷贝到指定目录后，再通过执行如下命令即可运行策略：\n```\n    java -jar tquant-bootstrap-1.0.0-jar-with-dependencies.jar -a /yourpath/algo_setting.json -g /yourpath/tiger_gateway_setting.json\n```\n调试阶段也可以通过IDE来运行，通过配置`TigerQuantBootstrap`的启动参数即可。如在Idea编辑器里的配置如下：\n![tquant-bootstrap](https://user-images.githubusercontent.com/3766355/219582428-9f2a6d81-4118-46f5-82c5-1fe77e0ea306.png)\n\n### 5. 停止执行策略\n有些策略是在程序里自动退出的，也有一些策略是一直运行的，如想停止对应的策略，可以在命令行下执行`ps`命令查出项目运行的进程 pid，再执行kill命令停止策略运行。\nkill命令执行时会同时执行项目的stop方法回调。\n```\n    ps -ef|grep TigerQuantBootstrap\n    kill {pid}\n```\n\n\n## 配置说明\n\n### 策略配置\n策略配置文件：`algo_setting.json`\n\n每个算法文件对应一个配置项，配置项的Key与策略Java文件名称要保持一致。\n配置项中必填参数如下：\n* enable：是否启用该策略。true 启用，false 不启用\n* class：策略算法对应的文件全路径名\n* 其他参数为自选参数，在策略启动时会自动注册到策略中。\n\n* 配置实例\n```\n{\n  \"BestLimitAlgo\": {\n    \"enable\": false,\n    \"class\":\"com.tquant.algorithm.algos.BestLimitAlgo\",\n    \"direction\": \"BUY\",\n    \"volume\": 100,\n    \"symbol\": \"00700\"\n  },\n  \"DmaAlgo\": {\n    \"enable\": false,\n    \"class\":\"com.tquant.algorithm.algos.DmaAlgo\",\n    \"direction\": \"BUY\",\n    \"price\": 13.2,\n    \"volume\": 100\n  },\n  \"SpreadAlgo\": {\n    \"enable\": true,\n    \"class\":\"com.tquant.algorithm.algos.MacdAlgo\",\n    \"symbol\": \"SPY\",\n    \"bars\": 100\n  }\n}\n```\n\n### 全局配置\n全局配置文件名：`global_setting.json` ， 在`tquant-core`模块 `resources` 目录下。\n\n\n* log.enable：是否开启日志开关。true 打开，false 关闭\n* log.level：日志级别，默认info级别。取值包括 error,warn,info\n* log.console：日志是否输出到控制台。true 输出到控制台，false 不输出到控制台\n* log.file：日志是否输出到文件。true 输出到文件，false 不输出到文件\n* log.path：日志输出到文件的路径。支持绝对路径和相对路径。默认当前项目下的log目录\n* storage.enable：是否开启持久化存储。true 开启，false 不开启\n* subscribe.enable: 是否开启API长连接订阅，默认为 false，开启后会通过长连接回调方法获取实时行情，交易订单变更，持仓和资产变更等。未开启的话可以通过API接口获取对应数据。\n* contract.load.enable: 是否在启动时开启合约加载，默认为 false，开启后会通过本地数据库加载全量合约，需要配合`tquant-loader`中的合约加载功能一块儿使用。\n\n### 接入券商配置\n目前只支持Tiger券商接口，配置文件名：`gateway_setting.json`\n\n* gateway：固定为TigerGateway\n* apiLogEnable：是否开启SDK的日志记录\n* apiLogPath：SDK日志文件输出路径，默认当前项目下的log目录\n\n下面配置为开发者信息相关，需要先申请开发者账号，注册开发者账号地址：https://www.tigersecurities.com/openapi\n* tigerId：开发者账号ID\n* account：开发者交易账号，可以是老虎综合账号或模拟账号。\n* privateKey：开发者自己生成的RSA私钥\n\n* 配置实例\n```\n{\n  \"gateway\": \"TigerGateway\",\n  \"apiLogEnable\": true,\n  \"apiLogPath\": \"log/\",\n  \"tigerId\": \"2015xxxx\",\n  \"account\": \"20190419163707900\",\n  \"privateKey\": \"MIICeQIBADANBgkqhkiG9w0BAQEFAASCAmMwggJfAgEAAoGBAL7...\"\n }\n```\n\n## Thetagang策略说明\n\nThetagang是我们封装的一个期权策略，策略的意图是赚取theta（时间价值）流失的钱，该策略最初是在reddit论坛里发起，是一个比较成熟的期权策略。\n具体介绍可以参考：https://www.reddit.com/r/options/comments/a36k4j/the_wheel_aka_triple_income_strategy_explained/\n\n同时在github有一个基于IB的[thetagang策略](https://github.com/brndnmtthws/thetagang)，我们的java版本策略也是基于此来改造的。\n\n策略使用参数介绍如下：\n\u003e 注意：以下策略配置文件不能直接使用，因为使用了注释说明，不是标准json格式，如需使用，可以直接使用项目根目录下的模板文件：`algo_setting.json`\n\n```json\n \"ThetaGangAlgo\": {\n    \"enable\": true, //是否启用策略\n    \"class\":\"com.tquant.algorithm.algos.ThetaGangAlgo\", //对应策略实现的代码路径\n    \"account\": {\n      \"account_id\": \"20190419163107900\", //使用的账号信息，可以配置为模拟账号或综合账号\n      \"cancel_orders\": true, //策略执行前，是否要取消已经挂出去的订单\n      \"margin_usage\": 0.5, //该策略要使用的资金占总资产的比例，如 0.5 表示为 50%\n    },\n    //期权链是延迟加载的，在你确定期权希腊值（delta）或期权价格之前，你需要先扫描期权链。\n    //这里的设置是告诉thetagang策略要加载多少个合约。不要让这些值太大，因为它们会导致扫描期权链过多，可能会失败。\n    //如果你遇到thetagang找不到合适的contract的问题，可以试试略微增加这些值。\n    \"option_chains\": {\n      \"expirations\": 4, //从期权链上加载的到期日数量\n      \"strikes\": 15 //从期权链上加载的行权价数量\n    },\n    \"roll_when\": {\n      \"pnl\": 0.9, //盈亏(pnl)到达 90% 时，需要滚动持仓\n      //或者，当离到期日\u003c=15天，并且盈亏至少到min_pnl (min_pnl默认为0)时。\n      //注意：对于期权最终是深度 ITM 的情况，特别是在卖出套期保值（covered call）的时候，盈亏有可能是负数、\n      //示例：如果你想在这种情况下进行滚动，请将min_pnl设置为一个负值，如-1（代表-100%）。\n      \"dte\": 15, \n      \"min_pnl\": 0.2,\n      //可选的： 当盈亏达到这个阈值时，创建一个平仓单。\n      //这会覆盖其他参数，也就是说，它忽略了dte和其他参数。如果不指定，它没有任何作用。\n      //这可以处理这样的情况，即你有长期的期权，已经慢慢变得毫无价值，你只是想把它们从你的投资组合中删除。\n      \"close_at_pnl\": 0.99,\n      \"calls\": {\n        \"itm\": true,\n        \"credit_only\": false //只有在有合适的contract可用时，才会进行滚动，从而获得一个 credit。\n      },\n      \"puts\": {\n        \"itm\": false,\n        \"credit_only\": false //只有在有合适的contract可用时，才会进行滚动，从而获得一个 credit。\n      }\n    },\n    \"write_when\": {\n      \"calls\": {\n        \"green\": true, //可选的，只有在对应标的上涨时才会write。\n        //有了套期保值(covered call)，我们就可以通过这个因素来限定写的套期保值的数量。\n        //在1.0的时候，我们对100%的头寸写覆盖性看涨。\n        //在0.5时，我们只写 50%的头寸。这个值必须在1和0之间（含）。\n        \"cap_factor\": 1\n      },\n      \"puts\": {\n        \"red\": true  //可选的，只有在对应标的下跌时才会write。\n      }\n    },\n    \"target\": {\n      \"dte\": 45,  // Target 45 or more days to expiry\n      \"delta\": 0.3,  //Target delta of 0.3 or less. Defaults to 0.3 if not specified.\n      // When writing new contracts (either covered calls or naked puts), or rolling\n      // before `roll_when.dte` is reached, never write more than this amount of\n      // contracts at once. This can be useful to avoid bunching by spreading contract\n      // placement out over time (and possibly expirations) in order to protect\n      // yourself from large swings. This value does not affect rolling existing\n      // contracts to the next expiration. This value is expressed as a percentage of\n      // buying power based on the market price of the underlying ticker, as a range\n      // from [0.0-1.0].\n      //\n      // Once the `roll_when.dte` date is reached, all the remaining positions are\n      // rolled regardless of the current position quantity.\n      //\n      // Defaults to 5% of buying power. Set this to 1.0 to effectively disable the\n      // limit.\n      \"maximum_new_contracts_percent\": 0.05, \n      // Minimum amount of open interest for a contract to qualify\n      \"minimum_open_interest\": 10\n    },\n\n    // Optional: specify delta separately for puts/calls. Takes precedent over\n    // target.delta.\n    //\n    //  [target.puts]\n    //  delta = 0.5\n    //  [target.calls]\n    //  delta = 0.3\n    \"symbols\": {\n        # NOTE: Please change these symbols and weights according to your preferences.\n        # These are provided only as an example for the purpose of configuration. These\n        # values were chosen as sane values should someone decide to run this code\n        # without changes, however it is in no way a recommendation or endorsement.\n        #\n        # You can specify the weight either as a percentage of your buying power (which\n        # is calculated as your NLV * account.margin_usage), or in terms of parts. Parts\n        # are summed from all symbols, then the weight is calculated by dividing the\n        # parts by the total parts.\n        #\n        # You should try to choose ETFs or stocks that:\n        #\n        #  1) Have sufficient trading volume for the underlying\n        #  2) Have standard options contracts (100 shares per contract)\n        #  3) Have options with sufficient open interest and trading volume\n        #\n        # The target delta may also be specified per-symbol, and takes precedence over\n        # `target.delta` or `target.puts/calls.delta`. You can specify a value for the\n        # symbol, or override individually for puts/calls.\n      \"SPY\": {\n        \"weight\": 0.4\n      },\n      \"AAPL\": {\n        \"weight\": 0.3\n      },\n      \"MSFT\": {\n        \"weight\": 0.3\n      }\n    }\n  }\n```\n\n## 外部依赖\n\n#### ta4j\n\n指标计算工具，包括常见的上百种指标计算。\n* 项目地址：https://github.com/ta4j/ta4j\n* 项目wiki：https://github.com/ta4j/ta4j-wiki\n\n\n## 问题反馈\n\n使用上遇到任何问题，或有任何建议，欢迎在github上反馈，也欢迎加入官方QQ群：441334668。\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftigerfintech%2Ftiger_quant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftigerfintech%2Ftiger_quant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftigerfintech%2Ftiger_quant/lists"}