{"id":25971679,"url":"https://github.com/dirkolbrich/gobacktest","last_synced_at":"2025-03-05T00:01:54.632Z","repository":{"id":57494176,"uuid":"98384762","full_name":"gobacktest/gobacktest","owner":"gobacktest","description":"event-driven backtesting framework written in golang","archived":true,"fork":false,"pushed_at":"2023-10-11T12:34:18.000Z","size":1076,"stargazers_count":224,"open_issues_count":0,"forks_count":57,"subscribers_count":14,"default_branch":"main","last_synced_at":"2024-05-22T15:31:18.467Z","etag":null,"topics":["algorithmic-trading","backtesting-frameworks","finance","financial-analysis","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gobacktest.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2017-07-26T05:54:17.000Z","updated_at":"2024-06-18T18:31:10.327Z","dependencies_parsed_at":"2024-06-18T18:31:09.375Z","dependency_job_id":"07a4c331-6569-4a49-97a1-417ea5102688","html_url":"https://github.com/gobacktest/gobacktest","commit_stats":null,"previous_names":["dirkolbrich/gobacktest"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobacktest%2Fgobacktest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobacktest%2Fgobacktest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobacktest%2Fgobacktest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobacktest%2Fgobacktest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gobacktest","download_url":"https://codeload.github.com/gobacktest/gobacktest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241940555,"owners_count":20045881,"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":["algorithmic-trading","backtesting-frameworks","finance","financial-analysis","go","golang"],"created_at":"2025-03-05T00:01:38.077Z","updated_at":"2025-03-05T00:01:54.615Z","avatar_url":"https://github.com/gobacktest.png","language":"Go","funding_links":[],"categories":["Golang"],"sub_categories":["Trading \u0026 Backtesting"],"readme":"[![Go Doc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](http://godoc.org/github.com/dirkolbrich/gobacktest)\n[![Travis](https://img.shields.io/travis/dirkolbrich/gobacktest.svg?style=flat-square)](https://travis-ci.org/dirkolbrich/gobacktest)\n[![Coverage Status](https://img.shields.io/coveralls/dirkolbrich/gobacktest/master.svg?style=flat-square)](https://coveralls.io/github/dirkolbrich/gobacktest?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/dirkolbrich/gobacktest?style=flat-square)](https://goreportcard.com/report/github.com/dirkolbrich/gobacktest)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](/LICENSE.md)\n\n_**Heads up:** This project is dead. It fought well, but died on the battlefield of abandoned open source projects. It was a good project. It will be remembered for decades to come._\n\n---\n\n# gobacktest - Fundamental stock analysis backtesting\n\nAn event-driven backtesting framework to test stock trading strategies based on fundamental analysis. Preferably this package will be the core of a backend service exposed via a REST API. Currently it has only core functionality.\n\n## Usage\n\nBasic example:\n\n```golang\npackage main\n\nimport (\n  \"github.com/dirkolbrich/gobacktest\"\n  \"github.com/dirkolbrich/gobacktest/data\"\n  \"github.com/dirkolbrich/gobacktest/strategy\"\n)\n\nfunc main() {\n  // initiate a new backtester\n  test := gobacktest.New()\n\n  // define and load symbols\n  symbols := []string{\"TEST.DE\"}\n  test.SetSymbols(symbols)\n\n  // create a data provider and load the data into the backtest\n  data := \u0026data.BarEventFromCSVFile{FileDir: \"../testdata/test/\"}\n  data.Load(symbols)\n  test.SetData(data)\n\n  // choose a strategy\n  strategy := strategy.BuyAndHold()\n\n  // create an asset and append it to the strategy\n  strategy.SetChildren(gobacktest.NewAsset(\"TEST.DE\"))\n  \n  // load the strategy into the backtest\n  test.SetStrategy(strategy)\n\n  // run the backtest\n  test.Run()\n\n  // print the results of the test\n  test.Stats().PrintResult()\n}\n```\n\nMore example tests are in the `/examples` folder.\n\nThe single parts of the backtester can be set independently:\n\n```golang\n// initiate new backtester\ntest := \u0026Backtest{}\n\n// set the portfolio with initial cash and a default size and risk manager\nportfolio := \u0026gobacktest.Portfolio{}\nportfolio.SetInitialCash(10000)\n\nsizeManager := \u0026gobacktest.Size{DefaultSize: 100, DefaultValue: 1000}\nportfolio.SetSizeManager(sizeManager)\n\nriskManager := \u0026gobacktest.Risk{}\nportfolio.SetRiskManager(riskManager)\n\ntest.SetPortfolio(portfolio)\n\n// create a new strategy with an algo stack\nstrategy := gobacktest.NewStrategy(\"basic\")\nstrategy.SetAlgo(\n    algo.CreateSignal(\"buy\"), // always create a buy signal on a data event\n)\n\n// create an asset and append to strategy\nstrategy.SetChildren(gobacktest.NewAsset(\"TEST.DE\"))\n\n// load the strategy into the backtest\ntest.SetStrategy(strategy)\n\n// create an execution provider and load it into the backtest\nexchange := \u0026gobacktest.Exchange{\n    Symbol:      \"TEST\",\n    Commission:  \u0026FixedCommission{Commission: 0},\n    ExchangeFee: \u0026FixedExchangeFee{ExchangeFee: 0},\n}\ntest.SetExchange(exchange)\n\n// choose a statistic and load into it the backtest\nstatistic := \u0026gobacktest.Statistic{}\ntest.SetStatistic(statistic)\n```\n\n## Dependencies\n\nNone so far. Only the standard library.\n\n## Basic components\n\nThese are the basic components of an event-driven framework.\n\n1. BackTester - general test case, bundles the following elements into a single test\n2. EventHandler - the different types of events, which travel through this system - data event, signal event, order event and fill event\n3. DataHandler - interface to a set of data, e.g historical quotes, fundamental data, dividends etc.\n4. StrategyHandler - generates a buy/sell signal based on the data\n5. PortfolioHandler - generates orders and manages profit \u0026 loss\n    + (SizeHandler) - manages the size of an order\n    + (RiskHandler) - manages the risk allocation of a portfolio\n6. ExecutionHandler - sends orders to the broker and receives the “fills” or signals that the stock has been bought or sold\n7. StatisticHandler - tracks all events during the backtests and calculates useful statistics like equity return, drawdown or sharp ratio etc., could be used to replay the complete backtest for later reference\n   + (ComplianceHandler) - tracks and documents all trades to the portfolio for compliance reasons\n\n## Infrastructure example\n\nAn overviev of the infrastructure of a complete backtesting and trading environment. Taken from the production roadmap of [QuantRocket](https://www.quantrocket.com/#product-roadmap).\n\n- General\n  + API gateway\n  + configuration loader\n  + logging service\n  + cron service\n- Data\n  + database backup and download service\n  + securities master services\n  + historical market data service\n  + fundamental data service\n  + earnings data service\n  + dividend data service\n  + real-time market data service\n  + exchange calendar service\n- Strategy\n  + performance analysis service - tearsheet\n- Portfolio\n  + account and portfolio service\n  + risk management service\n- Execution\n  + trading platform gateway service\n  + order management and trade ledger service\n  + backtesting and trading engine\n\n---\n\n## Resources\n\n### Articles\n\nThese links to articles are a good starting point to understand the intentions and basic functions of an event-driven backtesting framework.\n\n- Initial idea via a blog post [Python For Finance: Algorithmic Trading](https://www.datacamp.com/community/tutorials/finance-python-trading#backtesting) by Karlijn Willems [@willems_karlijn](https://twitter.com/willems_karlijn).\n- Very good explanation of the internals of a backtesting system by Michael Halls-Moore [@mhallsmoore](https://twitter.com/mhallsmoore) in the blog post series [Event-Driven-Backtesting-with-Python](https://www.quantstart.com/articles/Event-Driven-Backtesting-with-Python-Part-I).\n\n### Other backtesting frameworks\n\n- [QuantConnect](https://www.quantconnect.com)\n- [Quantopian](https://www.quantopian.com)\n- [QuantRocket](https://www.quantrocket.com) - in development, available Q2/2018\n- [Quandl](https://www.quandl.com) - financial data\n- [QSTrader](https://www.quantstart.com/qstrader) - open-source backtesting framework from [QuantStart](https://www.quantstart.com)\n- [bt - Flexible Backtesting for Python](http://pmorissette.github.io/bt/) - an inspiration for algorithm building blocks and a strategy/assets tree\n\n### General information on Quantitative Finance\n\n- [Quantocracy](http://quantocracy.com) - forum for quant news\n- [QuantStart](https://www.quantstart.com) - articels and tutorials about quant finance\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirkolbrich%2Fgobacktest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdirkolbrich%2Fgobacktest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirkolbrich%2Fgobacktest/lists"}