{"id":14080896,"url":"https://github.com/bsdz/yabte","last_synced_at":"2025-07-30T19:32:38.086Z","repository":{"id":65767648,"uuid":"578787976","full_name":"bsdz/yabte","owner":"bsdz","description":"Yet another backtesting engine","archived":false,"fork":false,"pushed_at":"2024-05-11T20:01:15.000Z","size":3236,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-29T02:12:27.417Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":false,"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/bsdz.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2022-12-15T22:08:32.000Z","updated_at":"2024-07-13T06:16:09.000Z","dependencies_parsed_at":"2023-11-18T00:59:36.127Z","dependency_job_id":"3b94d402-9b99-4895-b884-b6ea57724aa3","html_url":"https://github.com/bsdz/yabte","commit_stats":{"total_commits":46,"total_committers":2,"mean_commits":23.0,"dds":"0.23913043478260865","last_synced_commit":"4159786ccc9995eb2590378d4f69bbb83d276ee9"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsdz%2Fyabte","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsdz%2Fyabte/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsdz%2Fyabte/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsdz%2Fyabte/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsdz","download_url":"https://codeload.github.com/bsdz/yabte/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228178899,"owners_count":17881105,"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":[],"created_at":"2024-08-13T13:00:18.864Z","updated_at":"2024-12-04T19:32:03.207Z","avatar_url":"https://github.com/bsdz.png","language":"Jupyter Notebook","funding_links":[],"categories":["Python"],"sub_categories":["Trading \u0026 Backtesting"],"readme":"# yabte - Yet Another BackTesting Engine\n\nPython module for backtesting trading strategies.\n\nFeatures\n\n* Event driven, ie `on_open`, `on_close`, etc. \n* Multiple assets.\n* OHLC Asset. Extendable (e.g support additional fields, e.g. Volatility, or entirely different fields, e.g. Barrels per day).\n* Multiple books.\n* Positional and Basket orders. Extendible (e.g. can support stop loss).\n* Batch runs (for optimization).\n* Captures book history including transactions \u0026 daily cash, MtM and total values.\n\nThe module provides basic statistics like book cash, mtm and total value. Currently, everything else needs to be deferred to a 3rd party module like `empyrical`.\n\n## Core dependencies\n\nThe core module uses pandas and scipy.\n\n## Installation\n\n```bash\npip install yatbe\n```\n\n## Usage\n\nBelow is an example usage (the economic performance of the example strategy won't be good).\n\n```python\nimport pandas as pd\n\nfrom yabte.backtest import Book, SimpleOrder, Strategy, StrategyRunner\nfrom yabte.tests._helpers import generate_nasdaq_dataset\nfrom yabte.utilities.plot.plotly.strategy_runner import plot_strategy_runner_result\nfrom yabte.utilities.strategy_helpers import crossover\n\n\nclass SMAXO(Strategy):\n    def init(self):\n        # enhance data with simple moving averages\n\n        p = self.params\n        days_short = p.get(\"days_short\", 10)\n        days_long = p.get(\"days_long\", 20)\n\n        close_sma_short = (\n            self.data.loc[:, (slice(None), \"Close\")]\n            .rolling(days_short)\n            .mean()\n            .rename({\"Close\": \"CloseSMAShort\"}, axis=1, level=1)\n        )\n        close_sma_long = (\n            self.data.loc[:, (slice(None), \"Close\")]\n            .rolling(days_long)\n            .mean()\n            .rename({\"Close\": \"CloseSMALong\"}, axis=1, level=1)\n        )\n        self.data = pd.concat(\n            [self.data, close_sma_short, close_sma_long], axis=1\n        ).sort_index(axis=1)\n\n    def on_close(self):\n        # create some orders\n\n        for symbol in [\"GOOG\", \"MSFT\"]:\n            df = self.data[symbol]\n            ix_2d = df.index[-2:]\n            data = df.loc[ix_2d, (\"CloseSMAShort\", \"CloseSMALong\")].dropna()\n            if len(data) == 2:\n                if crossover(data.CloseSMAShort, data.CloseSMALong):\n                    self.orders.append(SimpleOrder(asset_name=symbol, size=-100))\n                elif crossover(data.CloseSMALong, data.CloseSMAShort):\n                    self.orders.append(SimpleOrder(asset_name=symbol, size=100))\n\n\n# load some data\nassets, df_combined = generate_nasdaq_dataset()\n\n# create a book with 100000 cash\nbook = Book(name=\"Main\", cash=\"100000\")\n\n# run our strategy\nsr = StrategyRunner(\n    data=df_combined,\n    assets=assets,\n    strategies=[SMAXO()],\n    books=[book],\n)\nsrr = sr.run()\n\n# see the trades or book history\nth = srr.transaction_history\nbch = srr.book_history.loc[:, (slice(None), \"cash\")]\n\n# plot the trades against book value\nplot_strategy_runner_result(srr, sr)\n```\n\n![Output from code](https://raw.githubusercontent.com/bsdz/yabte/main/readme_image.png)\n\n## Examples\n\nJupyter notebook examples can be found under the [notebooks folder](https://github.com/bsdz/yabte/tree/main/notebooks).\n\n## Documentation\n\nDocumentation can be found on [Read the Docs](https://yabte.readthedocs.io/en/latest/).\n\n\n## Development\n\nBefore commit run following format commands in project folder:\n\n```bash\npoetry run black .\npoetry run isort . --profile black\npoetry run docformatter . --recursive --in-place --black --exclude _unittest_numpy_extensions.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsdz%2Fyabte","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsdz%2Fyabte","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsdz%2Fyabte/lists"}