Backtest and deploy algorithmic strategies with AI.
This app is currently in Alpha and we are actively squashing bugs, thanks for your patience!
Register for free to access more AI models.
ideas remaining
# Setup logging configuration
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Define your strategy
class ExampleStrategy(bt.Strategy):
params = (
('rebalance_period', 21), # Rebalance period in trading days (monthly roughly for trading days)
)
def __init__(self):
self.rebalance_counter = 0
def next(self):
# Check for rebalancing condition
if self.rebalance_counter % self.params.rebalance_period == 0:
self.rebalance_portfolio()
self.rebalance_counter += 1
def rebalance_portfolio(self):
# Symbols for the 'Magnificent 7' stocks
symbols = ['AAPL', 'AMZN', 'GOOGL', 'MSFT', 'META', 'NVDA', 'TSLA']
positions = [self.getposition(data).size for data in self.datas]
cash = self.broker.get_cash()
total_value = cash + sum([pos * data.close[0] for pos, data in zip(positions, self.datas)])
equal_value = total_value / len(symbols)
# Iterate over all stocks and rebalance each
for i, data in enumerate(self.datas):
current_value = positions[i] * data.close[0]
target_size = int((equal_value - current_value) / data.close[0])
if target_size > 0:
self.buy(data=data, size=target_size)
elif target_size < 0:
self.sell(data=data, size=abs(target_size))
logging.info(f'Rebalanced {data._name}: New Target Size: {target_size} | Date: {self.datas[0].datetime.date(0)} | Close Price: {data.close[0]}')
# Adjust dates for lookback period
lookback_period = 0 # No specific indicator, zero lookback
# Fetch and add data for each stock
symbols = {
'AAPL': 'AAPL',
'AMZN': 'AMZN',
'GOOGL': 'GOOGL',
'MSFT': 'MSFT',
'META': 'META',
'NVDA': 'NVDA',
'TSLA': 'TSLA',
}
# Fetch and add data to Cerebro, fetching multiple tickers at once
for name, ticker in symbols.items():
data = bt.feeds.PandasData(dataname=yf.download(ticker, start_date, end_date), name=name)
cerebro.adddata(data)
globals()['lookback_period'] = lookback_period # Update global variable for lookback period usage
Test Pass | Quant Pass | Trade Pass | Enterprise | |
---|---|---|---|---|
Test trading strategies without code | ✓ | ✓ | ✓ | ✓ |
Test stocks/futures/cryptocurrency/forex strategies | ✓ | ✓ | ✓ | ✓ |
GPT-3.5 Turbo | ✓ | ✓ | ✓ | ✓ |
GPT-4o Turbo/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 |
Operation | Path | Description | Examples |
---|---|---|---|
Basics | N/A | Append the requested path based on the operation needed followed by the ticker symbol. Replace query parameters like <start> , <end> , <interval> , and <period> as needed. |
Example |
Get Stock Data | /data/{ticker} | Retrieve historical data for a specific stock ticker. Specify the start date, end date, interval, and period as query parameters. | Example |
Get Indicator Data | /indicator/{indicator}/{ticker} | Retrieve historical indicator data for a specific stock ticker. Specify the start date, end date, interval, and period as query parameters. | Example |
Calculate Moving Average | /moving_average/{ticker} | Calculate the moving average for a specific stock ticker. Specify the number of days, start date, end date, interval, and period as query parameters. | Example |
Get Volume Data | /volume/{ticker} | Retrieve the trading volume for a specific stock ticker. Specify the start date, end date, interval, and period as query parameters. | Example |
Calculate Volatility | /volatility/{ticker} | Calculate the volatility for a specific stock ticker. Specify the start date, end date, interval, and period as query parameters. | Example |
Calculate Price Change | /price_change/{ticker} | Calculate the price change for a specific stock ticker. Specify the start date, end date, interval, and period as query parameters. | Example |
Calculate Bollinger Bands | /bollinger_bands/{ticker} | Calculate the Bollinger Bands for a specific stock ticker. Specify the window, start date, end date, and interval as query parameters. | Example |
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