fix: `getClosingPrice()` for two calendardb modules

main
avraham 9 months ago
parent 5b3e9f85f6
commit 8d908521fd

@ -116,11 +116,12 @@ function makeCalendarDatabase(): CalendarDatabase {
getClosingPrice: async ({
key: { symbol, strike, type, frontExpirationDate, backExpirationDate },
}) => {
const startOfLastHourUnix = new Date(
`${frontExpirationDate}T00:00:00Z`,
const startOfExpirationDateUnix = new Date(
`${frontExpirationDate}T23:59:59Z`
).valueOf();
const endOfExpirationDateUnix = new Date(
`${frontExpirationDate}T00:00:00Z`
).valueOf();
const endOfLastHourUnix = startOfLastHourUnix + 3600 * 1000;
let minPrice = 0;
for (const { value } of calendarAggregatesDb.getRange({
start: [
symbol,
@ -128,7 +129,7 @@ function makeCalendarDatabase(): CalendarDatabase {
backExpirationDate,
strike,
type,
startOfLastHourUnix,
startOfExpirationDateUnix,
],
end: [
symbol,
@ -136,14 +137,15 @@ function makeCalendarDatabase(): CalendarDatabase {
backExpirationDate,
strike,
type,
endOfLastHourUnix,
endOfExpirationDateUnix,
],
reverse: true,
})) {
if (value.close < minPrice || minPrice === 0) {
minPrice = value.close;
if (value.close > 0) {
return value.close;
}
}
return minPrice;
return 0;
},
getTargetPriceByProbability: async ({
symbol,

@ -93,9 +93,10 @@ function makeCalendarDatabase(): CalendarDatabase {
getClosingPrice: async ({
key: { symbol, strike, type, frontExpirationDate, backExpirationDate },
}) => {
// get unix timestamp, in milliseconds, of the start of the last hour, which is 03:30PM in the `America/New_York` timezone on the front expiration date:
const startOfLastHourUnix = new Date(
`${frontExpirationDate}T00:00:00Z`,
).valueOf();
`${frontExpirationDate}T19:30:00Z`
).getTime();
const endOfLastHourUnix = startOfLastHourUnix + 3600 * 1000;
const frontOptionContractAggregates = (
await optionContractDatabase.getAggregates({
@ -104,7 +105,7 @@ function makeCalendarDatabase(): CalendarDatabase {
})
).filter(
({ tsStart }) =>
tsStart >= startOfLastHourUnix && tsStart < endOfLastHourUnix,
tsStart >= startOfLastHourUnix && tsStart < endOfLastHourUnix
);
const backOptionContractAggregates = (
await optionContractDatabase.getAggregates({
@ -113,7 +114,7 @@ function makeCalendarDatabase(): CalendarDatabase {
})
).filter(
({ tsStart }) =>
tsStart >= startOfLastHourUnix && tsStart < endOfLastHourUnix,
tsStart >= startOfLastHourUnix && tsStart < endOfLastHourUnix
);
let i = 0;
let j = 0;
@ -128,7 +129,7 @@ function makeCalendarDatabase(): CalendarDatabase {
) {
const calendarClosePrice =
backOptionContractAggregates[j].close -
frontOptionContractAggregates[j].close;
frontOptionContractAggregates[i].close;
if (calendarClosePrice < minPrice || minPrice === 0) {
minPrice = calendarClosePrice;
}

Loading…
Cancel
Save