Skip to content
TotalFinance

Backtest a strategy

Test a moving-average rule on your own price data, with next-bar execution, commissions, equity and drawdown.

Run it

Live, in your browser. Nothing leaves this page.

Local

Daily OHLC bars, oldest first. Paste or upload CSV/TSV with date, open, high, low, close (volume optional).

Synthetic uptrend with pullbacks (seed 7, not market data)

250 bars · 2025-01-02 → 2025-12-17

Synthetic
Preview rows
dateopenhighlowclosevolume
2025-01-02100.83101.2699.82100.04894440
2025-01-03100.32100.6598.799.291908571
2025-01-0699.65101.0999.2100.762282565
… 245 more rows …
2025-12-16135.29137.27134.61136.231345301
2025-12-17135.54135.95133.05133.921105532
20

sessions · integer

$10,000.00

USD

10 bp

basis points · 10 = 0.1%

Change any input; everything updates.

Final value
$12,258.75
USD
Total return
22.59%
Maximum drawdown
11.23%
from the running peak
Sharpe ratio
1.21803
annualized · 0% risk-free
Entries
11
42 fills incl. rebalancing
Price, signals, equity and drawdownSynthetic uptrend with pullbacks (seed 7, not market data). Entries and exits are drawn on the bar where they fill, one bar after the signal.
  • Up bar (hollow)
  • Down bar (filled)
  • SMA 20
Enter at the 2025-01-30 close (signal on 2025-01-29)Exit at the 2025-02-10 close (signal on 2025-02-07)Enter at the 2025-02-14 close (signal on 2025-02-13)Exit at the 2025-02-19 close (signal on 2025-02-18)Enter at the 2025-02-21 close (signal on 2025-02-20)Exit at the 2025-03-05 close (signal on 2025-03-04)Enter at the 2025-03-10 close (signal on 2025-03-07)Exit at the 2025-03-11 close (signal on 2025-03-10)Enter at the 2025-03-18 close (signal on 2025-03-17)Exit at the 2025-03-21 close (signal on 2025-03-20)Enter at the 2025-03-24 close (signal on 2025-03-21)Exit at the 2025-04-29 close (signal on 2025-04-28)Enter at the 2025-06-03 close (signal on 2025-06-02)Exit at the 2025-07-29 close (signal on 2025-07-28)Enter at the 2025-08-08 close (signal on 2025-08-07)Exit at the 2025-10-09 close (signal on 2025-10-08)Enter at the 2025-10-15 close (signal on 2025-10-14)Exit at the 2025-10-16 close (signal on 2025-10-15)Enter at the 2025-11-10 close (signal on 2025-11-07)Exit at the 2025-12-03 close (signal on 2025-12-02)Enter at the 2025-12-04 close (signal on 2025-12-03)Exit at the 2025-12-05 close (signal on 2025-12-04)EquityDrawdown2025-01-022025-03-312025-06-252025-09-192025-12-16
Show data (250 rows)
DateOpenHighLowCloseSMA 20Equity: Strategy equityDrawdown: Drawdown
2025-01-02100.83101.2699.82100.04Not defined$10,000.00-0.00%
2025-01-03100.32100.6598.799.29Not defined$10,000.00-0.00%
2025-01-0699.65101.0999.2100.76Not defined$10,000.00-0.00%
2025-01-07100.52102.65100.49101.93Not defined$10,000.00-0.00%
2025-01-08102.33102.91101.22102.36Not defined$10,000.00-0.00%
2025-01-09102.08104.2101.84104.13Not defined$10,000.00-0.00%
2025-01-10104.37104.99103.92104.89Not defined$10,000.00-0.00%
2025-01-13104.94106.64104.94106.28Not defined$10,000.00-0.00%
2025-01-14106.04107.63105.64107.36Not defined$10,000.00-0.00%
2025-01-15107.4111.72107.39111.46Not defined$10,000.00-0.00%
2025-01-16111.73114.08111.3113.75Not defined$10,000.00-0.00%
2025-01-17113.39114.11111.23111.83Not defined$10,000.00-0.00%
2025-01-20111.8112.96110.32111.56Not defined$10,000.00-0.00%
2025-01-21111.16111.9111.16111.68Not defined$10,000.00-0.00%
2025-01-22112.18112.94110.94112.05Not defined$10,000.00-0.00%
2025-01-23111.99112.4111.09111.3Not defined$10,000.00-0.00%
2025-01-24111.29112.1110.57111.82Not defined$10,000.00-0.00%
2025-01-27112.02114.12111.44113.75Not defined$10,000.00-0.00%
2025-01-28114.11114.68112.75113.09Not defined$10,000.00-0.00%
2025-01-29112.87114.11112.47114.06108.17$10,000.00-0.00%
2025-01-30114.03114.31113.28113.61108.848$9,990.00-0.10%
2025-01-31113.08113.83112.64113.32109.55$9,964.46-0.36%
2025-02-03113.12113.79111.92112.99110.161$9,935.45-0.65%
2025-02-04112.82113.08111.49111.93110.661$9,842.24-1.58%
2025-02-05111.87112.39111.61111.61111.123$9,814.10-1.86%
2025-02-06112.23112.49111.43111.67111.5$9,819.38-1.81%
2025-02-07111.73111.86109.41109.64111.738$9,640.87-3.59%
2025-02-10109.23110.7109.2110.12111.93$9,673.40-3.27%
2025-02-11110.09110.22108.54109.77112.05$9,673.40-3.27%
2025-02-12110.11110.52108.46108.55111.905$9,673.40-3.27%
2025-02-13108.71112.23108.3111.89111.812$9,673.40-3.27%
2025-02-14111.26113.37111.15112.64111.852$9,663.72-3.36%
2025-02-17112.5113.78112.07113.31111.94$9,721.25-2.79%
2025-02-18113.2113.35111.44111.74111.943$9,586.56-4.13%
2025-02-19111.63112.14110.71111.7111.925$9,573.54-4.26%
2025-02-20111.5113.9110.85112.99112.01$9,573.54-4.26%
2025-02-21113.06113.44110.77112.19112.028$9,563.97-4.36%
2025-02-24112.25113.76112.06113.08111.995$9,639.91-3.60%
2025-02-25112.96115.68112.52114.64112.072$9,772.89-2.27%
2025-02-26113.96114.14113.73113.97112.068$9,715.78-2.84%
2025-02-27113.72114.05113.16113.48112.061$9,674.01-3.26%
2025-02-28113.46114.13113.14113.66112.078$9,689.35-3.11%
2025-03-03113.37113.75111.96113.1112.084$9,641.61-3.58%
2025-03-04113.04114.53109.25112.07112.091$9,553.81-4.46%
2025-03-05112.03112.65110.88111.2112.07$9,470.16-5.30%
2025-03-06110.57111.6110.25111.51112.062$9,470.16-5.30%
2025-03-07111.47112.64111.17112.37112.199$9,470.16-5.30%
2025-03-10112.84112.87109.43109.69112.177$9,460.69-5.39%
2025-03-11109.62110.89108.79110.04112.191$9,481.41-5.19%
2025-03-12109.92110.77109.72110.75112.301$9,481.41-5.19%
2025-03-13110.53111.82110.43110.7112.241$9,481.41-5.19%
2025-03-14110.43111.34110.08111.15112.167$9,481.41-5.19%
2025-03-17111.25113.28111.02112.95112.149$9,481.41-5.19%
2025-03-18112.8113.34112.46113.08112.216$9,471.93-5.28%
2025-03-19113.14113.5112.29113.09112.285$9,472.75-5.27%
2025-03-20113.12113.81111.21111.82112.227$9,366.38-6.34%
2025-03-21112.21113.56111.37113.2112.277$9,472.49-5.28%
2025-03-24112.87117.09112.59116.23112.435$9,463.01-5.37%
2025-03-25116.53116.86114.08114.21112.413$9,298.38-7.02%
2025-03-26114.49114.57113.39113.67112.398$9,254.41-7.46%
2025-03-27113.81116.35113.77115.86112.517$9,432.71-5.67%
2025-03-28116.18116.48115.14115.19112.594$9,378.17-6.22%
2025-03-31114.93115.81114.81115.63112.72$9,413.99-5.86%
2025-04-01115.14116.97113.4116.45112.939$9,480.75-5.19%
2025-04-02116.22116.63114.91115.14113.136$9,374.09-6.26%
2025-04-03114.76117.39113.38115.74113.348$9,422.94-5.77%
2025-04-04115.95116.05115.39115.43113.501$9,397.70-6.02%
2025-04-07114.88118.44114.66117.74113.903$9,585.77-4.14%
2025-04-08118.14119.33118.13118.76114.339$9,668.82-3.31%
2025-04-09119.15121.04117.97120.29114.816$9,793.38-2.07%
2025-04-10120.21126.36119.58125.17115.54$10,190.68-0.00%
2025-04-11124.95125.63122.92123.69116.167$10,070.19-1.18%
2025-04-14123.64125.46123.18124.6116.749$10,144.28-0.46%
2025-04-15124.98127.19124.97126.8117.435$10,323.39-0.00%
2025-04-16127.11130.4126.86130.29118.295$10,607.53-0.00%
2025-04-17129.92133.24129.6133.01119.355$10,828.98-0.00%
2025-04-18133.05133.27132.17132.3120.31$10,771.17-0.53%
2025-04-21132.38132.52130.17130.33121.015$10,610.78-2.01%
2025-04-22130.32131.15128.04128.46121.727$10,458.54-3.42%
2025-04-23128.37133.3127.58132.66122.677$10,800.48-0.26%
2025-04-24132.9133.75128.12129.1123.339$10,510.64-2.94%
2025-04-25129.49129.57124.25124.64123.811$10,147.53-6.29%
2025-04-28124.05125.51120.73120.94124.077$9,846.30-9.07%
2025-04-29121.93124.66120.24123.6124.434$10,052.80-7.17%
2025-04-30124.27127.17122.1124.89124.922$10,052.80-7.17%
2025-05-01124.77124.9121.13122.15125.242$10,052.80-7.17%
2025-05-02121.82122.75119.75120.9125.516$10,052.80-7.17%
2025-05-05121.01123.88118.83122.63125.76$10,052.80-7.17%
2025-05-06122.18123.81121.04123.45125.995$10,052.80-7.17%
2025-05-07123.28124.12118.95120.02125.981$10,052.80-7.17%
2025-05-08120.52121.48116.28117.42125.594$10,052.80-7.17%
2025-05-09117.77118.43116.09116.72125.245$10,052.80-7.17%
2025-05-12116.59118.71113.65115.82124.806$10,052.80-7.17%
2025-05-13114.98117.97114.28115.92124.262$10,052.80-7.17%
2025-05-14116.56117.11112.75112.92123.394$10,052.80-7.17%
2025-05-15112.84115.55109.99110.96122.291$10,052.80-7.17%
2025-05-16110.93113.21110.36112.63121.308$10,052.80-7.17%
2025-05-19112.32112.41110.08110.47120.315$10,052.80-7.17%
2025-05-20110.94111.72109.93111.7119.477$10,052.80-7.17%
2025-05-21111.76111.88111.49111.82118.435$10,052.80-7.17%
2025-05-22111.28111.6109.91110.14117.487$10,052.80-7.17%
2025-05-23110.04112.46110.01112.3116.87$10,052.80-7.17%
2025-05-26111.72115.77111.62114.68116.557$10,052.80-7.17%
2025-05-27115.7115.82111.16113.1116.032$10,052.80-7.17%
2025-05-28112.44116.08109.99113.86115.48$10,052.80-7.17%
2025-05-29113.84114.96112.11112.67115.006$10,052.80-7.17%
2025-05-30112.7113.58112.37113.15114.619$10,052.80-7.17%
2025-06-02112.77115.03112.76114.88114.231$10,052.80-7.17%
2025-06-03114.54115.05113.85114.69113.793$10,042.75-7.26%
2025-06-04114.44114.93113.13113.89113.487$9,972.62-7.91%
2025-06-05114.1114.59113.92114.36113.334$10,013.77-7.53%
2025-06-06114.06115.32113.49115.09113.252$10,077.69-6.94%
2025-06-09114.81116.87114.67116.86113.304$10,232.68-5.51%
2025-06-10116.2116.29115.3115.71113.294$10,131.98-6.44%
2025-06-11115.01117.31114.65116.99113.497$10,244.06-5.40%
2025-06-12116.51118.86116.35118.38113.868$10,365.78-4.28%
2025-06-13118.63118.78117.64117.86114.13$10,320.24-4.70%
2025-06-16118.08120.83117.54119.89114.601$10,498.00-3.06%
2025-06-17119.4120.47118.9119.92115.012$10,500.62-3.03%
2025-06-18119.82119.9118.33118.6115.351$10,385.04-4.10%
2025-06-19118.78120.5118.6120.12115.85$10,518.14-2.87%
2025-06-20119.86120.23117.44117.56116.113$10,293.97-4.94%
2025-06-23117.63118117.47117.72116.265$10,307.98-4.81%
2025-06-24116.99117.82116.34117.49116.484$10,287.85-5.00%
2025-06-25117.23118.39117.18118.13116.698$10,343.89-4.48%
2025-06-26118.12120.38117.99120.13117.071$10,519.01-2.86%
2025-06-27120.51120.85117.72117.9117.308$10,323.75-4.67%
2025-06-30117.73119.99117.25119.24117.526$10,441.08-3.58%
2025-07-01119.63119.65118.88119.08117.746$10,427.07-3.71%
2025-07-02119.09122.68118.73122.47118.175$10,723.91-0.97%
2025-07-03122.64122.82121.65122.59118.586$10,734.42-0.87%
2025-07-04122.6126.74122.42126.72119.168$11,096.06-0.00%
2025-07-07126.38127.27124.32125.67119.608$11,004.12-0.83%
2025-07-08125.76127.22125.57127.22120.184$11,139.84-0.00%
2025-07-09127.31127.63125.37126.09120.639$11,040.89-0.89%
2025-07-10125.64126.08124.05124.77120.958$10,925.31-1.93%
2025-07-11125.66126.61125.38126.43121.387$11,070.66-0.62%
2025-07-14126.53129.05126.42128.24121.804$11,229.15-0.00%
2025-07-15127.87131.36127.74130.01122.309$11,384.14-0.00%
2025-07-16130.16130.46128.23128.72122.815$11,271.18-0.99%
2025-07-17129.4129.45127.9128.57123.237$11,258.05-1.11%
2025-07-18128.86129.25126.21126.64123.691$11,089.05-2.59%
2025-07-21126.23126.74124.3125.5124.08$10,989.23-3.47%
2025-07-22125.52126.99124.5124.72124.442$10,920.93-4.07%
2025-07-23124.19127.19123.99126.09124.84$11,040.89-3.02%
2025-07-24126.8127.46126.01126.64125.165$11,089.05-2.59%
2025-07-25126.62127.08125.86126.12125.576$11,043.52-2.99%
2025-07-28126.05126.24124.35125.06125.867$10,950.70-3.81%
2025-07-29125.13125.36124.04124.48126.137$10,889.01-4.35%
2025-07-30124.61127.12124.22126.18126.323$10,889.01-4.35%
2025-07-31126.53127.44124.46125.17126.452$10,889.01-4.35%
2025-08-01125.11125.86125.04125.45126.388$10,889.01-4.35%
2025-08-04124.93125.14123.8124.31126.32$10,889.01-4.35%
2025-08-05124.22125.72124.11125.6126.239$10,889.01-4.35%
2025-08-06125.35125.6124.54125.05126.187$10,889.01-4.35%
2025-08-07125.21127.68125.13127.48126.323$10,889.01-4.35%
2025-08-08127.73128.73125.93126.42126.322$10,878.13-4.44%
2025-08-11125.84127.36125.4127.34126.277$10,957.36-3.75%
2025-08-12126.86127.36126.65127.07126.13$10,934.12-3.95%
2025-08-13126.8130.23126.4130.21126.205$11,204.32-1.58%
2025-08-14130.69131.56129.93130.33126.293$11,214.64-1.49%
2025-08-15131.01131.07129.34129.79126.45$11,168.18-1.90%
2025-08-18129.75130.85129.58130.53126.702$11,231.85-1.34%
2025-08-19130.96131.59130.67131.41127.036$11,307.57-0.67%
2025-08-20130.82132.73130.66132.47127.355$11,398.78-0.00%
2025-08-21131.65131.89130.78131.04127.575$11,275.74-1.08%
2025-08-22130.59133.68129.9133.15127.927$11,457.30-0.00%
2025-08-25133.08134.56132.61134.37128.392$11,562.28-0.00%
2025-08-26134.57136.5134.5136.15128.976$11,715.44-0.00%
2025-08-27136.55138.92135.75138.03129.568$11,877.21-0.00%
2025-08-28137.82138.96137.29137.71130.195$11,849.68-0.23%
2025-08-29137.28142.14137.21141.99131.022$12,217.96-0.00%
2025-09-01142.28143.28142.25142.76131.945$12,284.22-0.00%
2025-09-02142.71143.08142.09142.44132.787$12,256.68-0.22%
2025-09-03142.36142.81141.42141.9133.63$12,210.22-0.60%
2025-09-04141.44141.46140.21140.33134.272$12,075.12-1.70%
2025-09-05140.34143.44139.97143.02135.102$12,306.59-0.00%
2025-09-08143.37143.87142.92143.67135.919$12,362.52-0.00%
2025-09-09144.41144.84143.32143.85136.758$12,378.01-0.00%
2025-09-10143.84146.39143.81145.79137.537$12,544.94-0.00%
2025-09-11145.94146.58142.74143.32138.186$12,332.41-1.69%
2025-09-12143.52146.63143.41145.94138.993$12,557.85-0.00%
2025-09-15146.22147.23142.57144.51139.693$12,434.80-0.98%
2025-09-16145.08145.93144.15145.92140.418$12,556.13-0.01%
2025-09-17145.94146.28144.79145.64141.077$12,532.04-0.21%
2025-09-18145.98149.74145.86147.73141.911$12,711.88-0.00%
2025-09-19147.77148.48145.06145.29142.518$12,501.92-1.65%
2025-09-22144.87147.54144.46147.48143.174$12,690.37-0.17%
2025-09-23147.38148.13144.94145.68143.65$12,535.48-1.39%
2025-09-24145.48147.18144.25147144.099$12,649.06-0.49%
2025-09-25146.53147.82146.08147.48144.587$12,690.37-0.17%
2025-09-26147.95148.43146.86148.23144.899$12,754.90-0.00%
2025-09-29147.55152.42146.5151.14145.318$13,005.30-0.00%
2025-09-30150.84151.5150.39151.02145.747$12,994.98-0.08%
2025-10-01150.51152.29150.5151.8146.242$13,062.09-0.00%
2025-10-02151.7155.81150.65155.57147.004$13,386.49-0.00%
2025-10-03156.15157.34149.32149.72147.339$12,883.11-3.76%
2025-10-06150.16152.69149.26152.32147.772$13,106.84-2.09%
2025-10-07152.14153.3148.75149.37148.047$12,853.00-3.99%
2025-10-08149.17149.76145.76146.77148.097$12,629.27-5.66%
2025-10-09146.93147.87145.82146.2148.24$12,567.64-6.12%
2025-10-10146.01150.11143.68147.36148.311$12,567.64-6.12%
2025-10-13146.57149.75146.47148.35148.503$12,567.64-6.12%
2025-10-14148.19151.57147.64149.97148.706$12,567.64-6.12%
2025-10-15150.27151.13142.93144.08148.628$12,555.08-6.21%
2025-10-16142.99143.48141.81142.58148.37$12,411.80-7.28%
2025-10-17141.04141.86138.88140.39148.125$12,411.80-7.28%
2025-10-20139.44142.27137.81141.68147.835$12,411.80-7.28%
2025-10-21141.5143.19139.14139.28147.515$12,411.80-7.28%
2025-10-22139.11141.7138.29141.14147.222$12,411.80-7.28%
2025-10-23142.87143.8137.18138.69146.783$12,411.80-7.28%
2025-10-24138.27139.37134.9135.14146.128$12,411.80-7.28%
2025-10-27135.54136.77135.42135.66145.354$12,411.80-7.28%
2025-10-28135.74140.04131.76136.53144.63$12,411.80-7.28%
2025-10-29137.19139.56135.71138.27143.953$12,411.80-7.28%
2025-10-30138.06138.16135.04135.96142.973$12,411.80-7.28%
2025-10-31135.99137.46135.4137.29142.351$12,411.80-7.28%
2025-11-03136.34138.66136137.41141.606$12,411.80-7.28%
2025-11-04138.21138.95136.3138.68141.071$12,411.80-7.28%
2025-11-05138.52140.81138.33140.55140.76$12,411.80-7.28%
2025-11-06140.87140.91140.14140.16140.458$12,411.80-7.28%
2025-11-07140.54146.15139.96145.77140.379$12,411.80-7.28%
2025-11-10145.65149.22145.22148.3140.376$12,399.39-7.37%
2025-11-11148.22148.52147.77148.48140.302$12,414.44-7.26%
2025-11-12148.49149.53145.55146.33140.414$12,234.68-8.60%
2025-11-13147.01148.75142.56143.57140.464$12,003.91-10.33%
2025-11-14143.29143.56141.87142.12140.551$11,882.68-11.23%
2025-11-17142.39146.91141.95145.75140.754$12,186.18-8.97%
2025-11-18145.56152.28144.84151.53141.367$12,669.45-5.36%
2025-11-19150.92153.19150.49152.92141.956$12,785.67-4.49%
2025-11-20152.52153.9151.71152.91142.666$12,784.83-4.49%
2025-11-21153.14153.89151.21151.35143.477$12,654.40-5.47%
2025-11-24152.87153.36149.15149.86144.187$12,529.82-6.40%
2025-11-25150.23153.4149.18151.22144.921$12,643.53-5.55%
2025-11-26151.26156.03149.91155.14145.765$12,971.28-3.10%
2025-11-27154.75155.35153.95155.13146.724$12,970.45-3.11%
2025-11-28154.95156.75149.82150.44147.381$12,578.32-6.04%
2025-12-01150.63150.94148.98149.33147.977$12,485.51-6.73%
2025-12-02149.68151.79143.34144.9148.288$12,115.11-9.50%
2025-12-03144.48150.12143.72149.3148.726$12,470.52-6.84%
2025-12-04150.1150.34148.03148.7149.153$12,458.05-6.94%
2025-12-05148.52150.45146.16146.47149.188$12,258.75-8.42%
2025-12-08146.07146.71144.2144.71149.008$12,258.75-8.42%
2025-12-09145.81145.9142.51142.99148.734$12,258.75-8.42%
2025-12-10142.8143.17140.59140.73148.454$12,258.75-8.42%
2025-12-11141.5142.15139.61140.44148.297$12,258.75-8.42%
2025-12-12141.22141.75137.23138.06148.094$12,258.75-8.42%
2025-12-15138.48139.11135.16135.18147.566$12,258.75-8.42%
2025-12-16135.29137.27134.61136.23146.8$12,258.75-8.42%
2025-12-17135.54135.95133.05133.92145.85$12,258.75-8.42%

Assumptions & conventions

What the calculation assumed, echoed by the library rather than hidden.

conventionsVersion
0.0.1
initialCapital
10,000
fill
close
cost
bps(10)
slippage
none
cashSettlement
immediate
corporateAction
none
calendar
everyBar
margin
maxLeverage

Diagnostics & warnings

No warnings. Engine, method and convergence details:

benchmarkFixtureVersion
0.0.1
dataNotice
Synthetic sample data, not market history. 252 periods per year is a stated annualization assumption.

Use it in your project

vectorized returns a backtest report with points, returns, trades, performance, assumptions and diagnostics. This example prints selected summary fields. The moving average returns an ordinary number array; warmup NaN values are deliberately excluded from signals.

Sample inputs

250 bars from: Synthetic uptrend with pullbacks (seed 7, not market data). Preview: the first three bars. Copy setup + call includes every bar. The 252-period annualization is a stated assumption, not a trading calendar.

Preview
[
  {
    "date": "2025-01-02",
    "open": 100.83,
    "high": 101.26,
    "low": 99.82,
    "close": 100.04,
    "volume": 894440
  },
  {
    "date": "2025-01-03",
    "open": 100.32,
    "high": 100.65,
    "low": 98.7,
    "close": 99.29,
    "volume": 1908571
  },
  {
    "date": "2025-01-06",
    "open": 99.65,
    "high": 101.09,
    "low": 99.2,
    "close": 100.76,
    "volume": 2282565
  }
]
Complete setup · included when you copy
First call
const average = sma(closes, { period: 20 });
// Warmup values are NaN: no position until the average exists.
const signal = closes.map((close, index) => Number.isFinite(average[index]) && close > average[index]!);
const backtest = vectorized({
  data,
  signal,
  initialCapital: 10000,
  executionLag: 1, // Trade on the bar after the signal.
  periodsPerYear: 252,
  fees: fees.bps(10),
});
const result = {
  finalValue: backtest.finalValue,
  totalReturn: backtest.performance.totalReturn,
  maxDrawdown: backtest.performance.maxDrawdown,
  fills: backtest.trades.length,
};
console.log(result);
Output of this example
{
  "finalValue": 12258.746779244666,
  "totalReturn": 0.2258746779244667,
  "maxDrawdown": 0.1123382528301128,
  "fills": 42
}
Reproduce this entire calculator
Full result object

Both examples use the inputs of the last successful calculation. Displayed metrics are rounded; copied programs keep exact values. Every copy on this page is type-checked and executed against the packed package in CI.

Ask your AI agent

With the TotalFinance MCP server connected, your agent runs this calculation with the totalfinance_backtest_vectorized_run tool (start the server with --profile backtesting). The prompt below uses your current inputs.

Prompt

Use the TotalFinance MCP tool totalfinance_backtest_vectorized_run to backtest this rule on my daily bars: hold while the close is above its 20-day moving average. Start with 10,000 USD and 10 basis points per trade. Report the final value, turnover and drawdown, and every policy the run assumed. [Paste your daily OHLCV CSV here: date, open, high, low, close, volume]

Connect Claude, Cursor, VS Code, Codex or ChatGPT

What this calculates

vectorized runs a backtest from bars and a signal aligned to them. The signal says whether to hold the asset on each bar; with executionLag: 1 a signal observed on one bar trades on the next, so the strategy can never act on a price before it exists. Fees, slippage, borrow costs, leverage limits and the annualization basis are explicit options, and the report echoes them.

Bring your own data

Choose Use your data in the panel and paste or upload daily bars as CSV or TSV with date, open, high, low and close columns (volume is optional). Most broker and data-vendor exports work as they are; rows newest-first are put in order and the panel tells you what it changed. Your data stays in your browser.

Reading the chart

Candles show each bar (hollow up, filled down), with the moving averages on top. Triangles mark entries and exits on the bar where they fill. The equity and drawdown panes share the price axis, so the crosshair lines up a trade with its effect.

Honest limits

The rebalance rule here is every bar, so small trades keep the position at its target weight; the fill count includes them. A good backtest on one series is not evidence of an edge. Read Backtesting for the engines, the laws every engine keeps and out-of-sample practice.

Edit this page on GitHub ↗Every code block on this site is executed in CI against the library.