|
|
|
@ -48,7 +48,7 @@ export async function backtest({
|
|
|
|
|
...calendar,
|
|
|
|
|
},
|
|
|
|
|
date,
|
|
|
|
|
}),
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
// for each minute of that day for which we have a stock candlestick:
|
|
|
|
@ -57,12 +57,12 @@ export async function backtest({
|
|
|
|
|
// filter-out calendars that are far-from-the-money (10%)
|
|
|
|
|
const calendarsNearTheMoney = calendars.filter(
|
|
|
|
|
({ strike }) =>
|
|
|
|
|
Math.abs((stockAggregate.open - strike) / stockAggregate.open) < 0.1,
|
|
|
|
|
Math.abs((stockAggregate.open - strike) / stockAggregate.open) < 0.1
|
|
|
|
|
);
|
|
|
|
|
// for each relevant calendar on that day:
|
|
|
|
|
for (const calendar of calendarsNearTheMoney) {
|
|
|
|
|
const strikePercentageFromTheMoney = Math.abs(
|
|
|
|
|
(stockAggregate.open - calendar.strike) / stockAggregate.open,
|
|
|
|
|
(stockAggregate.open - calendar.strike) / stockAggregate.open
|
|
|
|
|
);
|
|
|
|
|
/** In days. */
|
|
|
|
|
const calendarSpan =
|
|
|
|
@ -78,14 +78,14 @@ export async function backtest({
|
|
|
|
|
});
|
|
|
|
|
const calendarAggregates = calendarsAggregates.get(calendar);
|
|
|
|
|
const calendarAggregateAtCurrentTime = calendarAggregates.find(
|
|
|
|
|
({ tsStart }) => tsStart === stockAggregate.tsStart,
|
|
|
|
|
({ tsStart }) => tsStart === stockAggregate.tsStart
|
|
|
|
|
);
|
|
|
|
|
// if there exists a matching calendar candlestick for the current minute:
|
|
|
|
|
if (calendarAggregateAtCurrentTime) {
|
|
|
|
|
// if the current candlestick is a good price (i.e. less than the target price):
|
|
|
|
|
const minCalendarPriceInCandlestick = Math.min(
|
|
|
|
|
calendarAggregateAtCurrentTime.open,
|
|
|
|
|
calendarAggregateAtCurrentTime.close,
|
|
|
|
|
calendarAggregateAtCurrentTime.close
|
|
|
|
|
);
|
|
|
|
|
if (
|
|
|
|
|
minCalendarPriceInCandlestick < targetCalendarPrice &&
|
|
|
|
@ -104,7 +104,7 @@ export async function backtest({
|
|
|
|
|
minCalendarPriceInCandlestick * 100,
|
|
|
|
|
"...$",
|
|
|
|
|
buyingPower,
|
|
|
|
|
"left",
|
|
|
|
|
"left"
|
|
|
|
|
);
|
|
|
|
|
didBuyCalendar = true;
|
|
|
|
|
}
|
|
|
|
@ -136,7 +136,7 @@ export async function backtest({
|
|
|
|
|
calendarClosingPrice,
|
|
|
|
|
"...$",
|
|
|
|
|
buyingPower,
|
|
|
|
|
"left",
|
|
|
|
|
"left"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|