Metadata-Version: 2.1
Name: futon
Version: 1.0.0
Summary: Create automated bots that trade for you while you sleep
Home-page: https://github.com/agrawal-rohit/futon
License: GPL-3.0-only
Keywords: Stocks,Cryptocurrencies,Algorithmic Trading,Backtesting,Trading bots
Author: Rohit Agrawal
Author-email: rohitagrawalofficialmail@gmail.com
Requires-Python: >=3.7,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: Requests (==2.25.1)
Requires-Dist: TA_Lib (==0.4.20)
Requires-Dist: binance (==0.3)
Requires-Dist: bokeh (==2.3.2)
Requires-Dist: numpy (>=1.20.3,<2.0.0)
Requires-Dist: pandas (>=1.1.5,<2.0.0)
Requires-Dist: python_binance (==1.0.10)
Requires-Dist: tqdm (==4.61.1)
Requires-Dist: websocket_client (==1.1.0)
Project-URL: Documentation, https://github.com/agrawal-rohit/futon
Project-URL: Repository, https://github.com/agrawal-rohit/futon
Description-Content-Type: text/markdown

<p align="center">
<img width="341" alt="Logo" src="https://user-images.githubusercontent.com/29514438/122650855-bd657b00-d152-11eb-8296-1407f832bd91.png">
</p>

<p align="center">
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/workflow/status/agrawal-rohit/futon/Build">
<!-- <img alt="PyPI - Status" src="https://img.shields.io/pypi/status/futon"> -->
<!-- <img alt="Codecov" src="https://img.shields.io/codecov/c/github/agrawal-rohit/futon"> -->
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/futon">
<img alt="PyPI" src="https://img.shields.io/pypi/v/futon">
<img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/futon">
<img alt="CodeFactor Grade" src="https://img.shields.io/codefactor/grade/github/agrawal-rohit/futon">
<img alt="GitHub" src="https://img.shields.io/github/license/agrawal-rohit/futon">
</p>

# Installation

```shell
$ pip install futon
```

# Usage

## Step 1: Initialize a data provider

A data provider refers to a source from where an instruments historical data can be fetched. Currently, **Binance** is the only supported provider (more are being added actively)

```python
from futon.data.providers import Binance

# Add your developer API keys here
api_key = '<API KEY>'
secret_key = '<API SECRET>'

binance = Binance(api_key, secret_key)
```

## Step 2: Choose an instrument

```python
coin = futon.instruments.Crypto(base_asset = 'DOGE',
                                quote_asset = 'USDT',
                                provider = binance,
                                interval = '30-min',
                                start_date = '2021-05-01 00:00:00')
```

When you initialize an instrument, historical data for the instrument is downloaded by _default_

If you're a chart guy, then you can create an interactive OHLCV chart right in your jupyter notebook:

```python
from bokeh.io import output_notebook, show, push_notebook
output_notebook()

coin.plot_candles()
```

![Candlestick Plot](imgs/candlestick_plot.png)

## Step 3: Create a trading strategy

```python
from futon.strategy import TradingStrategy

class MACDCrossover(TradingStrategy):
    def setup(self):
        self.macd = futon.indicators.MACD(fastperiod = 6,
                                            slowperiod = 18,
                                            signalperiod = 5,
                                            plot_separately = True)

        self.indicators = [self.macd]

    def logic(self, account, lookback):
        try:
            today = lookback.iloc[-1]

            macd_today, signal_today, _ = self.macd.lookback[-1]
            macd_yest, signal_yest, _ = self.macd.lookback[-2]

            # Buying
            buy_signal = (macd_today > signal_today) and (macd_yest < signal_yest)
            if buy_signal:
                entry_price   = today.close
                entry_capital = account.buying_power
                account.buy(entry_capital=entry_capital, entry_price=entry_price)

            # Selling
            sell_signal = (macd_today < signal_today) and (macd_yest > signal_yest)

            if sell_signal:
                percent = 1
                exit_price = today.close
                account.sell(percent=percent, current_price=exit_price)

        except Exception as e:
            print('ERROR:', e)

strat = MACDCrossover(coin)
```

## Step 4: Run a backtest on historical data

```python
strat.backtest(start_date = '2021-06-1 00:00:00', commision = 0.001, show_trades = True)
```

**Output**

```
Performing backtest from: 01 June, 2021 (00:00:00) to 21 June, 2021 (16:00:00)

-------------- Results ----------------

Relative Returns: -2.55%
Relative Profit: -25.49

Strategy     : -36.4%
Net Profit   : -363.96

Buy and Hold : -33.85%
Net Profit   : -338.47

Buys        : 75
Sells        : 75
--------------------
Total Trades : 150

---------------------------------------
```

![Backtest Plot](imgs/backtest.png)

