Submit Feedback

Algorithmic investing reinvented.

Backtest and deploy algorithmic strategies with AI.

Backtest Strategies with AI (Alpha)

This app is currently in Alpha and we are actively squashing bugs, thanks for your patience!

Define Strategy:

Register for free to access more AI models.

💡

ideas remaining

Register for free to get 100 free ideas per month (only during Alpha).

Re-running backtest with new dates...

Strategy Analytics

Annual ReturnAverage LossAverage WinCalmar RatioMaximum DrawdownProfit FactorSharpe RatioWin Rate
21.33%$570.43$1021.020.004844.33%1.440.6244.62%

Backtested historical performance does not necessarily represent future performance.

Strategy Performance

Flow Diagram

Yes

Yes

No

No

Yes

No

Yes

No

Start Trading Day

Update TQQQ Price and Indicators

Calculate Current and Previous EMA Difference

Is Current EMA Diff > Previous EMA Diff?

Holding No Position?

Calculate Buy Size and Execute Buy Order

Hold Position

Is Current EMA Diff < Previous EMA Diff and Holding Position?

Execute Sell Order

More Trading Days?

End Trading

Generated Code

# Setup logging configuration
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

# Define your strategy
class ExampleStrategy(bt.Strategy):  # You must leave this name ExampleStrategy the same or the strategy will not run, you can take out this comment in your generated code
    # implement new params based on user specification
    params = (
        ('short_period', 12),  # Short term EMA period
        ('long_period', 26),  # Long term EMA period
    )

    def __init__(self):
        # Initialize EMA indicators with dynamic periods based on strategy parameters
        self.short_ema = bt.indicators.EMA(self.datas[0], period=self.params.short_period)
        self.long_ema = bt.indicators.EMA(self.datas[0], period=self.params.long_period)
        self.ema_diff = self.short_ema - self.long_ema
        self.prev_ema_diff = self.ema_diff(-1)
        logging.info(f'EMA Indicators Initialized: Short={self.params.short_period}, Long={self.params.long_period}')

    def next(self):
        # Calculate the current and previous EMA differences
        curr_ema_diff = self.ema_diff[0]
        prev_ema_diff = self.prev_ema_diff[0]

        # Log for tracking
        logging.info(f'Date: {self.datas[0].datetime.date(0)}, Current EMA Diff: {curr_ema_diff}, Previous EMA Diff: {prev_ema_diff}')

        # Check for buy signal
        if curr_ema_diff > prev_ema_diff and not self.getposition(self.datas[0]).size:
            size = int(self.broker.get_cash() / self.datas[0].close[0])  # Calculate size based on current cash
            self.buy(size=size)  # Execute buy order
            logging.info(f'BUY ORDER PLACED on {self.datas[0].datetime.date(0)}, Size: {size}, EMA Diff: {curr_ema_diff}, Cash: {self.broker.get_cash()}')

        # Check for sell signal
        elif curr_ema_diff < prev_ema_diff and self.getposition(self.datas[0]).size:
            self.sell(size=self.position.size)  # Execute sell order using current position size
            logging.info(f'SELL ORDER PLACED on {self.datas[0].datetime.date(0)}, Size: {self.position.size}, EMA Diff: {curr_ema_diff}, Cash: {self.broker.get_cash()}')

# Adjust start and end dates for data fetching to account for the lookback period
lookback_period = max(26, 12)  # The largest period used in EMA calculation
adjusted_start_date = (start_date - pd.Timedelta(days=lookback_period)).strftime('%Y-%m-%d')
extended_end_date = (end_date + pd.Timedelta(days=lookback_period)).strftime('%Y-%m-%d')

# Fetch and add data to Cerebro
# Note: Adjust the stock ticker to TQQQ as specified by the user
leveraged_etf_data = bt.feeds.PandasData(dataname=yf.download('TQQQ', start=adjusted_start_date, end=extended_end_date), name='TQQQ')
cerebro.adddata(leveraged_etf_data)

globals()['lookback_period'] = lookback_period  # Update global variable for lookback period usage

You need to connect a brokerage account to deploy strategies.

Select a broker to connect:

Your Saved Ideas

You are not following any algorithms yet.

Your Invested Ideas

You have not invested in any algorithms yet.

Features

Test Pass Quant Pass Trade Pass Enterprise
Test trading strategies without code
Test stocks/futures/cryptocurrency/forex strategies
GPT-4o and mini models
Fine tuned/thinking/proprietary Models
Dedicated API keys
Fine tuned models for your organization's tech stack
Ideas per Month 3 ?? ??? Unlimited
Basic analytics
Detailed analytics
Test options strategies*
Minute resolution data*
Save strategies*
Iterative strategy updates with AI assistant*
Deploy strategy with exchange*
View code structure
Fees Free $TBA $TBA $TBA
* = Features on roadmap

By using this app, you agree to: https://www.statisfund.com/legal - This app is built and managed by Statis Fund LLC - for questions and support email shawn@statisfund.com