# Fast Trade
[![License: LGPL v3](https://img.shields.io/github/license/jrmeier/fast-trade)](LICENSE)
[![PyPI](https://img.shields.io/pypi/v/fast-trade.svg?style=flat-square)](https://pypi.org/project/fast-trade/)
[![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/download/releases/3.7.0/)
[![Python application](https://github.com/jrmeier/fast-trade/workflows/Python%20application/badge.svg)](https://github.com/jrmeier/fast-trade/actions)
A library built with backtest portability and performance in mind for backtest trading strategies. There is also a [DataDownloader](#DataDownloader), which can be used to download compatible kline data from Binance (.com or .us)
## Motivations
Strategies are cheap. This is the main motivation behind fast-trade. Since a backtest is just a JSON object, strategies can be created, stored, modified, versioned, and re-run easily. Ideally, a backtest could be generated and tested quickly; fast-trade is just the library to handle that.
Fast Trade is also useful for quickly analyzing chart (`ohlcv`) data and downloading it.
## Beta Testing
I'm using this library to build a platform (live data, charting, paper trading, etc.) and I'm looking for beta testers. If you like this library, send me an email at fasttrade@jedm.dev.
## Contributing
If you'd like to add a feature, fix a bug, or something else, please clone the repo and fork it. When you're ready, open a PR into this main repo.
To get started with local dev, clone the repo, set up a virtual env, source it, then install the dev requirements.
```bash
git clone git@github.com:<YOUR GIT USERNAME>/fast-trade.git
cd ./fast-trade
python -m venv .fast_trade
source .fast_trade/bin/activate
pip install -r dev_requirements.txt
```
To generate testing coverage, run
```bash
coverage run -m pytest
coverage report -m
```
## Install
```bash
pip install fast-trade
```
## Usage
See [sma_strategy.json](./sma_strategy.json) and [strategy.json](./strategy.json) for an example strategy. The basic idea is you describe the "datapoints" then compare them in the "logics". The "datapoints" describe the technical analysis functions to run, and the "logics" describe the logic to use to determine when to enter and exit trades.
Example backtest script
```python
from fast_trade import run_backtest, validate_backtest
backtest = {
"base_balance": 1000, # start with a balance of 1000
"chart_period": "5Min", # time period selected on the chard
"chart_start": "2021-08-30 18:00:00", # when to start the chart
"chart_stop": "2021-09-06 16:39:00", # when to stop the chart
"comission": 0.01, # a comission to pay per transaction
"datapoints": [ # describes the data to use in the logic
{
"args": [ # args are passed to the transformer function
30
],
"transformer": "sma", # technical analysis function to run
"name": "sma_short" # reference point for use in logic
},
{
"args": [
90
],
"transformer": "sma",
"name": "sma_long"
},
],
"enter": [
[
"close", # field to reference, by default this is any column in the data file. Could also be a float or int
">", # operator to compare these to
"sma_long" # name of datapoint that was prevously defined
],
[
"close",
">",
"sma_short"
]
],
"exit": [
[
"close",
"<",
"sma_short"
]
],
"trailing_stop_loss": 0.05, # optional trailing stop loss
"exit_on_end": False, # at then end of the backtest, if true, the trade will exit
}
# backtests can also come from urls
# backtest = "https://raw.githubusercontent.com/jrmeier/fast-trade/master/sma_strategy.json"
# returns a mirror of the object, with errors if any
print(validate_backtest(backtest))
# also accepts urls
# datafile_path = "https://raw.githubusercontent.com/jrmeier/fast-trade/master/test/ohlcv_data.csv.txt"
datafile_path = "./BTCUSDT.csv"
# returns the summary object and the dataframe
result = run_backtest(backtest, datafile_path)
summary = result["summary"]
df = result["df"]
trade_log_df = result["trade_df"]
print(summary)
print(df.head())
```
## CLI
You can also use the package from the command line. Each command's specific help feature can be viewed by running `ft <command> -h`.
List the commands and their help.
`ft -h`
### Basic usage
This will download the last month of data for BTCUSD from binance.us and store in a `archive/` directory.
`ft download BTCUSD --exchange binance.us`
This will backtest a file with a strategy. By default, it will only show a summary of the backtest. However, if you want to save the results, add the `--save` flag and it will go the `saved_backtests/` directory.
`ft backtest ./strategy.json ./archive/BTCUSD_2022.csv`
You can also pass in url instead of files.
`ft backtest https://raw.githubusercontent.com/jrmeier/fast-trade/master/strategy.json ./archive/BTCUSD_2022.csv`
`ft backtest strategy.json https://example.com/BTCUSDT_2022.csv`
You can validate a backtest before you run it. This doesn't help with the data, but does help with the logic.
`ft validate stategy.json`
### Backteset Modifiers
Modifying the `chart_period`
`ft backtest ./strategy.json ./archive/BTCUSD_2022.csv --mods chart_period 1H`
Modifying the `chart_period` and the `trailing_stop_loss`
`ft backtest ./strategy.json ./archive/BTCUSD_2022.csv --mods chart_period 1H trailing_stop_loss .05`
Saving a test result
This generates creates the `saved_backtest` directory (if it doesn't exist), then inside of there, is another directory with a timestamp, with a chart, the backtest file, the summary, and the raw dataframe as a csv.
`ft backtest ./strategy.json ./archive/BTCUSD_2022.csv --save`
### DataDownloader
Download 1 minute kline/ohlcv from Binance and store them in CSVs in the `archive` path. You can rerun this command to keep the files updated.
It may take awhile to download all of the data the first time, so be patient. It only need to download all of it once, then it will be updated from the most recent date.
Check out the file [update_symbol_data.py](/fast_trade/update_symbol_data.py) if you want to see how it works.
Basic example
Download the last 30 days of BTCUSDT from binance.com
`python -m fast_trade download BTCUSDT`
`ft download SYMBOL --archive ARCHIVE_PATH --start START_DATE --end END_DATE --exchange=EXCHANGE`
Defaults are:
```python
EXCHANGE="binance.com" # can be binance.us
START= "2020-01-01" # start date
END= "2020-01-31" # end date
END='current date' # you'll probably never need this
ARCHIVE='./archive' # path the archive folder, which is where the CSVs are stored
```
Examples
downloads according to the defaults
`ft download`
download data for the symbol LTCBTC using the other defaults
`ft download LTCBTC`
download data starting January 2021
`ft download LTCBTC --start=2021-01-01`
## Testing
```bash
python -m pytest
```
## Coverage
```bash
coverage run -m pytest
coverage report -m
```
## Output
The output its a dictionary. The summary is a summary all the inputs and of the performace of the model. The df is a Pandas Dataframe, which contains all of the data used in the simulation. And the `trade_df` is a subset of the `df` frame which just has all the rows when there was an event. The `backtest` object is also returned, with the details of how the backtest was run.
Example output:
```python
{
"return_perc": -3.608,
"sharpe_ratio": -0.018705921376959495,
"buy_and_hold_perc": -13.661,
"median_trade_len": 1260.0,
"mean_trade_len": 1430.121951,
"max_trade_held": 4680.0,
"min_trade_len": 360.0,
"total_num_winning_trades": 46,
"total_num_losing_trades": 119,
"avg_win_per": 0.134,
"avg_loss_per": -0.081,
"best_trade_perc": 0.592,
"min_trade_perc": -2.588,
"median_trade_perc": -0.01,
"mean_trade_perc": -0.021,
"num_trades": 165,
"win_perc": 27.879,
"loss_perc": 72.121,
"equity_peak": 10053.901,
"equity_final": 9651.792,
"max_drawdown": 9651.792,
"total_fees": 81.745,
"first_tic": "2020-08-30 18:00:00",
"last_tic": "2020-09-06 16:39:00",
"total_tics": 3334,
"test_duration": 0.199153
}
```
## Backtest
The real goal of this project is to get to the point where these strategies can be generated and tested quickly and then be easily iterated on.
Below is an example of a very simple strategey. Basically, datapoints are used to build a list of datapoints to look at which must all be true to produce an enter or exit status for that tick.
Backtests include all the instructions needed to run the backtest minus the data.
### Backtest Requirements
- name:
- string, optional
- default: `None`
- description: a string for quick reference of the backtest
- chart_period:
- string, optional
- default: `"1Min"`
- description: a charting period string. allowed values are "Min" (minute), "T" (minute), "D" (day),"H" (hour)
- Ex.
- "1Min" is 1 minute
- "2H" is 2 hours
- "5D" is 5 days
- start: string or timestamp
- optional,
- default: `""`
- description: The time string of when to start the backtest with `%Y-%m-%d %H:%M:%S` date format or a timestamp. It will be tested
- Ex.
- `"2018-05-01 00:00:00"` May 1st, 2018 at midnight
- stop: sting or timestamp
- optional
- default: `""`
- description: The time string of when to stop the backtest with `%Y-%m-%d %H:%M:%S` date format or a timestamp
- Ex.
- `"2020-12-28 00:08:00"` December 28th, 2020 at 8am.
- `"2020-06-01"`June 6th, 2020
- `1590969600` (seconds) June 6th, 2020
- `1590969600000` (milliseconds) June 6th, 2020
- base_balance: float or int
- optional
- default: 1000
- description: The starting balance of trade account. Usually $ or "base" coins for cryptocurrencies.
- comission: float
- optional
- default: 0.0
- description: The "trading fee" per trade. This is subtracted per trade.
- enter: list,
- required
- default: `None`
- description: a list of [Logic](#LogicDetail)'s with instructions to compare the data on each tick. EVERY logic item must return True to ENTER the trade.
- any_enter: list,
- optional
- default: `None`
- description: a list of [Logic](#LogicDetail)'s with instructions to compare the data on each tick. ANY LOGIC ITEM can return True to ENTER the trade.
- exit: list
- required
- default: `None`
- description: a list of [Logic](#LogicDetail)'s with instructions to compare the data on each tick. EVERY LOGIC ITEM must return True to EXIT the trade.
- any_exit: list
- optional
- default: `None`
- description: a list of [Logic](#LogicDetail)'s with instructions to compare the data on each tick. ANY LOGIC ITEM can return True to EXIT the trade.
- datapoints: list
- optional
- default: `None`
- description: This describes how to create the datapoints. Each individual transformer has name that can be referenced in either the `enter` or `exit` logizs. For more information, see ([Datapoints](#Datapoints))
- trailing_stop_loss: float
- optional
- default `0`
- description: This sets a trailing stop loss, so the trade will exit immediately, without considering any other action. It is the percentage ot follow for example, to set a stop loss of 5%, set `0.05`
## Simple Moving Average Cross example
This is an example of a simple moving average cross backtest.
```python
{
"base_balance": 1000,
"chart_period": "5T",
"chart_start": "2020-08-30 18:00:00",
"chart_stop": "2020-09-06 16:39:00",
"comission": 0.01,
"datapoints": [
{
"args": [
30
],
"transformer": "sma",
"name": "sma_short"
},
{
"args": [
90
],
"transformer": "sma",
"name": "sma_long"
},
],
"enter": [
["close", ">", "sma_long"],
["close", ">", "sma_short"]
],
"exit": [["close", "<", "sma_short"]],
"trailing_stop_loss": 0.05,
"exit_on_end": False,
}
```
### LogicDetail
Each `logic` is contains a single `if` statement. The two variables are the first and last item in the list, with the operator to compare them `>`, `<` `=`.
To think of this easily, just say it out loud.
Ex.
If the close (closing price) at X time is greater than the "short_sma" (custom datapoint), then return True, else return False.
```python
[
"close", # datapoint or column in provided data
">", # operator for comparisson
"sma_short" # datapoint or column in provided data
]
```
Valid datapoints:
- open
- high
- low
- close
- volume
- any [datapoint](#Datapoints) (see [LogicExample1](#LogicExample1))
- any additional columns in your data file or your dataframe (see [LogicExample2](#LogicExample2))
#### LogicExample1
```python
[
"close", # valid datapoint, always provided
">", # logic to use to compare
"short" # valid custom datapoint, defined in datapoints
]
```
#### LogicExample2
```python
[
"rsi", # valid custom datapoint, should be defined in datapoints
"<", # logic to use to compare
70 # integer, float, or string
]
```
#### Logic Lookbacks
Logic lookbacks allow you to confirm a signal by checking the last N periods.
```python
[
"rsi", # valid custom datapoint, should be defined in datapoints
">", # logic to use to compare
30, # integer, float, or string
2 # optional, default 0, LogicalLookback number of periods to confirm this signal
]
```
### Datapoints
Datapoints are user defined technical indicators. You can select a defined [transformer](##Transformer) function to apply the technical analysis. They can reference data and calculate the new values to be referenced inside of any of the logics.
Simple SMA example
```python
{
"name": "sma_short", # transformer name
"transformer": "sma", # technical analysis function to be used
"args": [20], # arguments to pass to the function, for multiple args, add a "," behind each
}
```
## Transfomers (Technical Indicators)
Available transformer functions are from [FinTA](https://github.com/peerchemist/finta)
Custom datapoints can be added by setting a function name in the [datapoints](/fast_trade/transformers_map.py), then setting that equal to a function that takes in a dataframe as the first argument and whatever arguments passed in.
Note:
If a transfomer function returns multiple series, fast-trade will name concate the name of the series with the name of the transfomer function.
Example:
The `bbands` function returns two series, one for the upper band and one for the lower band. The name of the series will be `bbands_upper` and `bbands_lower`.
`bbands` returns 3 columns `upper_bb, middle_band, lower_bb`
Raw data
{
"_id": null,
"home_page": "https://github.com/jrmeier/fast-trade",
"name": "fast-trade",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3",
"maintainer_email": "",
"keywords": "backtesting,currency,ta,pandas,finance,numpy,analysis,technical analysis",
"author": "Jed Meier",
"author_email": "fast_trade@jedm.dev",
"download_url": "https://files.pythonhosted.org/packages/af/db/8abbe36f537c1e2dcc659162aacadb67d3de427ba16a5bf532efeb146e12/fast-trade-0.4.1.tar.gz",
"platform": null,
"description": "# Fast Trade\n\n[![License: LGPL v3](https://img.shields.io/github/license/jrmeier/fast-trade)](LICENSE)\n[![PyPI](https://img.shields.io/pypi/v/fast-trade.svg?style=flat-square)](https://pypi.org/project/fast-trade/)\n[![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/download/releases/3.7.0/)\n[![Python application](https://github.com/jrmeier/fast-trade/workflows/Python%20application/badge.svg)](https://github.com/jrmeier/fast-trade/actions)\n\nA library built with backtest portability and performance in mind for backtest trading strategies. There is also a [DataDownloader](#DataDownloader), which can be used to download compatible kline data from Binance (.com or .us)\n\n## Motivations\n\nStrategies are cheap. This is the main motivation behind fast-trade. Since a backtest is just a JSON object, strategies can be created, stored, modified, versioned, and re-run easily. Ideally, a backtest could be generated and tested quickly; fast-trade is just the library to handle that.\nFast Trade is also useful for quickly analyzing chart (`ohlcv`) data and downloading it.\n\n## Beta Testing\n\nI'm using this library to build a platform (live data, charting, paper trading, etc.) and I'm looking for beta testers. If you like this library, send me an email at fasttrade@jedm.dev.\n\n## Contributing\n\nIf you'd like to add a feature, fix a bug, or something else, please clone the repo and fork it. When you're ready, open a PR into this main repo.\n\nTo get started with local dev, clone the repo, set up a virtual env, source it, then install the dev requirements.\n\n```bash\ngit clone git@github.com:<YOUR GIT USERNAME>/fast-trade.git\ncd ./fast-trade\npython -m venv .fast_trade\nsource .fast_trade/bin/activate\npip install -r dev_requirements.txt\n```\n\nTo generate testing coverage, run\n\n```bash\ncoverage run -m pytest\ncoverage report -m\n```\n\n## Install\n\n```bash\npip install fast-trade\n```\n\n## Usage\n\nSee [sma_strategy.json](./sma_strategy.json) and [strategy.json](./strategy.json) for an example strategy. The basic idea is you describe the \"datapoints\" then compare them in the \"logics\". The \"datapoints\" describe the technical analysis functions to run, and the \"logics\" describe the logic to use to determine when to enter and exit trades.\n\nExample backtest script\n\n```python\nfrom fast_trade import run_backtest, validate_backtest\n\nbacktest = {\n \"base_balance\": 1000, # start with a balance of 1000\n \"chart_period\": \"5Min\", # time period selected on the chard\n \"chart_start\": \"2021-08-30 18:00:00\", # when to start the chart\n \"chart_stop\": \"2021-09-06 16:39:00\", # when to stop the chart\n \"comission\": 0.01, # a comission to pay per transaction \n \"datapoints\": [ # describes the data to use in the logic\n {\n \"args\": [ # args are passed to the transformer function\n 30\n ],\n \"transformer\": \"sma\", # technical analysis function to run\n \"name\": \"sma_short\" # reference point for use in logic\n },\n {\n \"args\": [\n 90\n ],\n \"transformer\": \"sma\",\n \"name\": \"sma_long\"\n },\n ],\n \"enter\": [\n [\n \"close\", # field to reference, by default this is any column in the data file. Could also be a float or int\n \">\", # operator to compare these to\n \"sma_long\" # name of datapoint that was prevously defined\n ],\n [\n \"close\",\n \">\",\n \"sma_short\"\n ]\n ],\n \"exit\": [\n [\n \"close\",\n \"<\",\n \"sma_short\"\n ]\n ],\n \"trailing_stop_loss\": 0.05, # optional trailing stop loss \n \"exit_on_end\": False, # at then end of the backtest, if true, the trade will exit\n}\n# backtests can also come from urls\n# backtest = \"https://raw.githubusercontent.com/jrmeier/fast-trade/master/sma_strategy.json\"\n\n# returns a mirror of the object, with errors if any\nprint(validate_backtest(backtest))\n\n# also accepts urls \n# datafile_path = \"https://raw.githubusercontent.com/jrmeier/fast-trade/master/test/ohlcv_data.csv.txt\"\ndatafile_path = \"./BTCUSDT.csv\"\n\n# returns the summary object and the dataframe\nresult = run_backtest(backtest, datafile_path)\n\nsummary = result[\"summary\"]\ndf = result[\"df\"]\ntrade_log_df = result[\"trade_df\"]\n\nprint(summary)\nprint(df.head())\n```\n## CLI\n\nYou can also use the package from the command line. Each command's specific help feature can be viewed by running `ft <command> -h`.\n\nList the commands and their help.\n`ft -h`\n\n### Basic usage\n\nThis will download the last month of data for BTCUSD from binance.us and store in a `archive/` directory.\n\n`ft download BTCUSD --exchange binance.us`\n\nThis will backtest a file with a strategy. By default, it will only show a summary of the backtest. However, if you want to save the results, add the `--save` flag and it will go the `saved_backtests/` directory.\n\n`ft backtest ./strategy.json ./archive/BTCUSD_2022.csv`\n\nYou can also pass in url instead of files.\n\n`ft backtest https://raw.githubusercontent.com/jrmeier/fast-trade/master/strategy.json ./archive/BTCUSD_2022.csv`\n\n`ft backtest strategy.json https://example.com/BTCUSDT_2022.csv`\n\nYou can validate a backtest before you run it. This doesn't help with the data, but does help with the logic.\n`ft validate stategy.json`\n\n### Backteset Modifiers\n\nModifying the `chart_period`\n\n`ft backtest ./strategy.json ./archive/BTCUSD_2022.csv --mods chart_period 1H`\n\nModifying the `chart_period` and the `trailing_stop_loss`\n\n`ft backtest ./strategy.json ./archive/BTCUSD_2022.csv --mods chart_period 1H trailing_stop_loss .05`\n\nSaving a test result\nThis generates creates the `saved_backtest` directory (if it doesn't exist), then inside of there, is another directory with a timestamp, with a chart, the backtest file, the summary, and the raw dataframe as a csv.\n`ft backtest ./strategy.json ./archive/BTCUSD_2022.csv --save`\n\n### DataDownloader\n\nDownload 1 minute kline/ohlcv from Binance and store them in CSVs in the `archive` path. You can rerun this command to keep the files updated.\nIt may take awhile to download all of the data the first time, so be patient. It only need to download all of it once, then it will be updated from the most recent date.\nCheck out the file [update_symbol_data.py](/fast_trade/update_symbol_data.py) if you want to see how it works.\n\nBasic example\nDownload the last 30 days of BTCUSDT from binance.com\n`python -m fast_trade download BTCUSDT`\n\n`ft download SYMBOL --archive ARCHIVE_PATH --start START_DATE --end END_DATE --exchange=EXCHANGE`\n\nDefaults are:\n\n```python\nEXCHANGE=\"binance.com\" # can be binance.us\nSTART= \"2020-01-01\" # start date\nEND= \"2020-01-31\" # end date\nEND='current date' # you'll probably never need this\nARCHIVE='./archive' # path the archive folder, which is where the CSVs are stored\n```\n\nExamples\n\ndownloads according to the defaults\n\n`ft download`\n\ndownload data for the symbol LTCBTC using the other defaults\n\n`ft download LTCBTC`\n\ndownload data starting January 2021\n`ft download LTCBTC --start=2021-01-01`\n\n## Testing\n\n```bash\npython -m pytest\n```\n\n## Coverage\n\n```bash\ncoverage run -m pytest\ncoverage report -m\n```\n\n## Output\n\nThe output its a dictionary. The summary is a summary all the inputs and of the performace of the model. The df is a Pandas Dataframe, which contains all of the data used in the simulation. And the `trade_df` is a subset of the `df` frame which just has all the rows when there was an event. The `backtest` object is also returned, with the details of how the backtest was run.\n\nExample output:\n\n```python\n{\n \"return_perc\": -3.608,\n \"sharpe_ratio\": -0.018705921376959495,\n \"buy_and_hold_perc\": -13.661,\n \"median_trade_len\": 1260.0,\n \"mean_trade_len\": 1430.121951,\n \"max_trade_held\": 4680.0,\n \"min_trade_len\": 360.0,\n \"total_num_winning_trades\": 46,\n \"total_num_losing_trades\": 119,\n \"avg_win_per\": 0.134,\n \"avg_loss_per\": -0.081,\n \"best_trade_perc\": 0.592,\n \"min_trade_perc\": -2.588,\n \"median_trade_perc\": -0.01,\n \"mean_trade_perc\": -0.021,\n \"num_trades\": 165,\n \"win_perc\": 27.879,\n \"loss_perc\": 72.121,\n \"equity_peak\": 10053.901,\n \"equity_final\": 9651.792,\n \"max_drawdown\": 9651.792,\n \"total_fees\": 81.745,\n \"first_tic\": \"2020-08-30 18:00:00\",\n \"last_tic\": \"2020-09-06 16:39:00\",\n \"total_tics\": 3334,\n \"test_duration\": 0.199153\n}\n```\n\n## Backtest\n\nThe real goal of this project is to get to the point where these strategies can be generated and tested quickly and then be easily iterated on.\n\nBelow is an example of a very simple strategey. Basically, datapoints are used to build a list of datapoints to look at which must all be true to produce an enter or exit status for that tick.\n\nBacktests include all the instructions needed to run the backtest minus the data.\n\n### Backtest Requirements\n\n- name:\n - string, optional\n - default: `None`\n - description: a string for quick reference of the backtest\n- chart_period:\n - string, optional\n - default: `\"1Min\"`\n - description: a charting period string. allowed values are \"Min\" (minute), \"T\" (minute), \"D\" (day),\"H\" (hour)\n - Ex.\n - \"1Min\" is 1 minute\n - \"2H\" is 2 hours\n - \"5D\" is 5 days\n- start: string or timestamp\n - optional,\n - default: `\"\"`\n - description: The time string of when to start the backtest with `%Y-%m-%d %H:%M:%S` date format or a timestamp. It will be tested\n - Ex.\n - `\"2018-05-01 00:00:00\"` May 1st, 2018 at midnight\n\n- stop: sting or timestamp\n - optional\n - default: `\"\"`\n - description: The time string of when to stop the backtest with `%Y-%m-%d %H:%M:%S` date format or a timestamp\n - Ex.\n - `\"2020-12-28 00:08:00\"` December 28th, 2020 at 8am.\n - `\"2020-06-01\"`June 6th, 2020\n - `1590969600` (seconds) June 6th, 2020\n - `1590969600000` (milliseconds) June 6th, 2020\n\n- base_balance: float or int\n - optional\n - default: 1000\n - description: The starting balance of trade account. Usually $ or \"base\" coins for cryptocurrencies.\n\n- comission: float\n - optional\n - default: 0.0\n - description: The \"trading fee\" per trade. This is subtracted per trade.\n\n- enter: list,\n - required\n - default: `None`\n - description: a list of [Logic](#LogicDetail)'s with instructions to compare the data on each tick. EVERY logic item must return True to ENTER the trade.\n\n- any_enter: list,\n - optional\n - default: `None`\n - description: a list of [Logic](#LogicDetail)'s with instructions to compare the data on each tick. ANY LOGIC ITEM can return True to ENTER the trade.\n\n- exit: list\n - required\n - default: `None`\n - description: a list of [Logic](#LogicDetail)'s with instructions to compare the data on each tick. EVERY LOGIC ITEM must return True to EXIT the trade.\n\n- any_exit: list\n - optional\n - default: `None`\n - description: a list of [Logic](#LogicDetail)'s with instructions to compare the data on each tick. ANY LOGIC ITEM can return True to EXIT the trade.\n\n- datapoints: list\n - optional\n - default: `None`\n - description: This describes how to create the datapoints. Each individual transformer has name that can be referenced in either the `enter` or `exit` logizs. For more information, see ([Datapoints](#Datapoints))\n\n- trailing_stop_loss: float\n - optional\n - default `0`\n - description: This sets a trailing stop loss, so the trade will exit immediately, without considering any other action. It is the percentage ot follow for example, to set a stop loss of 5%, set `0.05`\n\n## Simple Moving Average Cross example\n\nThis is an example of a simple moving average cross backtest.\n\n```python\n{\n \"base_balance\": 1000,\n \"chart_period\": \"5T\",\n \"chart_start\": \"2020-08-30 18:00:00\",\n \"chart_stop\": \"2020-09-06 16:39:00\",\n \"comission\": 0.01,\n \"datapoints\": [\n {\n \"args\": [\n 30\n ],\n \"transformer\": \"sma\",\n \"name\": \"sma_short\"\n },\n {\n \"args\": [\n 90\n ],\n \"transformer\": \"sma\",\n \"name\": \"sma_long\"\n },\n ],\n \"enter\": [\n [\"close\", \">\", \"sma_long\"],\n [\"close\", \">\", \"sma_short\"]\n ],\n \"exit\": [[\"close\", \"<\", \"sma_short\"]],\n \"trailing_stop_loss\": 0.05,\n \"exit_on_end\": False,\n}\n```\n\n### LogicDetail\n\nEach `logic` is contains a single `if` statement. The two variables are the first and last item in the list, with the operator to compare them `>`, `<` `=`.\n\nTo think of this easily, just say it out loud.\nEx.\n\nIf the close (closing price) at X time is greater than the \"short_sma\" (custom datapoint), then return True, else return False.\n\n```python\n[\n \"close\", # datapoint or column in provided data\n \">\", # operator for comparisson\n \"sma_short\" # datapoint or column in provided data\n]\n```\n\nValid datapoints:\n\n- open\n- high\n- low\n- close\n- volume\n- any [datapoint](#Datapoints) (see [LogicExample1](#LogicExample1))\n- any additional columns in your data file or your dataframe (see [LogicExample2](#LogicExample2))\n\n#### LogicExample1\n\n```python\n [\n \"close\", # valid datapoint, always provided\n \">\", # logic to use to compare\n \"short\" # valid custom datapoint, defined in datapoints\n ]\n```\n\n#### LogicExample2\n\n```python\n [\n \"rsi\", # valid custom datapoint, should be defined in datapoints\n \"<\", # logic to use to compare\n 70 # integer, float, or string \n ]\n```\n\n#### Logic Lookbacks\n\nLogic lookbacks allow you to confirm a signal by checking the last N periods.\n\n```python\n [\n \"rsi\", # valid custom datapoint, should be defined in datapoints\n \">\", # logic to use to compare\n 30, # integer, float, or string\n 2 # optional, default 0, LogicalLookback number of periods to confirm this signal\n ]\n```\n\n### Datapoints\n\nDatapoints are user defined technical indicators. You can select a defined [transformer](##Transformer) function to apply the technical analysis. They can reference data and calculate the new values to be referenced inside of any of the logics.\n\nSimple SMA example\n\n```python\n {\n \"name\": \"sma_short\", # transformer name\n \"transformer\": \"sma\", # technical analysis function to be used\n \"args\": [20], # arguments to pass to the function, for multiple args, add a \",\" behind each\n }\n```\n\n## Transfomers (Technical Indicators)\n\nAvailable transformer functions are from [FinTA](https://github.com/peerchemist/finta)\n\nCustom datapoints can be added by setting a function name in the [datapoints](/fast_trade/transformers_map.py), then setting that equal to a function that takes in a dataframe as the first argument and whatever arguments passed in.\n\nNote:\n \nIf a transfomer function returns multiple series, fast-trade will name concate the name of the series with the name of the transfomer function.\n\nExample:\n\nThe `bbands` function returns two series, one for the upper band and one for the lower band. The name of the series will be `bbands_upper` and `bbands_lower`.\n\n`bbands` returns 3 columns `upper_bb, middle_band, lower_bb`\n",
"bugtrack_url": null,
"license": "GNU AGPLv3",
"summary": "About low code backtesting library utilizing pandas and technical analysis indicators",
"version": "0.4.1",
"split_keywords": [
"backtesting",
"currency",
"ta",
"pandas",
"finance",
"numpy",
"analysis",
"technical analysis"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4602d32bdfce0301dc5821453f3d173c73e92d07544d4e429984ed3ac86a1d1b",
"md5": "a2ebe4edab61b0942e33b57b46946cde",
"sha256": "18cd2404a189e12d0c33380947691950a588d88096d06f4c54e57bc636a6b3da"
},
"downloads": -1,
"filename": "fast_trade-0.4.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a2ebe4edab61b0942e33b57b46946cde",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3",
"size": 38438,
"upload_time": "2023-01-31T16:18:15",
"upload_time_iso_8601": "2023-01-31T16:18:15.063614Z",
"url": "https://files.pythonhosted.org/packages/46/02/d32bdfce0301dc5821453f3d173c73e92d07544d4e429984ed3ac86a1d1b/fast_trade-0.4.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "afdb8abbe36f537c1e2dcc659162aacadb67d3de427ba16a5bf532efeb146e12",
"md5": "09e88a5cb71bd05924dd5f10fbdc549c",
"sha256": "e736fe490efd5cbb98830e3fe94fb0cb51a1ba5b2755ee64166d7b3d385d4eac"
},
"downloads": -1,
"filename": "fast-trade-0.4.1.tar.gz",
"has_sig": false,
"md5_digest": "09e88a5cb71bd05924dd5f10fbdc549c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3",
"size": 45925,
"upload_time": "2023-01-31T16:18:17",
"upload_time_iso_8601": "2023-01-31T16:18:17.231644Z",
"url": "https://files.pythonhosted.org/packages/af/db/8abbe36f537c1e2dcc659162aacadb67d3de427ba16a5bf532efeb146e12/fast-trade-0.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-31 16:18:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "jrmeier",
"github_project": "fast-trade",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [],
"lcname": "fast-trade"
}