Installation
$ 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)
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
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:
from bokeh.io import output_notebook, show, push_notebook
output_notebook()
coin.plot_candles()
Step 3: Create a trading strategy
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
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
---------------------------------------
Metadata
Release files for futon 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| futon-1.0.0.tar.gz | 35.0 kB | Without provenance | Details for futon-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| futon-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for futon-1.0.0-py3-none-any.whl |
Total release size: 71.6 kB
Release files / futon-1.0.0.tar.gz
| Download URL | futon-1.0.0.tar.gz |
|---|---|
| Size | 35.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c8cf9e2782709b66dd367dd96fc30930a205715e07d5a0a7228dc3a16a640755
|
|
BLAKE2b-256 checksum How to use checksums |
4b65fe8b1eeaba6b8dda34f51cb2098d0f4ed482fdc6d2ec5767a978f3de5599
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|
Release files / futon-1.0.0-py3-none-any.whl
| Download URL | futon-1.0.0-py3-none-any.whl |
|---|---|
| Size | 36.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3db290e361c6dfd34204dae8b6f5a325c6427a663a0c154c758a87bfacf40127
|
|
BLAKE2b-256 checksum How to use checksums |
9608f8144812ad8b1950cb8d2e9a8fc7126ee0797e6da75a34077b0627c70083
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|
Security for futon 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.