USD ($)
Ticker
Balance
Range
// Load Math.js Library
await this.loadScript('https://cdnjs.cloudflare.com/ajax/libs/mathjs/12.4.3/math.min.js');
math.config({ randomSeed: 42 });
this.on('start', async (next, timeseries) => {
this.print(`Start (size: ${Object.values(timeseries).length})`);
this.state.prevDate = this.date;
next();
});
this.on('data', async (next) => {
// Print
const dateStr = this.date.toISOString().split('T')[0];
this.print(`------ ${dateStr} (${this.index}/${this.length}) ------`);
this.print(
'cash:', this.portfolio.cash.toFixed(2),
'equity:', this.portfolio.longValue.toFixed(2),
'profit:', this.portfolio.realizedProfit.toFixed(2)
);
// Trade Logic
// use market data directly to make decisions,
// or complex tools like a neural network with api
// calls like fetch('http://localhost:1234/my-python-ai')
const qnt = 100;
for (let asset of this.assets) {
const amount = qnt * asset.value;
const rnd = math.randomInt(0, 3);
if (rnd === 0) this.buy(asset.assetCode, qnt);
else if (rnd === 1) this.sell(asset.assetCode, qnt);
if (rnd !== 2)
this.print(`[${asset.assetCode}] ${rnd === 0 ? 'Buy' : 'Sell'}: ${asset.currency} ${amount.toFixed(2)}`);
 
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Backtest Results | Check the Docs
Backtest Output