Skip to content

AwesomeTrading/lettrade

Repository files navigation

LetTrade

Documentation Code Coverage PyPI PyPI Python Version PyPI Downloads

A lightweight trading framework compatible with Stock, Forex, Crypto... markets

Inspired by freqtrade, backtrader, backtesting.py...

Let make algo trading simple :)

Find more at Documentation

Installation

Stable version

pip install lettrade

Developing version

pip install git+https://git@github.com/AwesomeTrading/lettrade.git@main

Example

import talib.abstract as ta

from lettrade.all import DataFeed, Strategy, let_backtest, crossover, crossunder


class SmaCross(Strategy):
    ema1_period = 9
    ema2_period = 21

    def indicators(self, df: DataFeed):
        df["ema1"] = ta.EMA(df, timeperiod=self.ema1_period)
        df["ema2"] = ta.EMA(df, timeperiod=self.ema2_period)

        df["crossover"] = crossover(df.ema1, df.ema2)
        df["crossunder"] = crossunder(df.ema1, df.ema2)

    def next(self, df: DataFeed):
        if df.crossover.l[-1]:
            self.buy(0.1)
        elif df.crossunder.l[-1]:
            self.sell(0.1)

lt = let_backtest(
    strategy=SmaCross,
    datas="example/data/data/EURUSD_5m_0_1000.csv",
)

lt.run()
lt.plot()
# Strategy                       <class 'SmaCross'>
Start                     2024-05-13 21:15:00+00:00
End                       2024-05-17 08:30:00+00:00
Duration                            3 days 11:15:00
Start Balance [$]                             10000
Equity [$]                                  10000.0
PL [$]                                          0.0
PL [%]                                          0.0
Buy & Hold PL [%]                               2.0
Max. Drawdown [%]                            -33.08
Avg. Drawdown [%]                             -5.58
Max. Drawdown Duration            688 days 00:00:00
Avg. Drawdown Duration             41 days 00:00:00
                                                   
# Trades                                         34
Best Trade [%]                               0.0007
Worst Trade [%]                           -0.000732
Profit Factor                                  2.13
SQN                                            1.78

Plot

Start a strategy

All example in example/ directory

Download data

python -m example.data.yfinance

Backtest strategy

python -m example.strategy.backtest_sma_cross

Live Trading

Official

  • MetaTrader: Support MetaTrader 5 Terminal trading
  • CCXT: [WIP] Support most of cryptocurrency exchange from CCXT library

Development

Set up conda environment

conda create -y -n LetTrade python=3.10
conda activate LetTrade
conda install -c conda-forge ta-lib
pip install -r requirements-dev.txt