Backtesting simple SMA strategy
Select the data
with now() - interval 12 month as start_date, toStartOfMinute(now()) as end_date, 10000 as initial_cash,
-- Fetching BTC data for the specified period
btc_data as (SELECT timestamp,
argMaxMerge(close) as close
FROM public_data.candle_1m
WHERE market = 'BTC-USD'
AND exchange = 'coinbase'
and timestamp > start_date
and timestamp < end_date
GROUP BY timestamp)timestamp
close
Compute the SMA
timestamp
close
sma50
sma200
Generate the signals and extract the trades
timestamp
price
signal
trade_id
Compute strategy performance
trade_id
entry_date
exit_date
entry_price
exit_price
signal
trade_return
Sharpe Ratio
Full example
number of candles
Execution time