Compare commits
37 Commits
eba5344b15
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c83f2ce0a0 | |||
| 4d989f10eb | |||
| 906e63eb91 | |||
| 3732680d52 | |||
| 3c841f488c | |||
| b6cc25b769 | |||
| 14dff05785 | |||
| f05831b5f1 | |||
| b7f9d60715 | |||
| b2169e1da7 | |||
| aeac0e1042 | |||
| 904d2da84a | |||
| 694bb38536 | |||
| 64a5172ea8 | |||
| ac9554ba21 | |||
| 2597c0f6ac | |||
| add21288be | |||
| db809d7b57 | |||
| 8986dc4ea9 | |||
| ea9bd307f3 | |||
| 7bca5e701d | |||
| 82915fb0b5 | |||
| d134385bd7 | |||
| 3bc976b63a | |||
| 72f45b81a5 | |||
| d6762fdae5 | |||
| 15a5d7c67b | |||
| fe1265810d | |||
| 8d908521fd | |||
| 5b3e9f85f6 | |||
| 666ff16583 | |||
| 35b3278d08 | |||
| 704d59a363 | |||
| 93d5ac8a30 | |||
| 1d83cd419a | |||
| cfb207aae8 | |||
| c749321fe9 |
+3
-1
@@ -1,2 +1,4 @@
|
|||||||
.pnpm-store
|
.pnpm-store
|
||||||
node_modules
|
node_modules
|
||||||
|
.aider*
|
||||||
|
.env
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
nodejs 20.15.1
|
nodejs 20.15.1
|
||||||
|
python 3.12.4
|
||||||
|
pnpm 9.7.1
|
||||||
+2
-2
@@ -2,14 +2,14 @@
|
|||||||
FROM node:20-slim AS build
|
FROM node:20-slim AS build
|
||||||
ENV PNPM_HOME="/pnpm"
|
ENV PNPM_HOME="/pnpm"
|
||||||
ENV PATH="$PNPM_HOME:$PATH"
|
ENV PATH="$PNPM_HOME:$PATH"
|
||||||
RUN corepack enable
|
RUN npm install -g corepack@latest && corepack enable
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
# copy what's necessary to install dependencies:
|
# copy what's necessary to install dependencies:
|
||||||
COPY package.json pnpm-lock.yaml /app/
|
COPY package.json pnpm-lock.yaml /app/
|
||||||
# install dependencies:
|
# install dependencies:
|
||||||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
||||||
# copy what's necessary to build:
|
# copy what's necessary to build:
|
||||||
COPY tsconfig.json vite.config.ts index.html index.css postcss.config.js tailwind.config.js /app/
|
COPY tsconfig.json vite.config.ts index.html index.css /app/
|
||||||
COPY src /app/src
|
COPY src /app/src
|
||||||
# Vite injects envvars at build time, not runtime:
|
# Vite injects envvars at build time, not runtime:
|
||||||
ENV VITE_SERVER_BASE_URL=https://calendar-optimizer-server.sakal.us
|
ENV VITE_SERVER_BASE_URL=https://calendar-optimizer-server.sakal.us
|
||||||
|
|||||||
@@ -7,12 +7,10 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@date-io/date-fns": "^3.0.0",
|
"@mui/icons-material": "^6.1.1",
|
||||||
"@emotion/react": "^11.13.0",
|
"@mui/material": "^6.1.1",
|
||||||
"@emotion/styled": "^11.13.0",
|
"@mui/system": "^6.1.1",
|
||||||
"@mui/material": "^5.16.6",
|
"@mui/x-date-pickers": "^7.18.0",
|
||||||
"@mui/system": "^5.16.6",
|
|
||||||
"@mui/x-date-pickers": "^7.12.0",
|
|
||||||
"@preact/signals": "^1.2.2",
|
"@preact/signals": "^1.2.2",
|
||||||
"@trpc/client": "^10.45.0",
|
"@trpc/client": "^10.45.0",
|
||||||
"chart.js": "^4.4.1",
|
"chart.js": "^4.4.1",
|
||||||
|
|||||||
Generated
+182
-111
@@ -8,24 +8,18 @@ importers:
|
|||||||
|
|
||||||
.:
|
.:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@date-io/date-fns':
|
'@mui/icons-material':
|
||||||
specifier: ^3.0.0
|
specifier: ^6.1.1
|
||||||
version: 3.0.0(date-fns@3.6.0)
|
version: 6.1.1(@mui/material@6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
||||||
'@emotion/react':
|
|
||||||
specifier: ^11.13.0
|
|
||||||
version: 11.13.0(@types/react@18.3.3)(react@18.3.1)
|
|
||||||
'@emotion/styled':
|
|
||||||
specifier: ^11.13.0
|
|
||||||
version: 11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
|
||||||
'@mui/material':
|
'@mui/material':
|
||||||
specifier: ^5.16.6
|
specifier: ^6.1.1
|
||||||
version: 5.16.6(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
version: 6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||||
'@mui/system':
|
'@mui/system':
|
||||||
specifier: ^5.16.6
|
specifier: ^6.1.1
|
||||||
version: 5.16.6(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
version: 6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
||||||
'@mui/x-date-pickers':
|
'@mui/x-date-pickers':
|
||||||
specifier: ^7.12.0
|
specifier: ^7.18.0
|
||||||
version: 7.12.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@mui/material@5.16.6(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(@types/react@18.3.3)(date-fns@3.6.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
version: 7.18.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@mui/material@6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(@mui/system@6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(date-fns@3.6.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||||
'@preact/signals':
|
'@preact/signals':
|
||||||
specifier: ^1.2.2
|
specifier: ^1.2.2
|
||||||
version: 1.2.2(preact@10.19.3)
|
version: 1.2.2(preact@10.19.3)
|
||||||
@@ -178,6 +172,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-7dRy4DwXwtzBrPbZflqxnvfxLF8kdZXPkhymtDeFoFqE6ldzjQFgYTtYIFARcLEYDrqfBfYcZt1WqFxRoyC9Rw==}
|
resolution: {integrity: sha512-7dRy4DwXwtzBrPbZflqxnvfxLF8kdZXPkhymtDeFoFqE6ldzjQFgYTtYIFARcLEYDrqfBfYcZt1WqFxRoyC9Rw==}
|
||||||
engines: {node: '>=6.9.0'}
|
engines: {node: '>=6.9.0'}
|
||||||
|
|
||||||
|
'@babel/runtime@7.25.6':
|
||||||
|
resolution: {integrity: sha512-VBj9MYyDb9tuLq7yzqjgzt6Q+IBQLrGZfdjOekyEirZPHxXWoTSGUTMrpsfi58Up73d13NfYLv8HT9vmznjzhQ==}
|
||||||
|
engines: {node: '>=6.9.0'}
|
||||||
|
|
||||||
'@babel/template@7.22.15':
|
'@babel/template@7.22.15':
|
||||||
resolution: {integrity: sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==}
|
resolution: {integrity: sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==}
|
||||||
engines: {node: '>=6.9.0'}
|
engines: {node: '>=6.9.0'}
|
||||||
@@ -190,17 +188,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-+uarb83brBzPKN38NX1MkB6vb6+mwvR6amUulqAE7ccQw1pEl+bCia9TbdG1lsnFP7lZySvUn37CHyXQdfTwzg==}
|
resolution: {integrity: sha512-+uarb83brBzPKN38NX1MkB6vb6+mwvR6amUulqAE7ccQw1pEl+bCia9TbdG1lsnFP7lZySvUn37CHyXQdfTwzg==}
|
||||||
engines: {node: '>=6.9.0'}
|
engines: {node: '>=6.9.0'}
|
||||||
|
|
||||||
'@date-io/core@3.0.0':
|
|
||||||
resolution: {integrity: sha512-S3j+IAQVBYNkQzchVVhX40eBkGDreBpScy9RXwTS5j2+k07+62pMVPisQ44Gq76Rqy5AOG/EZXCwBpY/jbemvA==}
|
|
||||||
|
|
||||||
'@date-io/date-fns@3.0.0':
|
|
||||||
resolution: {integrity: sha512-hsLAbsdP8LKfi7OQ729cXMWfmHQEq0hn3ysXfAAoc92j6j6sBq0s0tplnkWu6O4iBUpVCYRPGuNjQQhTaOu2AA==}
|
|
||||||
peerDependencies:
|
|
||||||
date-fns: ^3.2.0
|
|
||||||
peerDependenciesMeta:
|
|
||||||
date-fns:
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
'@emotion/babel-plugin@11.12.0':
|
'@emotion/babel-plugin@11.12.0':
|
||||||
resolution: {integrity: sha512-y2WQb+oP8Jqvvclh8Q55gLUyb7UFvgv7eJfsj7td5TToBrIUtPay2kMrZi4xjq9qw2vD0ZR5fSho0yqoFgX7Rw==}
|
resolution: {integrity: sha512-y2WQb+oP8Jqvvclh8Q55gLUyb7UFvgv7eJfsj7td5TToBrIUtPay2kMrZi4xjq9qw2vD0ZR5fSho0yqoFgX7Rw==}
|
||||||
|
|
||||||
@@ -408,57 +395,71 @@ packages:
|
|||||||
'@kurkle/color@0.3.2':
|
'@kurkle/color@0.3.2':
|
||||||
resolution: {integrity: sha512-fuscdXJ9G1qb7W8VdHi+IwRqij3lBkosAm4ydQtEmbY58OzHXqQhvlxqEkoz0yssNVn38bcpRWgA9PP+OGoisw==}
|
resolution: {integrity: sha512-fuscdXJ9G1qb7W8VdHi+IwRqij3lBkosAm4ydQtEmbY58OzHXqQhvlxqEkoz0yssNVn38bcpRWgA9PP+OGoisw==}
|
||||||
|
|
||||||
'@mui/core-downloads-tracker@5.16.6':
|
'@mui/core-downloads-tracker@6.1.1':
|
||||||
resolution: {integrity: sha512-kytg6LheUG42V8H/o/Ptz3olSO5kUXW9zF0ox18VnblX6bO2yif1FPItgc3ey1t5ansb1+gbe7SatntqusQupg==}
|
resolution: {integrity: sha512-VdQC1tPIIcZAnf62L2M1eQif0x2vlKg3YK4kGYbtijSH4niEgI21GnstykW1vQIs+Bc6L+Hua2GATYVjilJ22A==}
|
||||||
|
|
||||||
'@mui/material@5.16.6':
|
'@mui/icons-material@6.1.1':
|
||||||
resolution: {integrity: sha512-0LUIKBOIjiFfzzFNxXZBRAyr9UQfmTAFzbt6ziOU2FDXhorNN2o3N9/32mNJbCA8zJo2FqFU6d3dtoqUDyIEfA==}
|
resolution: {integrity: sha512-sy/YKwcLPW8VcacNP2uWMYR9xyWuwO9NN9FXuGEU90bRshBXj8pdKk+joe3TCW7oviVS3zXLHlc94wQ0jNsQRQ==}
|
||||||
engines: {node: '>=12.0.0'}
|
engines: {node: '>=14.0.0'}
|
||||||
|
peerDependencies:
|
||||||
|
'@mui/material': ^6.1.1
|
||||||
|
'@types/react': ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
|
react: ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
|
peerDependenciesMeta:
|
||||||
|
'@types/react':
|
||||||
|
optional: true
|
||||||
|
|
||||||
|
'@mui/material@6.1.1':
|
||||||
|
resolution: {integrity: sha512-b+eULldTqtqTCbN++2BtBWCir/1LwEYw+2mIlOt2GiEUh1EBBw4/wIukGKKNt3xrCZqRA80yLLkV6tF61Lq3cA==}
|
||||||
|
engines: {node: '>=14.0.0'}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
'@emotion/react': ^11.5.0
|
'@emotion/react': ^11.5.0
|
||||||
'@emotion/styled': ^11.3.0
|
'@emotion/styled': ^11.3.0
|
||||||
'@types/react': ^17.0.0 || ^18.0.0
|
'@mui/material-pigment-css': ^6.1.1
|
||||||
react: ^17.0.0 || ^18.0.0
|
'@types/react': ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
react-dom: ^17.0.0 || ^18.0.0
|
react: ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
|
react-dom: ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
peerDependenciesMeta:
|
peerDependenciesMeta:
|
||||||
'@emotion/react':
|
'@emotion/react':
|
||||||
optional: true
|
optional: true
|
||||||
'@emotion/styled':
|
'@emotion/styled':
|
||||||
optional: true
|
optional: true
|
||||||
|
'@mui/material-pigment-css':
|
||||||
|
optional: true
|
||||||
'@types/react':
|
'@types/react':
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
'@mui/private-theming@5.16.6':
|
'@mui/private-theming@6.1.1':
|
||||||
resolution: {integrity: sha512-rAk+Rh8Clg7Cd7shZhyt2HGTTE5wYKNSJ5sspf28Fqm/PZ69Er9o6KX25g03/FG2dfpg5GCwZh/xOojiTfm3hw==}
|
resolution: {integrity: sha512-JlrjIdhyZUtewtdAuUsvi3ZnO0YS49IW4Mfz19ZWTlQ0sDGga6LNPVwHClWr2/zJK2we2BQx9/i8M32rgKuzrg==}
|
||||||
engines: {node: '>=12.0.0'}
|
engines: {node: '>=14.0.0'}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
'@types/react': ^17.0.0 || ^18.0.0
|
'@types/react': ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
react: ^17.0.0 || ^18.0.0
|
react: ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
peerDependenciesMeta:
|
peerDependenciesMeta:
|
||||||
'@types/react':
|
'@types/react':
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
'@mui/styled-engine@5.16.6':
|
'@mui/styled-engine@6.1.1':
|
||||||
resolution: {integrity: sha512-zaThmS67ZmtHSWToTiHslbI8jwrmITcN93LQaR2lKArbvS7Z3iLkwRoiikNWutx9MBs8Q6okKvbZq1RQYB3v7g==}
|
resolution: {integrity: sha512-HJyIoMpFb11fnHuRtUILOXgq6vj4LhIlE8maG4SwP/W+E5sa7HFexhnB3vOMT7bKys4UKNxhobC8jwWxYilGsA==}
|
||||||
engines: {node: '>=12.0.0'}
|
engines: {node: '>=14.0.0'}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
'@emotion/react': ^11.4.1
|
'@emotion/react': ^11.4.1
|
||||||
'@emotion/styled': ^11.3.0
|
'@emotion/styled': ^11.3.0
|
||||||
react: ^17.0.0 || ^18.0.0
|
react: ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
peerDependenciesMeta:
|
peerDependenciesMeta:
|
||||||
'@emotion/react':
|
'@emotion/react':
|
||||||
optional: true
|
optional: true
|
||||||
'@emotion/styled':
|
'@emotion/styled':
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
'@mui/system@5.16.6':
|
'@mui/system@6.1.1':
|
||||||
resolution: {integrity: sha512-5xgyJjBIMPw8HIaZpfbGAaFYPwImQn7Nyh+wwKWhvkoIeDosQ1ZMVrbTclefi7G8hNmqhip04duYwYpbBFnBgw==}
|
resolution: {integrity: sha512-PaYsCz2tUOcpu3T0okDEsSuP/yCDIj9JZ4Tox1JovRSKIjltHpXPsXZSGr3RiWdtM1MTQMFMCZzu0+CKbyy+Kw==}
|
||||||
engines: {node: '>=12.0.0'}
|
engines: {node: '>=14.0.0'}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
'@emotion/react': ^11.5.0
|
'@emotion/react': ^11.5.0
|
||||||
'@emotion/styled': ^11.3.0
|
'@emotion/styled': ^11.3.0
|
||||||
'@types/react': ^17.0.0 || ^18.0.0
|
'@types/react': ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
react: ^17.0.0 || ^18.0.0
|
react: ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
peerDependenciesMeta:
|
peerDependenciesMeta:
|
||||||
'@emotion/react':
|
'@emotion/react':
|
||||||
optional: true
|
optional: true
|
||||||
@@ -467,10 +468,10 @@ packages:
|
|||||||
'@types/react':
|
'@types/react':
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
'@mui/types@7.2.15':
|
'@mui/types@7.2.17':
|
||||||
resolution: {integrity: sha512-nbo7yPhtKJkdf9kcVOF8JZHPZTmqXjJ/tI0bdWgHg5tp9AnIN4Y7f7wm9T+0SyGYJk76+GYZ8Q5XaTYAsUHN0Q==}
|
resolution: {integrity: sha512-oyumoJgB6jDV8JFzRqjBo2daUuHpzDjoO/e3IrRhhHo/FxJlaVhET6mcNrKHUq2E+R+q3ql0qAtvQ4rfWHhAeQ==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
'@types/react': ^17.0.0 || ^18.0.0
|
'@types/react': ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
peerDependenciesMeta:
|
peerDependenciesMeta:
|
||||||
'@types/react':
|
'@types/react':
|
||||||
optional: true
|
optional: true
|
||||||
@@ -485,14 +486,25 @@ packages:
|
|||||||
'@types/react':
|
'@types/react':
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
'@mui/x-date-pickers@7.12.0':
|
'@mui/utils@6.1.1':
|
||||||
resolution: {integrity: sha512-WU5C7QNfSpJ9cP8vl2sY7q35NW+0TUMgEy+sl98fcPhLckq3cgV1wnVxoZnQZ3BxVQAtx+7ag/MpefU03vJcVw==}
|
resolution: {integrity: sha512-HlRrgdJSPbYDXPpoVMWZV8AE7WcFtAk13rWNWAEVWKSanzBBkymjz3km+Th/Srowsh4pf1fTSP1B0L116wQBYw==}
|
||||||
|
engines: {node: '>=14.0.0'}
|
||||||
|
peerDependencies:
|
||||||
|
'@types/react': ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
|
react: ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
|
peerDependenciesMeta:
|
||||||
|
'@types/react':
|
||||||
|
optional: true
|
||||||
|
|
||||||
|
'@mui/x-date-pickers@7.18.0':
|
||||||
|
resolution: {integrity: sha512-12tXIoMj9vpS8fS/bS3kWPCoVrH38vNGCxgplI0vOnUrN9rJuYJz3agLPJe1S0xciTw+9W8ZSe3soaW+owoz1Q==}
|
||||||
engines: {node: '>=14.0.0'}
|
engines: {node: '>=14.0.0'}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
'@emotion/react': ^11.9.0
|
'@emotion/react': ^11.9.0
|
||||||
'@emotion/styled': ^11.8.1
|
'@emotion/styled': ^11.8.1
|
||||||
'@mui/material': ^5.15.14
|
'@mui/material': ^5.15.14 || ^6.0.0
|
||||||
date-fns: ^2.25.0 || ^3.2.0
|
'@mui/system': ^5.15.14 || ^6.0.0
|
||||||
|
date-fns: ^2.25.0 || ^3.2.0 || ^4.0.0
|
||||||
date-fns-jalali: ^2.13.0-0 || ^3.2.0-0
|
date-fns-jalali: ^2.13.0-0 || ^3.2.0-0
|
||||||
dayjs: ^1.10.7
|
dayjs: ^1.10.7
|
||||||
luxon: ^3.0.2
|
luxon: ^3.0.2
|
||||||
@@ -521,6 +533,12 @@ packages:
|
|||||||
moment-jalaali:
|
moment-jalaali:
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
'@mui/x-internals@7.18.0':
|
||||||
|
resolution: {integrity: sha512-lzCHOWIR0cAIY1bGrWSprYerahbnH5C31ql/2OWCEjcngL2NAV1M6oKI2Vp4HheqzJ822c60UyWyapvyjSzY/A==}
|
||||||
|
engines: {node: '>=14.0.0'}
|
||||||
|
peerDependencies:
|
||||||
|
react: ^17.0.0 || ^18.0.0
|
||||||
|
|
||||||
'@popperjs/core@2.11.8':
|
'@popperjs/core@2.11.8':
|
||||||
resolution: {integrity: sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==}
|
resolution: {integrity: sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==}
|
||||||
|
|
||||||
@@ -573,8 +591,8 @@ packages:
|
|||||||
'@types/prop-types@15.7.12':
|
'@types/prop-types@15.7.12':
|
||||||
resolution: {integrity: sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==}
|
resolution: {integrity: sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==}
|
||||||
|
|
||||||
'@types/react-transition-group@4.4.10':
|
'@types/react-transition-group@4.4.11':
|
||||||
resolution: {integrity: sha512-hT/+s0VQs2ojCX823m60m5f0sL5idt9SO6Tj6Dg+rdphGPIeJbJ6CxvBYkgkGKrYeDjvIpKTR38UzmtHJOGW3Q==}
|
resolution: {integrity: sha512-RM05tAniPZ5DZPzzNFP+DmrcOdD0efDUxMy3145oljWSl3x9ZV5vhme98gTxFrj2lhXvmGNnUiuDyJgY9IKkNA==}
|
||||||
|
|
||||||
'@types/react@18.3.3':
|
'@types/react@18.3.3':
|
||||||
resolution: {integrity: sha512-hti/R0pS0q1/xx+TsI73XIqk26eBsISZ2R0wUijXIngRK9R/e7Xw/cXVxQK7R5JjW+SV4zGcn5hXjudkN/pLIw==}
|
resolution: {integrity: sha512-hti/R0pS0q1/xx+TsI73XIqk26eBsISZ2R0wUijXIngRK9R/e7Xw/cXVxQK7R5JjW+SV4zGcn5hXjudkN/pLIw==}
|
||||||
@@ -1107,6 +1125,10 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
regenerator-runtime: 0.14.1
|
regenerator-runtime: 0.14.1
|
||||||
|
|
||||||
|
'@babel/runtime@7.25.6':
|
||||||
|
dependencies:
|
||||||
|
regenerator-runtime: 0.14.1
|
||||||
|
|
||||||
'@babel/template@7.22.15':
|
'@babel/template@7.22.15':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/code-frame': 7.23.5
|
'@babel/code-frame': 7.23.5
|
||||||
@@ -1134,18 +1156,10 @@ snapshots:
|
|||||||
'@babel/helper-validator-identifier': 7.22.20
|
'@babel/helper-validator-identifier': 7.22.20
|
||||||
to-fast-properties: 2.0.0
|
to-fast-properties: 2.0.0
|
||||||
|
|
||||||
'@date-io/core@3.0.0': {}
|
|
||||||
|
|
||||||
'@date-io/date-fns@3.0.0(date-fns@3.6.0)':
|
|
||||||
dependencies:
|
|
||||||
'@date-io/core': 3.0.0
|
|
||||||
optionalDependencies:
|
|
||||||
date-fns: 3.6.0
|
|
||||||
|
|
||||||
'@emotion/babel-plugin@11.12.0':
|
'@emotion/babel-plugin@11.12.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/helper-module-imports': 7.22.15
|
'@babel/helper-module-imports': 7.22.15
|
||||||
'@babel/runtime': 7.25.0
|
'@babel/runtime': 7.25.6
|
||||||
'@emotion/hash': 0.9.2
|
'@emotion/hash': 0.9.2
|
||||||
'@emotion/memoize': 0.9.0
|
'@emotion/memoize': 0.9.0
|
||||||
'@emotion/serialize': 1.3.0
|
'@emotion/serialize': 1.3.0
|
||||||
@@ -1155,6 +1169,7 @@ snapshots:
|
|||||||
find-root: 1.1.0
|
find-root: 1.1.0
|
||||||
source-map: 0.5.7
|
source-map: 0.5.7
|
||||||
stylis: 4.2.0
|
stylis: 4.2.0
|
||||||
|
optional: true
|
||||||
|
|
||||||
'@emotion/cache@11.13.1':
|
'@emotion/cache@11.13.1':
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -1164,17 +1179,19 @@ snapshots:
|
|||||||
'@emotion/weak-memoize': 0.4.0
|
'@emotion/weak-memoize': 0.4.0
|
||||||
stylis: 4.2.0
|
stylis: 4.2.0
|
||||||
|
|
||||||
'@emotion/hash@0.9.2': {}
|
'@emotion/hash@0.9.2':
|
||||||
|
optional: true
|
||||||
|
|
||||||
'@emotion/is-prop-valid@1.3.0':
|
'@emotion/is-prop-valid@1.3.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@emotion/memoize': 0.9.0
|
'@emotion/memoize': 0.9.0
|
||||||
|
optional: true
|
||||||
|
|
||||||
'@emotion/memoize@0.9.0': {}
|
'@emotion/memoize@0.9.0': {}
|
||||||
|
|
||||||
'@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1)':
|
'@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/runtime': 7.25.0
|
'@babel/runtime': 7.25.6
|
||||||
'@emotion/babel-plugin': 11.12.0
|
'@emotion/babel-plugin': 11.12.0
|
||||||
'@emotion/cache': 11.13.1
|
'@emotion/cache': 11.13.1
|
||||||
'@emotion/serialize': 1.3.0
|
'@emotion/serialize': 1.3.0
|
||||||
@@ -1185,6 +1202,7 @@ snapshots:
|
|||||||
react: 18.3.1
|
react: 18.3.1
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@types/react': 18.3.3
|
'@types/react': 18.3.3
|
||||||
|
optional: true
|
||||||
|
|
||||||
'@emotion/serialize@1.3.0':
|
'@emotion/serialize@1.3.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -1193,12 +1211,13 @@ snapshots:
|
|||||||
'@emotion/unitless': 0.9.0
|
'@emotion/unitless': 0.9.0
|
||||||
'@emotion/utils': 1.4.0
|
'@emotion/utils': 1.4.0
|
||||||
csstype: 3.1.3
|
csstype: 3.1.3
|
||||||
|
optional: true
|
||||||
|
|
||||||
'@emotion/sheet@1.4.0': {}
|
'@emotion/sheet@1.4.0': {}
|
||||||
|
|
||||||
'@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)':
|
'@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/runtime': 7.25.0
|
'@babel/runtime': 7.25.6
|
||||||
'@emotion/babel-plugin': 11.12.0
|
'@emotion/babel-plugin': 11.12.0
|
||||||
'@emotion/is-prop-valid': 1.3.0
|
'@emotion/is-prop-valid': 1.3.0
|
||||||
'@emotion/react': 11.13.0(@types/react@18.3.3)(react@18.3.1)
|
'@emotion/react': 11.13.0(@types/react@18.3.3)(react@18.3.1)
|
||||||
@@ -1208,12 +1227,15 @@ snapshots:
|
|||||||
react: 18.3.1
|
react: 18.3.1
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@types/react': 18.3.3
|
'@types/react': 18.3.3
|
||||||
|
optional: true
|
||||||
|
|
||||||
'@emotion/unitless@0.9.0': {}
|
'@emotion/unitless@0.9.0':
|
||||||
|
optional: true
|
||||||
|
|
||||||
'@emotion/use-insertion-effect-with-fallbacks@1.1.0(react@18.3.1)':
|
'@emotion/use-insertion-effect-with-fallbacks@1.1.0(react@18.3.1)':
|
||||||
dependencies:
|
dependencies:
|
||||||
react: 18.3.1
|
react: 18.3.1
|
||||||
|
optional: true
|
||||||
|
|
||||||
'@emotion/utils@1.4.0': {}
|
'@emotion/utils@1.4.0': {}
|
||||||
|
|
||||||
@@ -1304,17 +1326,25 @@ snapshots:
|
|||||||
|
|
||||||
'@kurkle/color@0.3.2': {}
|
'@kurkle/color@0.3.2': {}
|
||||||
|
|
||||||
'@mui/core-downloads-tracker@5.16.6': {}
|
'@mui/core-downloads-tracker@6.1.1': {}
|
||||||
|
|
||||||
'@mui/material@5.16.6(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
|
'@mui/icons-material@6.1.1(@mui/material@6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/runtime': 7.25.0
|
'@babel/runtime': 7.25.6
|
||||||
'@mui/core-downloads-tracker': 5.16.6
|
'@mui/material': 6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||||
'@mui/system': 5.16.6(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
react: 18.3.1
|
||||||
'@mui/types': 7.2.15(@types/react@18.3.3)
|
optionalDependencies:
|
||||||
'@mui/utils': 5.16.6(@types/react@18.3.3)(react@18.3.1)
|
'@types/react': 18.3.3
|
||||||
|
|
||||||
|
'@mui/material@6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
|
||||||
|
dependencies:
|
||||||
|
'@babel/runtime': 7.25.6
|
||||||
|
'@mui/core-downloads-tracker': 6.1.1
|
||||||
|
'@mui/system': 6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
||||||
|
'@mui/types': 7.2.17(@types/react@18.3.3)
|
||||||
|
'@mui/utils': 6.1.1(@types/react@18.3.3)(react@18.3.1)
|
||||||
'@popperjs/core': 2.11.8
|
'@popperjs/core': 2.11.8
|
||||||
'@types/react-transition-group': 4.4.10
|
'@types/react-transition-group': 4.4.11
|
||||||
clsx: 2.1.1
|
clsx: 2.1.1
|
||||||
csstype: 3.1.3
|
csstype: 3.1.3
|
||||||
prop-types: 15.8.1
|
prop-types: 15.8.1
|
||||||
@@ -1327,19 +1357,20 @@ snapshots:
|
|||||||
'@emotion/styled': 11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
'@emotion/styled': 11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
||||||
'@types/react': 18.3.3
|
'@types/react': 18.3.3
|
||||||
|
|
||||||
'@mui/private-theming@5.16.6(@types/react@18.3.3)(react@18.3.1)':
|
'@mui/private-theming@6.1.1(@types/react@18.3.3)(react@18.3.1)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/runtime': 7.25.0
|
'@babel/runtime': 7.25.6
|
||||||
'@mui/utils': 5.16.6(@types/react@18.3.3)(react@18.3.1)
|
'@mui/utils': 6.1.1(@types/react@18.3.3)(react@18.3.1)
|
||||||
prop-types: 15.8.1
|
prop-types: 15.8.1
|
||||||
react: 18.3.1
|
react: 18.3.1
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@types/react': 18.3.3
|
'@types/react': 18.3.3
|
||||||
|
|
||||||
'@mui/styled-engine@5.16.6(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(react@18.3.1)':
|
'@mui/styled-engine@6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(react@18.3.1)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/runtime': 7.25.0
|
'@babel/runtime': 7.25.6
|
||||||
'@emotion/cache': 11.13.1
|
'@emotion/cache': 11.13.1
|
||||||
|
'@emotion/sheet': 1.4.0
|
||||||
csstype: 3.1.3
|
csstype: 3.1.3
|
||||||
prop-types: 15.8.1
|
prop-types: 15.8.1
|
||||||
react: 18.3.1
|
react: 18.3.1
|
||||||
@@ -1347,13 +1378,13 @@ snapshots:
|
|||||||
'@emotion/react': 11.13.0(@types/react@18.3.3)(react@18.3.1)
|
'@emotion/react': 11.13.0(@types/react@18.3.3)(react@18.3.1)
|
||||||
'@emotion/styled': 11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
'@emotion/styled': 11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
||||||
|
|
||||||
'@mui/system@5.16.6(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)':
|
'@mui/system@6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/runtime': 7.25.0
|
'@babel/runtime': 7.25.6
|
||||||
'@mui/private-theming': 5.16.6(@types/react@18.3.3)(react@18.3.1)
|
'@mui/private-theming': 6.1.1(@types/react@18.3.3)(react@18.3.1)
|
||||||
'@mui/styled-engine': 5.16.6(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(react@18.3.1)
|
'@mui/styled-engine': 6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(react@18.3.1)
|
||||||
'@mui/types': 7.2.15(@types/react@18.3.3)
|
'@mui/types': 7.2.17(@types/react@18.3.3)
|
||||||
'@mui/utils': 5.16.6(@types/react@18.3.3)(react@18.3.1)
|
'@mui/utils': 6.1.1(@types/react@18.3.3)(react@18.3.1)
|
||||||
clsx: 2.1.1
|
clsx: 2.1.1
|
||||||
csstype: 3.1.3
|
csstype: 3.1.3
|
||||||
prop-types: 15.8.1
|
prop-types: 15.8.1
|
||||||
@@ -1363,14 +1394,14 @@ snapshots:
|
|||||||
'@emotion/styled': 11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
'@emotion/styled': 11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
||||||
'@types/react': 18.3.3
|
'@types/react': 18.3.3
|
||||||
|
|
||||||
'@mui/types@7.2.15(@types/react@18.3.3)':
|
'@mui/types@7.2.17(@types/react@18.3.3)':
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@types/react': 18.3.3
|
'@types/react': 18.3.3
|
||||||
|
|
||||||
'@mui/utils@5.16.6(@types/react@18.3.3)(react@18.3.1)':
|
'@mui/utils@5.16.6(@types/react@18.3.3)(react@18.3.1)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/runtime': 7.25.0
|
'@babel/runtime': 7.25.6
|
||||||
'@mui/types': 7.2.15(@types/react@18.3.3)
|
'@mui/types': 7.2.17(@types/react@18.3.3)
|
||||||
'@types/prop-types': 15.7.12
|
'@types/prop-types': 15.7.12
|
||||||
clsx: 2.1.1
|
clsx: 2.1.1
|
||||||
prop-types: 15.8.1
|
prop-types: 15.8.1
|
||||||
@@ -1379,13 +1410,26 @@ snapshots:
|
|||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@types/react': 18.3.3
|
'@types/react': 18.3.3
|
||||||
|
|
||||||
'@mui/x-date-pickers@7.12.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@mui/material@5.16.6(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(@types/react@18.3.3)(date-fns@3.6.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
|
'@mui/utils@6.1.1(@types/react@18.3.3)(react@18.3.1)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/runtime': 7.25.0
|
'@babel/runtime': 7.25.6
|
||||||
'@mui/material': 5.16.6(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
'@mui/types': 7.2.17(@types/react@18.3.3)
|
||||||
'@mui/system': 5.16.6(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
'@types/prop-types': 15.7.12
|
||||||
|
clsx: 2.1.1
|
||||||
|
prop-types: 15.8.1
|
||||||
|
react: 18.3.1
|
||||||
|
react-is: 18.3.1
|
||||||
|
optionalDependencies:
|
||||||
|
'@types/react': 18.3.3
|
||||||
|
|
||||||
|
'@mui/x-date-pickers@7.18.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@mui/material@6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(@mui/system@6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(date-fns@3.6.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
|
||||||
|
dependencies:
|
||||||
|
'@babel/runtime': 7.25.6
|
||||||
|
'@mui/material': 6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||||
|
'@mui/system': 6.1.1(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.0(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1))(@types/react@18.3.3)(react@18.3.1)
|
||||||
'@mui/utils': 5.16.6(@types/react@18.3.3)(react@18.3.1)
|
'@mui/utils': 5.16.6(@types/react@18.3.3)(react@18.3.1)
|
||||||
'@types/react-transition-group': 4.4.10
|
'@mui/x-internals': 7.18.0(@types/react@18.3.3)(react@18.3.1)
|
||||||
|
'@types/react-transition-group': 4.4.11
|
||||||
clsx: 2.1.1
|
clsx: 2.1.1
|
||||||
prop-types: 15.8.1
|
prop-types: 15.8.1
|
||||||
react: 18.3.1
|
react: 18.3.1
|
||||||
@@ -1398,6 +1442,14 @@ snapshots:
|
|||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- '@types/react'
|
- '@types/react'
|
||||||
|
|
||||||
|
'@mui/x-internals@7.18.0(@types/react@18.3.3)(react@18.3.1)':
|
||||||
|
dependencies:
|
||||||
|
'@babel/runtime': 7.25.6
|
||||||
|
'@mui/utils': 5.16.6(@types/react@18.3.3)(react@18.3.1)
|
||||||
|
react: 18.3.1
|
||||||
|
transitivePeerDependencies:
|
||||||
|
- '@types/react'
|
||||||
|
|
||||||
'@popperjs/core@2.11.8': {}
|
'@popperjs/core@2.11.8': {}
|
||||||
|
|
||||||
'@preact/preset-vite@2.8.1(@babel/core@7.23.7)(preact@10.19.3)(vite@4.5.1)':
|
'@preact/preset-vite@2.8.1(@babel/core@7.23.7)(preact@10.19.3)(vite@4.5.1)':
|
||||||
@@ -1456,11 +1508,12 @@ snapshots:
|
|||||||
|
|
||||||
'@trpc/server@10.45.0': {}
|
'@trpc/server@10.45.0': {}
|
||||||
|
|
||||||
'@types/parse-json@4.0.2': {}
|
'@types/parse-json@4.0.2':
|
||||||
|
optional: true
|
||||||
|
|
||||||
'@types/prop-types@15.7.12': {}
|
'@types/prop-types@15.7.12': {}
|
||||||
|
|
||||||
'@types/react-transition-group@4.4.10':
|
'@types/react-transition-group@4.4.11':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/react': 18.3.3
|
'@types/react': 18.3.3
|
||||||
|
|
||||||
@@ -1475,9 +1528,10 @@ snapshots:
|
|||||||
|
|
||||||
babel-plugin-macros@3.1.0:
|
babel-plugin-macros@3.1.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/runtime': 7.25.0
|
'@babel/runtime': 7.25.6
|
||||||
cosmiconfig: 7.1.0
|
cosmiconfig: 7.1.0
|
||||||
resolve: 1.22.8
|
resolve: 1.22.8
|
||||||
|
optional: true
|
||||||
|
|
||||||
babel-plugin-transform-hook-names@1.0.2(@babel/core@7.23.7):
|
babel-plugin-transform-hook-names@1.0.2(@babel/core@7.23.7):
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -1492,7 +1546,8 @@ snapshots:
|
|||||||
node-releases: 2.0.14
|
node-releases: 2.0.14
|
||||||
update-browserslist-db: 1.0.13(browserslist@4.22.2)
|
update-browserslist-db: 1.0.13(browserslist@4.22.2)
|
||||||
|
|
||||||
callsites@3.1.0: {}
|
callsites@3.1.0:
|
||||||
|
optional: true
|
||||||
|
|
||||||
caniuse-lite@1.0.30001575: {}
|
caniuse-lite@1.0.30001575: {}
|
||||||
|
|
||||||
@@ -1514,7 +1569,8 @@ snapshots:
|
|||||||
|
|
||||||
color-name@1.1.3: {}
|
color-name@1.1.3: {}
|
||||||
|
|
||||||
convert-source-map@1.9.0: {}
|
convert-source-map@1.9.0:
|
||||||
|
optional: true
|
||||||
|
|
||||||
convert-source-map@2.0.0: {}
|
convert-source-map@2.0.0: {}
|
||||||
|
|
||||||
@@ -1525,6 +1581,7 @@ snapshots:
|
|||||||
parse-json: 5.2.0
|
parse-json: 5.2.0
|
||||||
path-type: 4.0.0
|
path-type: 4.0.0
|
||||||
yaml: 1.10.2
|
yaml: 1.10.2
|
||||||
|
optional: true
|
||||||
|
|
||||||
css-select@5.1.0:
|
css-select@5.1.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -1576,6 +1633,7 @@ snapshots:
|
|||||||
error-ex@1.3.2:
|
error-ex@1.3.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
is-arrayish: 0.2.1
|
is-arrayish: 0.2.1
|
||||||
|
optional: true
|
||||||
|
|
||||||
esbuild@0.18.20:
|
esbuild@0.18.20:
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
@@ -1606,11 +1664,13 @@ snapshots:
|
|||||||
|
|
||||||
escape-string-regexp@1.0.5: {}
|
escape-string-regexp@1.0.5: {}
|
||||||
|
|
||||||
escape-string-regexp@4.0.0: {}
|
escape-string-regexp@4.0.0:
|
||||||
|
optional: true
|
||||||
|
|
||||||
estree-walker@2.0.2: {}
|
estree-walker@2.0.2: {}
|
||||||
|
|
||||||
find-root@1.1.0: {}
|
find-root@1.1.0:
|
||||||
|
optional: true
|
||||||
|
|
||||||
fsevents@2.3.3:
|
fsevents@2.3.3:
|
||||||
optional: true
|
optional: true
|
||||||
@@ -1632,13 +1692,16 @@ snapshots:
|
|||||||
hoist-non-react-statics@3.3.2:
|
hoist-non-react-statics@3.3.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
react-is: 16.13.1
|
react-is: 16.13.1
|
||||||
|
optional: true
|
||||||
|
|
||||||
import-fresh@3.3.0:
|
import-fresh@3.3.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
parent-module: 1.0.1
|
parent-module: 1.0.1
|
||||||
resolve-from: 4.0.0
|
resolve-from: 4.0.0
|
||||||
|
optional: true
|
||||||
|
|
||||||
is-arrayish@0.2.1: {}
|
is-arrayish@0.2.1:
|
||||||
|
optional: true
|
||||||
|
|
||||||
is-core-module@2.13.1:
|
is-core-module@2.13.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -1648,13 +1711,15 @@ snapshots:
|
|||||||
|
|
||||||
jsesc@2.5.2: {}
|
jsesc@2.5.2: {}
|
||||||
|
|
||||||
json-parse-even-better-errors@2.3.1: {}
|
json-parse-even-better-errors@2.3.1:
|
||||||
|
optional: true
|
||||||
|
|
||||||
json5@2.2.3: {}
|
json5@2.2.3: {}
|
||||||
|
|
||||||
kolorist@1.8.0: {}
|
kolorist@1.8.0: {}
|
||||||
|
|
||||||
lines-and-columns@1.2.4: {}
|
lines-and-columns@1.2.4:
|
||||||
|
optional: true
|
||||||
|
|
||||||
loose-envify@1.4.0:
|
loose-envify@1.4.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -1688,6 +1753,7 @@ snapshots:
|
|||||||
parent-module@1.0.1:
|
parent-module@1.0.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
callsites: 3.1.0
|
callsites: 3.1.0
|
||||||
|
optional: true
|
||||||
|
|
||||||
parse-json@5.2.0:
|
parse-json@5.2.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -1695,10 +1761,12 @@ snapshots:
|
|||||||
error-ex: 1.3.2
|
error-ex: 1.3.2
|
||||||
json-parse-even-better-errors: 2.3.1
|
json-parse-even-better-errors: 2.3.1
|
||||||
lines-and-columns: 1.2.4
|
lines-and-columns: 1.2.4
|
||||||
|
optional: true
|
||||||
|
|
||||||
path-parse@1.0.7: {}
|
path-parse@1.0.7: {}
|
||||||
|
|
||||||
path-type@4.0.0: {}
|
path-type@4.0.0:
|
||||||
|
optional: true
|
||||||
|
|
||||||
picocolors@1.0.0: {}
|
picocolors@1.0.0: {}
|
||||||
|
|
||||||
@@ -1761,7 +1829,8 @@ snapshots:
|
|||||||
|
|
||||||
regenerator-runtime@0.14.1: {}
|
regenerator-runtime@0.14.1: {}
|
||||||
|
|
||||||
resolve-from@4.0.0: {}
|
resolve-from@4.0.0:
|
||||||
|
optional: true
|
||||||
|
|
||||||
resolve@1.22.8:
|
resolve@1.22.8:
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -1781,7 +1850,8 @@ snapshots:
|
|||||||
|
|
||||||
source-map-js@1.2.0: {}
|
source-map-js@1.2.0: {}
|
||||||
|
|
||||||
source-map@0.5.7: {}
|
source-map@0.5.7:
|
||||||
|
optional: true
|
||||||
|
|
||||||
stylis@4.2.0: {}
|
stylis@4.2.0: {}
|
||||||
|
|
||||||
@@ -1811,4 +1881,5 @@ snapshots:
|
|||||||
|
|
||||||
yallist@3.1.1: {}
|
yallist@3.1.1: {}
|
||||||
|
|
||||||
yaml@1.10.2: {}
|
yaml@1.10.2:
|
||||||
|
optional: true
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { signal, computed } from "@preact/signals";
|
|
||||||
import { useEffect } from "preact/hooks";
|
import { useEffect } from "preact/hooks";
|
||||||
import { trpc } from "../trpc.js";
|
import { trpc } from "../trpc.js";
|
||||||
import {
|
import {
|
||||||
@@ -6,195 +5,65 @@ import {
|
|||||||
LinearScale,
|
LinearScale,
|
||||||
CategoryScale,
|
CategoryScale,
|
||||||
PointElement,
|
PointElement,
|
||||||
|
LineElement,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
Title,
|
Title,
|
||||||
} from "chart.js";
|
} from "chart.js";
|
||||||
import { Scatter } from "react-chartjs-2";
|
import { Scatter } from "react-chartjs-2";
|
||||||
import {
|
import {
|
||||||
Container,
|
Container,
|
||||||
Grid,
|
Grid2,
|
||||||
Typography,
|
Typography,
|
||||||
TextField,
|
|
||||||
Select,
|
|
||||||
MenuItem,
|
|
||||||
InputLabel,
|
|
||||||
FormControl,
|
|
||||||
Paper,
|
Paper,
|
||||||
|
Popper,
|
||||||
|
ClickAwayListener,
|
||||||
|
Stack,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
import {
|
||||||
|
availableUnderlyings,
|
||||||
|
calendarExitPriceChartData,
|
||||||
|
isPopperOpen,
|
||||||
|
lookbackPeriodEnd,
|
||||||
|
lookbackPeriodStart,
|
||||||
|
maxChartPrice,
|
||||||
|
maxN,
|
||||||
|
popperAnchorEl,
|
||||||
|
popperContent,
|
||||||
|
similarCalendarPriceChartData,
|
||||||
|
stockPriceChartData,
|
||||||
|
underlying,
|
||||||
|
} from "./HistoricalCalendarPrices/state.js";
|
||||||
|
import { EditableStrike } from "./HistoricalCalendarPrices/EditableStrike.js";
|
||||||
|
import {
|
||||||
|
refreshcalendarExitPriceChartData,
|
||||||
|
refreshSimilarCalendarPriceChartData,
|
||||||
|
refreshStockPriceChartData,
|
||||||
|
} from "./HistoricalCalendarPrices/actions.js";
|
||||||
|
import { EditableUnderlying } from "./HistoricalCalendarPrices/EditableUnderlying.js";
|
||||||
|
import { EditableOpenDTE } from "./HistoricalCalendarPrices/EditableOpenDTE.js";
|
||||||
|
import { EditableExitDTE } from "./HistoricalCalendarPrices/EditableExitDTE.js";
|
||||||
|
import { EditableSpan } from "./HistoricalCalendarPrices/EditableSpan.js";
|
||||||
|
import { EditableLookbackPeriod } from "./HistoricalCalendarPrices/EditableLookbackPeriod.js";
|
||||||
|
|
||||||
ChartJS.register(LinearScale, CategoryScale, PointElement, Tooltip, Title);
|
ChartJS.register(
|
||||||
|
LinearScale,
|
||||||
const availableUnderlyings = signal([]);
|
CategoryScale,
|
||||||
const chosenUnderlying = signal(null);
|
PointElement,
|
||||||
|
LineElement,
|
||||||
const chosenDaysToFrontExpiration = signal(14);
|
Tooltip,
|
||||||
|
Title
|
||||||
const chosenDaysBetweenFrontAndBackExpiration = signal(14);
|
|
||||||
|
|
||||||
const chosenStrikePercentageFromUnderlyingPrice = signal(1.4);
|
|
||||||
const chosenStrikePercentageFromUnderlyingPriceRadius = signal(0.05);
|
|
||||||
|
|
||||||
const chosenExitToFrontExpiration = signal(2);
|
|
||||||
|
|
||||||
const historicalStockQuoteChartData = signal([]);
|
|
||||||
|
|
||||||
const historicalCalendarQuoteChartData = signal([]);
|
|
||||||
|
|
||||||
const historicalCalendarExitQuoteChartData = signal([]);
|
|
||||||
|
|
||||||
const chosenLookbackPeriodStart = signal("2022-01-01");
|
|
||||||
const chosenLookbackPeriodEnd = signal("2024-01-01");
|
|
||||||
|
|
||||||
const maxChartPrice = computed(() =>
|
|
||||||
Math.max(
|
|
||||||
Math.max.apply(
|
|
||||||
null,
|
|
||||||
historicalCalendarQuoteChartData.value.map((d) => d.y),
|
|
||||||
),
|
|
||||||
Math.max.apply(
|
|
||||||
null,
|
|
||||||
historicalCalendarExitQuoteChartData.value.map((d) => d.y),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const maxN = computed(() =>
|
|
||||||
Math.max.apply(
|
|
||||||
null,
|
|
||||||
historicalCalendarExitQuoteChartData.value.map((d) => d.n),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
const refreshHistoricalStockQuoteChartData = () => {
|
|
||||||
historicalStockQuoteChartData.value = [];
|
|
||||||
trpc.getHistoricalStockQuoteChartData
|
|
||||||
.query({
|
|
||||||
underlying: chosenUnderlying.value,
|
|
||||||
lookbackPeriodStart: chosenLookbackPeriodStart.value,
|
|
||||||
lookbackPeriodEnd: chosenLookbackPeriodEnd.value,
|
|
||||||
})
|
|
||||||
.then((getHistoricalStockQuoteChartDataResponse) => {
|
|
||||||
historicalStockQuoteChartData.value =
|
|
||||||
getHistoricalStockQuoteChartDataResponse;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const refreshHistoricalCalendarQuoteChartData = () => {
|
|
||||||
historicalCalendarQuoteChartData.value = [];
|
|
||||||
trpc.getHistoricalCalendarQuoteChartData
|
|
||||||
.query({
|
|
||||||
underlying: chosenUnderlying.value,
|
|
||||||
daysToFrontExpiration: chosenDaysToFrontExpiration.value,
|
|
||||||
daysBetweenFrontAndBackExpiration:
|
|
||||||
chosenDaysBetweenFrontAndBackExpiration.value,
|
|
||||||
strikePercentageFromUnderlyingPriceRangeMin:
|
|
||||||
chosenStrikePercentageFromUnderlyingPrice.value -
|
|
||||||
chosenStrikePercentageFromUnderlyingPriceRadius.value,
|
|
||||||
strikePercentageFromUnderlyingPriceRangeMax:
|
|
||||||
chosenStrikePercentageFromUnderlyingPrice.value +
|
|
||||||
chosenStrikePercentageFromUnderlyingPriceRadius.value,
|
|
||||||
lookbackPeriodStart: chosenLookbackPeriodStart.value,
|
|
||||||
lookbackPeriodEnd: chosenLookbackPeriodEnd.value,
|
|
||||||
})
|
|
||||||
.then((getHistoricalCalendarQuoteChartDataResponse) => {
|
|
||||||
historicalCalendarQuoteChartData.value =
|
|
||||||
getHistoricalCalendarQuoteChartDataResponse;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const refreshHistoricalCalendarExitQuoteChartData = () => {
|
|
||||||
historicalCalendarExitQuoteChartData.value = [];
|
|
||||||
trpc.getHistoricalCalendarExitQuoteChartData
|
|
||||||
.query({
|
|
||||||
underlying: chosenUnderlying.value,
|
|
||||||
daysToFrontExpiration: chosenExitToFrontExpiration.value,
|
|
||||||
daysBetweenFrontAndBackExpiration:
|
|
||||||
chosenDaysBetweenFrontAndBackExpiration.value,
|
|
||||||
lookbackPeriodStart: chosenLookbackPeriodStart.value,
|
|
||||||
lookbackPeriodEnd: chosenLookbackPeriodEnd.value,
|
|
||||||
})
|
|
||||||
.then((getHistoricalCalendarExitQuoteChartDataResponse) => {
|
|
||||||
historicalCalendarExitQuoteChartData.value =
|
|
||||||
getHistoricalCalendarExitQuoteChartDataResponse;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const handleInit = () => {
|
const handleInit = () => {
|
||||||
trpc.getAvailableUnderlyings.query().then((availableUnderlyingsResponse) => {
|
trpc.CalendarCharacteristicsForm.getAvailableUnderlyings
|
||||||
availableUnderlyings.value = availableUnderlyingsResponse;
|
.query()
|
||||||
chosenUnderlying.value = availableUnderlyingsResponse[0];
|
.then((availableUnderlyingsResponse) => {
|
||||||
refreshHistoricalStockQuoteChartData();
|
availableUnderlyings.value = availableUnderlyingsResponse;
|
||||||
refreshHistoricalCalendarQuoteChartData();
|
underlying.value = availableUnderlyingsResponse[0];
|
||||||
refreshHistoricalCalendarExitQuoteChartData();
|
refreshStockPriceChartData();
|
||||||
});
|
refreshSimilarCalendarPriceChartData();
|
||||||
};
|
refreshcalendarExitPriceChartData();
|
||||||
const handleUnderlyingChange = (e) => {
|
});
|
||||||
if (chosenUnderlying.value !== e.target.value) {
|
|
||||||
chosenUnderlying.value = e.target.value;
|
|
||||||
refreshHistoricalStockQuoteChartData();
|
|
||||||
refreshHistoricalCalendarQuoteChartData();
|
|
||||||
refreshHistoricalCalendarExitQuoteChartData();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const handleDaysToFrontExpirationChange = (e) => {
|
|
||||||
if (chosenDaysToFrontExpiration.value !== Number.parseInt(e.target.value)) {
|
|
||||||
chosenDaysToFrontExpiration.value = Number.parseInt(e.target.value);
|
|
||||||
refreshHistoricalCalendarQuoteChartData();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const handleDaysBetweenFrontAndBackExpirationChange = (e) => {
|
|
||||||
if (
|
|
||||||
chosenDaysBetweenFrontAndBackExpiration.value !==
|
|
||||||
Number.parseInt(e.target.value)
|
|
||||||
) {
|
|
||||||
chosenDaysBetweenFrontAndBackExpiration.value = Number.parseInt(
|
|
||||||
e.target.value,
|
|
||||||
);
|
|
||||||
refreshHistoricalCalendarQuoteChartData();
|
|
||||||
refreshHistoricalCalendarExitQuoteChartData();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const handleStrikePercentageFromUnderlyingPriceChange = (e) => {
|
|
||||||
if (
|
|
||||||
chosenStrikePercentageFromUnderlyingPrice.value !==
|
|
||||||
Number.parseFloat(e.target.value)
|
|
||||||
) {
|
|
||||||
chosenStrikePercentageFromUnderlyingPrice.value = Number.parseFloat(
|
|
||||||
e.target.value,
|
|
||||||
);
|
|
||||||
refreshHistoricalCalendarQuoteChartData();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const handleStrikePercentageFromUnderlyingPriceRadiusChange = (e) => {
|
|
||||||
if (
|
|
||||||
chosenStrikePercentageFromUnderlyingPriceRadius.value !==
|
|
||||||
Number.parseFloat(e.target.value)
|
|
||||||
) {
|
|
||||||
chosenStrikePercentageFromUnderlyingPriceRadius.value = Number.parseFloat(
|
|
||||||
e.target.value,
|
|
||||||
);
|
|
||||||
refreshHistoricalCalendarQuoteChartData();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const handleExitToFrontExpirationChange = (e) => {
|
|
||||||
if (chosenExitToFrontExpiration.value !== Number.parseInt(e.target.value)) {
|
|
||||||
chosenExitToFrontExpiration.value = Number.parseInt(e.target.value);
|
|
||||||
refreshHistoricalCalendarExitQuoteChartData();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleLookbackPeriodStartChange = (e) => {
|
|
||||||
if (chosenLookbackPeriodStart.value !== e.target.value) {
|
|
||||||
chosenLookbackPeriodStart.value = e.target.value;
|
|
||||||
refreshHistoricalStockQuoteChartData();
|
|
||||||
refreshHistoricalCalendarQuoteChartData();
|
|
||||||
refreshHistoricalCalendarExitQuoteChartData();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const handleLookbackPeriodEndChange = (e) => {
|
|
||||||
if (chosenLookbackPeriodEnd.value !== e.target.value) {
|
|
||||||
chosenLookbackPeriodEnd.value = e.target.value;
|
|
||||||
refreshHistoricalStockQuoteChartData();
|
|
||||||
refreshHistoricalCalendarQuoteChartData();
|
|
||||||
refreshHistoricalCalendarExitQuoteChartData();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function HistoricalCalendarPrices() {
|
export function HistoricalCalendarPrices() {
|
||||||
@@ -202,193 +71,94 @@ export function HistoricalCalendarPrices() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Container maxWidth="lg">
|
<Container maxWidth="lg">
|
||||||
<Grid container spacing={4}>
|
<Grid2 container spacing={4} columns={12}>
|
||||||
<Grid item xs={12}>
|
{/* <Grid2 size={{ xs: 12 }}>
|
||||||
|
|
||||||
<Typography variant="h4" gutterBottom>
|
<Typography variant="h4" gutterBottom>
|
||||||
Historical Calendar Prices
|
<EditableUnderlying /> :
|
||||||
|
<EditableSpan />
|
||||||
|
-Day Calendar @ <EditableStrike />
|
||||||
|
%-from-the-money
|
||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
<Typography variant="h5" gutterBottom sx={{ pl: 1 }}>
|
||||||
<Grid item xs={12} md={6}>
|
Opening at <EditableOpenDTE /> DTE, Closing at <EditableExitDTE />
|
||||||
<Paper elevation={3} sx={{ p: 3 }}>
|
DTE
|
||||||
<Grid container spacing={2}>
|
</Typography>
|
||||||
<Grid item xs={12}>
|
<Typography variant="h5" gutterBottom>
|
||||||
<FormControl fullWidth>
|
<EditableLookbackPeriodStart />-
|
||||||
<InputLabel>Available Underlyings</InputLabel>
|
<EditableLookbackPeriodEnd />
|
||||||
<Select
|
</Typography>
|
||||||
value={chosenUnderlying.value || ""}
|
<ClickAwayListener
|
||||||
onChange={handleUnderlyingChange}
|
onClickAway={() => {
|
||||||
label="Available Underlyings"
|
isPopperOpen.value = false;
|
||||||
>
|
// refreshSimilarCalendarPriceChartData();
|
||||||
{availableUnderlyings.value.map((underlying) => (
|
console.log("clicked away");
|
||||||
<MenuItem key={underlying} value={underlying}>
|
}}
|
||||||
{underlying}
|
>
|
||||||
</MenuItem>
|
<Popper open={isPopperOpen.value} anchorEl={popperAnchorEl.value}>
|
||||||
))}
|
<Paper elevation={3} sx={{ p: 3 }}>
|
||||||
</Select>
|
{popperContent.value}
|
||||||
</FormControl>
|
</Paper>
|
||||||
</Grid>
|
</Popper>
|
||||||
<Grid item xs={12}>
|
</ClickAwayListener>
|
||||||
<TextField
|
</Grid2> */}
|
||||||
fullWidth
|
|
||||||
label="Now-to-Front-Month Days to Expiration"
|
<Grid2 size={{ xs: 12 }}>
|
||||||
type="number"
|
<Stack direction="row" spacing={2}>
|
||||||
value={chosenDaysToFrontExpiration.value}
|
<Typography gutterBottom minWidth={"8em"}>
|
||||||
onChange={handleDaysToFrontExpirationChange}
|
Underlying
|
||||||
InputProps={{ endAdornment: "Days" }}
|
</Typography>
|
||||||
/>
|
<EditableUnderlying />
|
||||||
</Grid>
|
</Stack>
|
||||||
<Grid item xs={12}>
|
<Stack direction="row" spacing={2}>
|
||||||
<TextField
|
<Typography gutterBottom minWidth={"8em"}>
|
||||||
fullWidth
|
Open DTE
|
||||||
label="Front-to-Back-Month Days to Expiration Difference"
|
</Typography>
|
||||||
type="number"
|
<EditableOpenDTE />
|
||||||
value={chosenDaysBetweenFrontAndBackExpiration.value}
|
</Stack>
|
||||||
onChange={handleDaysBetweenFrontAndBackExpirationChange}
|
<Stack direction="row" spacing={2}>
|
||||||
InputProps={{ endAdornment: "Days Difference" }}
|
<Typography gutterBottom minWidth={"8em"}>
|
||||||
/>
|
Exit DTE
|
||||||
</Grid>
|
</Typography>
|
||||||
<Grid item xs={6}>
|
<EditableExitDTE />
|
||||||
<TextField
|
</Stack>
|
||||||
fullWidth
|
<Stack direction="row" spacing={2}>
|
||||||
label="Strike % From Underlying Price"
|
<Typography gutterBottom minWidth={"8em"}>
|
||||||
type="number"
|
Span
|
||||||
value={chosenStrikePercentageFromUnderlyingPrice.value}
|
</Typography>
|
||||||
onChange={handleStrikePercentageFromUnderlyingPriceChange}
|
<EditableSpan />
|
||||||
InputProps={{ endAdornment: "%" }}
|
</Stack>
|
||||||
/>
|
<Stack direction="row" spacing={2}>
|
||||||
</Grid>
|
<Typography gutterBottom minWidth={"8em"}>
|
||||||
<Grid item xs={6}>
|
Lookback Period
|
||||||
<TextField
|
</Typography>
|
||||||
fullWidth
|
<EditableLookbackPeriod />
|
||||||
label="Strike % Radius"
|
</Stack>
|
||||||
type="number"
|
<ClickAwayListener
|
||||||
value={chosenStrikePercentageFromUnderlyingPriceRadius.value}
|
onClickAway={() => {
|
||||||
onChange={
|
isPopperOpen.value = false;
|
||||||
handleStrikePercentageFromUnderlyingPriceRadiusChange
|
// refreshSimilarCalendarPriceChartData();
|
||||||
}
|
console.log("clicked away");
|
||||||
InputProps={{ endAdornment: "%" }}
|
}}
|
||||||
/>
|
>
|
||||||
</Grid>
|
<Popper open={isPopperOpen.value} anchorEl={popperAnchorEl.value}>
|
||||||
<Grid item xs={12}>
|
<Paper elevation={3} sx={{ p: 3 }}>
|
||||||
<TextField
|
{popperContent.value}
|
||||||
fullWidth
|
</Paper>
|
||||||
label="Exit-to-Front-Month Days to Expiration"
|
</Popper>
|
||||||
type="number"
|
</ClickAwayListener>
|
||||||
value={chosenExitToFrontExpiration.value}
|
</Grid2>
|
||||||
onChange={handleExitToFrontExpirationChange}
|
|
||||||
InputProps={{ endAdornment: "Days" }}
|
<Grid2 size={{ xs: 12, md: 6 }}>
|
||||||
/>
|
<Paper elevation={3} sx={{ p: 3, minHeight: "28em" }}>
|
||||||
</Grid>
|
{underlying.value !== null &&
|
||||||
<Grid item xs={6}>
|
similarCalendarPriceChartData.value.length > 0 ? (
|
||||||
<TextField
|
|
||||||
fullWidth
|
|
||||||
label="Lookback Period Start"
|
|
||||||
type="date"
|
|
||||||
value={chosenLookbackPeriodStart.value}
|
|
||||||
onChange={(e) =>
|
|
||||||
handleLookbackPeriodStartChange({
|
|
||||||
target: { value: e.target.value },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
InputLabelProps={{ shrink: true }}
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
<Grid item xs={6}>
|
|
||||||
<TextField
|
|
||||||
fullWidth
|
|
||||||
label="Lookback Period End"
|
|
||||||
type="date"
|
|
||||||
value={chosenLookbackPeriodEnd.value}
|
|
||||||
onChange={(e) =>
|
|
||||||
handleLookbackPeriodEndChange({
|
|
||||||
target: { value: e.target.value },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
InputLabelProps={{ shrink: true }}
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
</Paper>
|
|
||||||
</Grid>
|
|
||||||
<Grid item xs={12} md={6}>
|
|
||||||
<Paper elevation={3} sx={{ p: 3, height: "100%" }}>
|
|
||||||
{chosenUnderlying.value !== null &&
|
|
||||||
historicalStockQuoteChartData.value.length > 0 ? (
|
|
||||||
<Scatter
|
|
||||||
data={{
|
|
||||||
datasets: [
|
|
||||||
{
|
|
||||||
label: "Stock Open Price",
|
|
||||||
data: historicalStockQuoteChartData.value,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}}
|
|
||||||
options={{
|
|
||||||
scales: {
|
|
||||||
x: {
|
|
||||||
title: {
|
|
||||||
display: true,
|
|
||||||
text: "Time",
|
|
||||||
},
|
|
||||||
ticks: {
|
|
||||||
callback: (value, index, ticks) =>
|
|
||||||
new Date((value as number) * 1000)
|
|
||||||
.toISOString()
|
|
||||||
.substring(0, 10),
|
|
||||||
},
|
|
||||||
min:
|
|
||||||
new Date(chosenLookbackPeriodStart.value).getTime() /
|
|
||||||
1000,
|
|
||||||
max:
|
|
||||||
new Date(chosenLookbackPeriodEnd.value).getTime() /
|
|
||||||
1000,
|
|
||||||
},
|
|
||||||
y: {
|
|
||||||
beginAtZero: false,
|
|
||||||
ticks: {
|
|
||||||
callback: (value, index, ticks) =>
|
|
||||||
`$${value.toString()}`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
elements: {
|
|
||||||
point: {
|
|
||||||
radius: 1,
|
|
||||||
borderWidth: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
plugins: {
|
|
||||||
tooltip: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
legend: {
|
|
||||||
display: false,
|
|
||||||
},
|
|
||||||
title: {
|
|
||||||
display: true,
|
|
||||||
text: "Stock Price",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
animation: false,
|
|
||||||
maintainAspectRatio: false,
|
|
||||||
events: [],
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Typography>Loading Chart...</Typography>
|
|
||||||
)}
|
|
||||||
</Paper>
|
|
||||||
</Grid>
|
|
||||||
<Grid item xs={12}>
|
|
||||||
<Paper elevation={3} sx={{ p: 3 }}>
|
|
||||||
{chosenUnderlying.value !== null &&
|
|
||||||
historicalCalendarQuoteChartData.value.length > 0 ? (
|
|
||||||
<Scatter
|
<Scatter
|
||||||
data={{
|
data={{
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: "Calendar Open Price",
|
label: "Calendar Open Price",
|
||||||
data: historicalCalendarQuoteChartData.value,
|
data: similarCalendarPriceChartData.value,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}}
|
}}
|
||||||
@@ -405,12 +175,8 @@ export function HistoricalCalendarPrices() {
|
|||||||
.toISOString()
|
.toISOString()
|
||||||
.substring(0, 10),
|
.substring(0, 10),
|
||||||
},
|
},
|
||||||
min:
|
min: new Date(lookbackPeriodStart.value).getTime() / 1000,
|
||||||
new Date(chosenLookbackPeriodStart.value).getTime() /
|
max: new Date(lookbackPeriodEnd.value).getTime() / 1000,
|
||||||
1000,
|
|
||||||
max:
|
|
||||||
new Date(chosenLookbackPeriodEnd.value).getTime() /
|
|
||||||
1000,
|
|
||||||
},
|
},
|
||||||
y: {
|
y: {
|
||||||
beginAtZero: true,
|
beginAtZero: true,
|
||||||
@@ -443,17 +209,17 @@ export function HistoricalCalendarPrices() {
|
|||||||
<Typography>Loading Chart...</Typography>
|
<Typography>Loading Chart...</Typography>
|
||||||
)}
|
)}
|
||||||
</Paper>
|
</Paper>
|
||||||
</Grid>
|
</Grid2>
|
||||||
<Grid item xs={12}>
|
<Grid2 size={{ xs: 12, md: 6 }}>
|
||||||
<Paper elevation={3} sx={{ p: 3 }}>
|
<Paper elevation={3} sx={{ p: 3, minHeight: "28em" }}>
|
||||||
{chosenUnderlying.value !== null &&
|
{underlying.value !== null &&
|
||||||
historicalCalendarQuoteChartData.value.length > 0 ? (
|
calendarExitPriceChartData.value.length > 0 ? (
|
||||||
<Scatter
|
<Scatter
|
||||||
data={{
|
data={{
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: "Calendar Exit Price",
|
label: "Calendar Exit Price",
|
||||||
data: historicalCalendarExitQuoteChartData.value,
|
data: calendarExitPriceChartData.value,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}}
|
}}
|
||||||
@@ -517,8 +283,78 @@ export function HistoricalCalendarPrices() {
|
|||||||
<Typography>Loading Chart...</Typography>
|
<Typography>Loading Chart...</Typography>
|
||||||
)}
|
)}
|
||||||
</Paper>
|
</Paper>
|
||||||
</Grid>
|
</Grid2>
|
||||||
</Grid>
|
<Grid2 size={{ xs: 12 }}>
|
||||||
|
<Paper elevation={3} sx={{ p: 3, minHeight: "28em", height: "100%" }}>
|
||||||
|
{underlying.value !== null &&
|
||||||
|
stockPriceChartData.value.length > 0 ? (
|
||||||
|
<Scatter
|
||||||
|
data={{
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: "Stock Open Price",
|
||||||
|
data: stockPriceChartData.value,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}}
|
||||||
|
options={{
|
||||||
|
showLine: true,
|
||||||
|
normalized: true,
|
||||||
|
scales: {
|
||||||
|
x: {
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: "Time",
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
callback: (value, index, ticks) =>
|
||||||
|
new Date((value as number) * 1000)
|
||||||
|
.toISOString()
|
||||||
|
.substring(0, 10),
|
||||||
|
},
|
||||||
|
min: new Date(lookbackPeriodStart.value).getTime() / 1000,
|
||||||
|
max: new Date(lookbackPeriodEnd.value).getTime() / 1000,
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
beginAtZero: false,
|
||||||
|
ticks: {
|
||||||
|
callback: (value, index, ticks) =>
|
||||||
|
`$${value.toString()}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
elements: {
|
||||||
|
point: {
|
||||||
|
radius: 2,
|
||||||
|
borderWidth: 0,
|
||||||
|
},
|
||||||
|
line: {
|
||||||
|
borderWidth: 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
tooltip: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
display: false,
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: "Stock Price",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
animation: false,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
events: [],
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Typography>Loading Chart...</Typography>
|
||||||
|
)}
|
||||||
|
</Paper>
|
||||||
|
</Grid2>
|
||||||
|
</Grid2>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import TextField from "@mui/material/TextField";
|
||||||
|
import { EditableValue } from "./EditableValue";
|
||||||
|
import { exitDTE } from "./state";
|
||||||
|
import { refreshcalendarExitPriceChartData } from "./actions";
|
||||||
|
import Slider from "@mui/material/Slider";
|
||||||
|
|
||||||
|
const handleExitDTEChange = (e) => {
|
||||||
|
if (exitDTE.value !== Number.parseInt(e.target.value)) {
|
||||||
|
exitDTE.value = Number.parseInt(e.target.value);
|
||||||
|
refreshcalendarExitPriceChartData();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export function EditableExitDTE() {
|
||||||
|
return (
|
||||||
|
<Slider
|
||||||
|
value={exitDTE.value}
|
||||||
|
onChange={handleExitDTEChange}
|
||||||
|
min={0}
|
||||||
|
max={5}
|
||||||
|
step={1}
|
||||||
|
valueLabelDisplay="on"
|
||||||
|
/>
|
||||||
|
// <EditableValue text={exitDTE.value}>
|
||||||
|
// <ExitToFrontExpirationChooser />
|
||||||
|
// </EditableValue>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import TextField from "@mui/material/TextField";
|
||||||
|
import {
|
||||||
|
refreshcalendarExitPriceChartData,
|
||||||
|
refreshSimilarCalendarPriceChartData,
|
||||||
|
refreshStockPriceChartData,
|
||||||
|
} from "./actions";
|
||||||
|
import { lookbackPeriodEnd, lookbackPeriodStart } from "./state";
|
||||||
|
import Slider from "@mui/material/Slider";
|
||||||
|
|
||||||
|
const handleLookbackPeriodChange = (
|
||||||
|
e,
|
||||||
|
[newLookbackPeriodStart, newLookbackPeriodEnd]: [number, number]
|
||||||
|
) => {
|
||||||
|
const [lookbackPeriodStartUnixTime, lookbackPeriodEndUnixTime] = [
|
||||||
|
new Date(lookbackPeriodStart.value).getTime(),
|
||||||
|
new Date(lookbackPeriodEnd.value).getTime(),
|
||||||
|
];
|
||||||
|
if (lookbackPeriodStartUnixTime !== newLookbackPeriodStart) {
|
||||||
|
lookbackPeriodStart.value = new Date(newLookbackPeriodStart)
|
||||||
|
.toISOString()
|
||||||
|
.substring(0, 10);
|
||||||
|
refreshStockPriceChartData();
|
||||||
|
refreshSimilarCalendarPriceChartData();
|
||||||
|
refreshcalendarExitPriceChartData();
|
||||||
|
}
|
||||||
|
if (lookbackPeriodEndUnixTime !== newLookbackPeriodEnd) {
|
||||||
|
lookbackPeriodEnd.value = new Date(newLookbackPeriodEnd)
|
||||||
|
.toISOString()
|
||||||
|
.substring(0, 10);
|
||||||
|
refreshStockPriceChartData();
|
||||||
|
refreshSimilarCalendarPriceChartData();
|
||||||
|
refreshcalendarExitPriceChartData();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const earliestDate = new Date("2022-03-07");
|
||||||
|
const DAY = 1000 * 60 * 60 * 24;
|
||||||
|
function addDays(date, days) {
|
||||||
|
const result = new Date(date);
|
||||||
|
result.setDate(result.getDate() + days);
|
||||||
|
return result.toISOString().substring(0, 10);
|
||||||
|
}
|
||||||
|
function daysBetween(date1, date2) {
|
||||||
|
return Math.round(Math.abs((date2.getTime() - date1.getTime()) / DAY));
|
||||||
|
}
|
||||||
|
export function EditableLookbackPeriod() {
|
||||||
|
return (
|
||||||
|
<Slider
|
||||||
|
value={[
|
||||||
|
new Date(lookbackPeriodStart.value).getTime(),
|
||||||
|
new Date(lookbackPeriodEnd.value).getTime(),
|
||||||
|
]}
|
||||||
|
onChange={handleLookbackPeriodChange}
|
||||||
|
valueLabelFormat={(unixTimeMs) =>
|
||||||
|
new Date(unixTimeMs).toISOString().substring(0, 10)
|
||||||
|
}
|
||||||
|
getAriaValueText={(unixTimeMs) =>
|
||||||
|
new Date(unixTimeMs).toISOString().substring(0, 10)
|
||||||
|
}
|
||||||
|
min={earliestDate.getTime()}
|
||||||
|
max={earliestDate.getTime() + 250 * DAY}
|
||||||
|
step={DAY}
|
||||||
|
valueLabelDisplay="on"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import TextField from "@mui/material/TextField";
|
||||||
|
import {
|
||||||
|
refreshcalendarExitPriceChartData,
|
||||||
|
refreshSimilarCalendarPriceChartData,
|
||||||
|
refreshStockPriceChartData,
|
||||||
|
} from "./actions";
|
||||||
|
import { lookbackPeriodEnd } from "./state";
|
||||||
|
import { EditableValue } from "./EditableValue";
|
||||||
|
|
||||||
|
const handleLookbackPeriodEndChange = (e) => {
|
||||||
|
if (lookbackPeriodEnd.value !== e.target.value) {
|
||||||
|
lookbackPeriodEnd.value = e.target.value;
|
||||||
|
refreshStockPriceChartData();
|
||||||
|
refreshSimilarCalendarPriceChartData();
|
||||||
|
refreshcalendarExitPriceChartData();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function LookbackPeriodEndChooser() {
|
||||||
|
return (
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
label="Lookback Period End"
|
||||||
|
type="date"
|
||||||
|
value={lookbackPeriodEnd.value}
|
||||||
|
onChange={handleLookbackPeriodEndChange}
|
||||||
|
InputLabelProps={{ shrink: true }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function EditableLookbackPeriodEnd() {
|
||||||
|
return (
|
||||||
|
<EditableValue text={lookbackPeriodEnd.value}>
|
||||||
|
<LookbackPeriodEndChooser />
|
||||||
|
</EditableValue>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import TextField from "@mui/material/TextField";
|
||||||
|
import {
|
||||||
|
refreshcalendarExitPriceChartData,
|
||||||
|
refreshSimilarCalendarPriceChartData,
|
||||||
|
refreshStockPriceChartData,
|
||||||
|
} from "./actions";
|
||||||
|
import { lookbackPeriodStart } from "./state";
|
||||||
|
import { EditableValue } from "./EditableValue";
|
||||||
|
|
||||||
|
const handleLookbackPeriodStartChange = (e) => {
|
||||||
|
if (lookbackPeriodStart.value !== e.target.value) {
|
||||||
|
lookbackPeriodStart.value = e.target.value;
|
||||||
|
refreshStockPriceChartData();
|
||||||
|
refreshSimilarCalendarPriceChartData();
|
||||||
|
refreshcalendarExitPriceChartData();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function LookbackPeriodStartChooser() {
|
||||||
|
return (
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
label="Lookback Period Start"
|
||||||
|
type="date"
|
||||||
|
value={lookbackPeriodStart.value}
|
||||||
|
onChange={handleLookbackPeriodStartChange}
|
||||||
|
InputLabelProps={{ shrink: true }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function EditableLookbackPeriodStart() {
|
||||||
|
return (
|
||||||
|
<EditableValue text={lookbackPeriodStart.value}>
|
||||||
|
<LookbackPeriodStartChooser />
|
||||||
|
</EditableValue>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { refreshSimilarCalendarPriceChartData } from "./actions";
|
||||||
|
import { openDTE } from "./state";
|
||||||
|
import Slider from "@mui/material/Slider";
|
||||||
|
|
||||||
|
const handleOpenDTEChange = (e) => {
|
||||||
|
if (openDTE.value !== Number.parseInt(e.target.value)) {
|
||||||
|
openDTE.value = Number.parseInt(e.target.value);
|
||||||
|
refreshSimilarCalendarPriceChartData();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export function EditableOpenDTE() {
|
||||||
|
return (
|
||||||
|
<Slider
|
||||||
|
value={openDTE.value}
|
||||||
|
onChange={handleOpenDTEChange}
|
||||||
|
min={0}
|
||||||
|
max={5}
|
||||||
|
step={1}
|
||||||
|
valueLabelDisplay="on"
|
||||||
|
/>
|
||||||
|
// <EditableValue text={openDTE.value}>
|
||||||
|
// <DaysToFrontExpirationChooser />
|
||||||
|
// </EditableValue>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import TextField from "@mui/material/TextField";
|
||||||
|
import {
|
||||||
|
refreshcalendarExitPriceChartData,
|
||||||
|
refreshSimilarCalendarPriceChartData,
|
||||||
|
} from "./actions";
|
||||||
|
import { span } from "./state";
|
||||||
|
import { EditableValue } from "./EditableValue";
|
||||||
|
import Slider from "@mui/material/Slider";
|
||||||
|
|
||||||
|
const handleSpanChange = (e) => {
|
||||||
|
if (span.value !== Number.parseInt(e.target.value)) {
|
||||||
|
span.value = Number.parseInt(e.target.value);
|
||||||
|
refreshSimilarCalendarPriceChartData();
|
||||||
|
refreshcalendarExitPriceChartData();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function DaysBetweenFrontAndBackExpirationChooser() {
|
||||||
|
return (
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
label="Front-to-Back-Month Days to Expiration Difference"
|
||||||
|
type="number"
|
||||||
|
value={span.value}
|
||||||
|
onChange={handleSpanChange}
|
||||||
|
InputProps={{ endAdornment: "Days Difference" }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function EditableSpan() {
|
||||||
|
return (
|
||||||
|
<Slider
|
||||||
|
value={span.value}
|
||||||
|
onChange={handleSpanChange}
|
||||||
|
min={3}
|
||||||
|
max={45}
|
||||||
|
step={1}
|
||||||
|
valueLabelDisplay="on"
|
||||||
|
/>
|
||||||
|
// <EditableValue text={span.value}>
|
||||||
|
// <DaysBetweenFrontAndBackExpirationChooser />
|
||||||
|
// </EditableValue>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import { EditableValue } from "./EditableValue";
|
||||||
|
import { moniness, moninessRadius } from "./state";
|
||||||
|
import Slider from "@mui/material/Slider";
|
||||||
|
import { refreshSimilarCalendarPriceChartData } from "./actions";
|
||||||
|
|
||||||
|
function MoninessChooser() {
|
||||||
|
return (
|
||||||
|
<Slider
|
||||||
|
fullWidth
|
||||||
|
label="Strike % From Underlying Price"
|
||||||
|
value={moniness.value}
|
||||||
|
valueLabelDisplay="on"
|
||||||
|
min={0}
|
||||||
|
max={10}
|
||||||
|
step={1}
|
||||||
|
onChange={(e, value) => {
|
||||||
|
moniness.value = value as number;
|
||||||
|
}}
|
||||||
|
onChangeCommitted={(e, value) => {
|
||||||
|
refreshSimilarCalendarPriceChartData();
|
||||||
|
}}
|
||||||
|
InputProps={{ endAdornment: "%" }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MoninessRadiusChooser() {
|
||||||
|
return (
|
||||||
|
<Slider
|
||||||
|
fullWidth
|
||||||
|
label="Strike % Radius"
|
||||||
|
value={moninessRadius.value}
|
||||||
|
valueLabelDisplay="on"
|
||||||
|
min={0}
|
||||||
|
max={10}
|
||||||
|
step={1}
|
||||||
|
onChange={(e, value) => {
|
||||||
|
moninessRadius.value = value as number;
|
||||||
|
}}
|
||||||
|
onChangeCommitted={(e, value) => {
|
||||||
|
refreshSimilarCalendarPriceChartData();
|
||||||
|
}}
|
||||||
|
InputProps={{ endAdornment: "%" }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This is its own component so that sliding the slider with the mouse is
|
||||||
|
* smoother. Preact detects reads from the "slider" signal values, and
|
||||||
|
* associates them with the component that read them and redraws that component.
|
||||||
|
* If this was not its own component, it would redraw the entire UI. It was very
|
||||||
|
* slow. */
|
||||||
|
export function EditableStrike() {
|
||||||
|
return (
|
||||||
|
<EditableValue
|
||||||
|
text={`${moniness.value.toFixed(1)}±${moninessRadius.value.toFixed(2)}`}
|
||||||
|
>
|
||||||
|
<Box sx={{ minWidth: "20em" }}>
|
||||||
|
<MoninessChooser />
|
||||||
|
<MoninessRadiusChooser />
|
||||||
|
</Box>
|
||||||
|
</EditableValue>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import Select from "@mui/material/Select";
|
||||||
|
import { EditableValue } from "./EditableValue";
|
||||||
|
import { availableUnderlyings, underlying } from "./state";
|
||||||
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
|
import {
|
||||||
|
refreshcalendarExitPriceChartData,
|
||||||
|
refreshSimilarCalendarPriceChartData,
|
||||||
|
refreshStockPriceChartData,
|
||||||
|
} from "./actions";
|
||||||
|
|
||||||
|
const handleUnderlyingChange = (e) => {
|
||||||
|
if (underlying.value !== e.target.value) {
|
||||||
|
underlying.value = e.target.value;
|
||||||
|
refreshStockPriceChartData();
|
||||||
|
refreshSimilarCalendarPriceChartData();
|
||||||
|
refreshcalendarExitPriceChartData();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function UnderlyingChooser() {
|
||||||
|
return (
|
||||||
|
<Select
|
||||||
|
value={underlying.value || ""}
|
||||||
|
onChange={handleUnderlyingChange}
|
||||||
|
label="Available Underlyings"
|
||||||
|
>
|
||||||
|
{availableUnderlyings.value.map((underlying) => (
|
||||||
|
<MenuItem key={underlying} value={underlying}>
|
||||||
|
{underlying}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function EditableUnderlying() {
|
||||||
|
return (
|
||||||
|
<EditableValue text={underlying.value}>
|
||||||
|
<UnderlyingChooser />
|
||||||
|
</EditableValue>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import Button from "@mui/material/Button";
|
||||||
|
import { isPopperOpen, popperAnchorEl, popperContent } from "./state";
|
||||||
|
|
||||||
|
export function EditableValue({ text, children }) {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="text"
|
||||||
|
size="large"
|
||||||
|
sx={{
|
||||||
|
textDecoration: "underline",
|
||||||
|
textUnderlineOffset: "3px",
|
||||||
|
fontSize: "1.0em",
|
||||||
|
}}
|
||||||
|
onClick={(e) => {
|
||||||
|
// stop propagation so it's not caught by the ClickAwayListener:
|
||||||
|
e.stopPropagation();
|
||||||
|
if (isPopperOpen.value === false) {
|
||||||
|
isPopperOpen.value = true;
|
||||||
|
popperAnchorEl.value = e.currentTarget;
|
||||||
|
popperContent.value = children;
|
||||||
|
} else {
|
||||||
|
isPopperOpen.value = false;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{text}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
import { trpc } from "../../trpc";
|
||||||
|
import {
|
||||||
|
calendarExitPriceChartData,
|
||||||
|
span,
|
||||||
|
openDTE,
|
||||||
|
exitDTE,
|
||||||
|
lookbackPeriodEnd,
|
||||||
|
lookbackPeriodStart,
|
||||||
|
similarCalendarPriceChartData,
|
||||||
|
stockPriceChartData,
|
||||||
|
moniness,
|
||||||
|
moninessRadius,
|
||||||
|
underlying,
|
||||||
|
} from "./state";
|
||||||
|
|
||||||
|
function debounce(func, wait) {
|
||||||
|
let timeout;
|
||||||
|
return function () {
|
||||||
|
const context = this;
|
||||||
|
const args = arguments;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => func.apply(context, args), wait);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function throttle(func, limit) {
|
||||||
|
let inThrottle;
|
||||||
|
return function () {
|
||||||
|
const context = this;
|
||||||
|
const args = arguments;
|
||||||
|
if (!inThrottle) {
|
||||||
|
func.apply(context, args);
|
||||||
|
inThrottle = true;
|
||||||
|
setTimeout(() => (inThrottle = false), limit);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const refreshStockPriceChartData = throttle(() => {
|
||||||
|
stockPriceChartData.value = [];
|
||||||
|
trpc.StockPriceChart.getChartData
|
||||||
|
.query({
|
||||||
|
underlying: underlying.value,
|
||||||
|
lookbackPeriodStart: lookbackPeriodStart.value,
|
||||||
|
lookbackPeriodEnd: lookbackPeriodEnd.value,
|
||||||
|
})
|
||||||
|
.then((getChartDataResponse) => {
|
||||||
|
stockPriceChartData.value = getChartDataResponse;
|
||||||
|
});
|
||||||
|
}, 400);
|
||||||
|
export const refreshSimilarCalendarPriceChartData = throttle(() => {
|
||||||
|
similarCalendarPriceChartData.value = [];
|
||||||
|
trpc.SimilarCalendarPriceChart.getChartData
|
||||||
|
.query({
|
||||||
|
underlying: underlying.value,
|
||||||
|
daysToFrontExpiration: openDTE.value,
|
||||||
|
daysBetweenFrontAndBackExpiration: span.value,
|
||||||
|
strikePercentageFromUnderlyingPriceRangeMin:
|
||||||
|
(moniness.value - moninessRadius.value) / 100,
|
||||||
|
strikePercentageFromUnderlyingPriceRangeMax:
|
||||||
|
(moniness.value + moninessRadius.value) / 100,
|
||||||
|
lookbackPeriodStart: lookbackPeriodStart.value,
|
||||||
|
lookbackPeriodEnd: lookbackPeriodEnd.value,
|
||||||
|
})
|
||||||
|
.then((getChartDataResponse) => {
|
||||||
|
similarCalendarPriceChartData.value = getChartDataResponse;
|
||||||
|
});
|
||||||
|
}, 400);
|
||||||
|
export const refreshcalendarExitPriceChartData = throttle(() => {
|
||||||
|
calendarExitPriceChartData.value = [];
|
||||||
|
trpc.CalendarExitPriceChart.getChartData
|
||||||
|
.query({
|
||||||
|
underlying: underlying.value,
|
||||||
|
daysToFrontExpiration: exitDTE.value,
|
||||||
|
daysBetweenFrontAndBackExpiration: span.value,
|
||||||
|
lookbackPeriodStart: lookbackPeriodStart.value,
|
||||||
|
lookbackPeriodEnd: lookbackPeriodEnd.value,
|
||||||
|
})
|
||||||
|
.then((getChartDataResponse) => {
|
||||||
|
calendarExitPriceChartData.value = getChartDataResponse;
|
||||||
|
});
|
||||||
|
}, 400);
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { computed, signal } from "@preact/signals";
|
||||||
|
|
||||||
|
export const isPopperOpen = signal(false);
|
||||||
|
export const popperAnchorEl = signal(null);
|
||||||
|
export const popperContent = signal(null);
|
||||||
|
|
||||||
|
export const availableUnderlyings = signal([]);
|
||||||
|
export const underlying = signal(null);
|
||||||
|
|
||||||
|
export const openDTE = signal(14);
|
||||||
|
|
||||||
|
export const span = signal(14);
|
||||||
|
|
||||||
|
export const moniness = signal(1);
|
||||||
|
export const moninessRadius = signal(1);
|
||||||
|
|
||||||
|
export const exitDTE = signal(2);
|
||||||
|
|
||||||
|
export const stockPriceChartData = signal<Array<[number, number]>>([]);
|
||||||
|
|
||||||
|
export const similarCalendarPriceChartData = signal([]);
|
||||||
|
|
||||||
|
export const calendarExitPriceChartData = signal([]);
|
||||||
|
|
||||||
|
export const lookbackPeriodStart = signal("2022-03-01");
|
||||||
|
export const lookbackPeriodEnd = signal("2022-04-01");
|
||||||
|
|
||||||
|
export const maxChartPrice = computed(() =>
|
||||||
|
Math.max(
|
||||||
|
Math.max.apply(
|
||||||
|
null,
|
||||||
|
similarCalendarPriceChartData.value.map((d) => d.y).slice(0, -2)
|
||||||
|
),
|
||||||
|
Math.max.apply(
|
||||||
|
null,
|
||||||
|
calendarExitPriceChartData.value.map((d) => d.y).slice(0, -2)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const maxN = computed(() =>
|
||||||
|
Math.max.apply(
|
||||||
|
null,
|
||||||
|
calendarExitPriceChartData.value.map((d) => d.n)
|
||||||
|
)
|
||||||
|
);
|
||||||
+2
-1
@@ -26,4 +26,5 @@ dist-ssr
|
|||||||
|
|
||||||
.env
|
.env
|
||||||
*.db
|
*.db
|
||||||
*.db-lck
|
*.db-lck
|
||||||
|
Calendar tRPC
|
||||||
+17
-12
@@ -2,22 +2,27 @@
|
|||||||
FROM node:20-slim AS base
|
FROM node:20-slim AS base
|
||||||
ENV PNPM_HOME="/pnpm"
|
ENV PNPM_HOME="/pnpm"
|
||||||
ENV PATH="$PNPM_HOME:$PATH"
|
ENV PATH="$PNPM_HOME:$PATH"
|
||||||
RUN corepack enable
|
RUN npm install -g corepack@latest && corepack enable
|
||||||
COPY package.json pnpm-lock.yaml /app/
|
COPY package.json pnpm-lock.yaml /app/
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
FROM base AS prod-deps
|
|
||||||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
|
|
||||||
|
|
||||||
# install dev dependencies which are needed for building, such as typescript:
|
|
||||||
FROM base AS build
|
|
||||||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
||||||
COPY tsconfig.json /app/
|
COPY tsconfig.json /app/
|
||||||
COPY src /app/src
|
COPY src /app/src
|
||||||
RUN pnpm run build
|
CMD [ "pnpm", "tsx", "src/index.ts" ]
|
||||||
|
|
||||||
FROM base
|
# FROM base AS prod-deps
|
||||||
COPY --from=prod-deps /app/node_modules /app/node_modules
|
# RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
|
||||||
COPY --from=build /app/dist /app/dist
|
|
||||||
WORKDIR /app/dist
|
# # install dev dependencies which are needed for building, such as typescript:
|
||||||
CMD [ "node", "index.js" ]
|
# FROM base AS build
|
||||||
|
# RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
||||||
|
# COPY tsconfig.json /app/
|
||||||
|
# COPY src /app/src
|
||||||
|
# RUN pnpm run build
|
||||||
|
|
||||||
|
# FROM base
|
||||||
|
# COPY --from=prod-deps /app/node_modules /app/node_modules
|
||||||
|
# COPY --from=build /app/dist /app/dist
|
||||||
|
# WORKDIR /app/dist
|
||||||
|
# CMD [ "node", "index.js" ]
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
- Ingest stock/underlying aggregates from flatfiles
|
||||||
|
- Create backtesting function to step through each minute of every day.
|
||||||
+10
-3
@@ -2,32 +2,39 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "esbuild src/*.ts src/**/*.ts --platform=node --outdir=dist --format=esm",
|
"build": "esbuild src/*.ts src/*.tsx src/**/*.ts src/**/**/*.ts --platform=node --outdir=dist --format=esm",
|
||||||
"dev:node": "node --watch dist/index.js",
|
"dev:node": "node --watch dist/index.js",
|
||||||
"dev:esbuild": "pnpm run build --watch",
|
"dev:esbuild": "pnpm run build --watch",
|
||||||
"dev": "run-p dev:*"
|
"dev": "run-p dev:*",
|
||||||
|
"cli": "tsx src/cli.tsx"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@clickhouse/client": "^0.2.7",
|
"@clickhouse/client": "^1.4.1",
|
||||||
"@humanwhocodes/env": "^3.0.5",
|
"@humanwhocodes/env": "^3.0.5",
|
||||||
"@sinclair/typebox": "^0.32.5",
|
"@sinclair/typebox": "^0.32.5",
|
||||||
"@trpc/server": "^10.45.0",
|
"@trpc/server": "^10.45.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
|
"date-fns": "^3.6.0",
|
||||||
"execa": "^9.3.0",
|
"execa": "^9.3.0",
|
||||||
|
"ink": "^4.1.0",
|
||||||
|
"ink-text-input": "^5.0.1",
|
||||||
"lmdbx": "^0.5.0",
|
"lmdbx": "^0.5.0",
|
||||||
"p-all": "^5.0.0",
|
"p-all": "^5.0.0",
|
||||||
"p-queue": "^8.0.1",
|
"p-queue": "^8.0.1",
|
||||||
"p-retry": "^6.2.0",
|
"p-retry": "^6.2.0",
|
||||||
"p-series": "^3.0.0",
|
"p-series": "^3.0.0",
|
||||||
"p-throttle": "^6.1.0",
|
"p-throttle": "^6.1.0",
|
||||||
|
"react": "^18.2.0",
|
||||||
"sqlite": "^5.1.1",
|
"sqlite": "^5.1.1",
|
||||||
"sqlite3": "^5.1.7"
|
"sqlite3": "^5.1.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/cors": "^2.8.17",
|
"@types/cors": "^2.8.17",
|
||||||
"@types/node": "^20.10.7",
|
"@types/node": "^20.10.7",
|
||||||
|
"@types/react": "^18.0.0",
|
||||||
"esbuild": "^0.19.11",
|
"esbuild": "^0.19.11",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
|
"tsx": "^4.17.0",
|
||||||
"typescript": "^5.3.3"
|
"typescript": "^5.3.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+697
-12
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,191 @@
|
|||||||
|
import type { CalendarDatabase, CalendarKey } from "./interfaces.js";
|
||||||
|
import type { Aggregate } from "../interfaces.js";
|
||||||
|
import { query } from "../../lib/clickhouse.js";
|
||||||
|
|
||||||
|
function makeCalendarDatabase(): CalendarDatabase {
|
||||||
|
const calendarDatabase: Omit<CalendarDatabase, "getCalendars"> = {
|
||||||
|
getKeys: async ({ key: { symbol }, date }) => {
|
||||||
|
const calendarsForSymbolOnDate = await query<
|
||||||
|
Omit<CalendarKey, "symbol">
|
||||||
|
>(`
|
||||||
|
WITH today_option_contracts AS (
|
||||||
|
SELECT expirationDate, strike, type
|
||||||
|
FROM option_contract_existences
|
||||||
|
WHERE symbol = '${symbol}'
|
||||||
|
AND asOfDate = '${date}'
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
front_option_contract.type as type,
|
||||||
|
front_option_contract.strike as strike,
|
||||||
|
front_option_contract.expirationDate as frontExpirationDate,
|
||||||
|
back_option_contract.expirationDate as backExpirationDate
|
||||||
|
FROM today_option_contracts AS front_option_contract
|
||||||
|
ASOF INNER JOIN today_option_contracts AS back_option_contract
|
||||||
|
ON front_option_contract.type = back_option_contract.type
|
||||||
|
AND front_option_contract.strike = back_option_contract.strike
|
||||||
|
AND front_option_contract.expirationDate < back_option_contract.expirationDate
|
||||||
|
`);
|
||||||
|
|
||||||
|
return calendarsForSymbolOnDate.map((calendarWithoutSymbol) => ({
|
||||||
|
...calendarWithoutSymbol,
|
||||||
|
symbol,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
getAggregate: async ({
|
||||||
|
key: { symbol, frontExpirationDate, backExpirationDate, strike, type },
|
||||||
|
tsStart,
|
||||||
|
}) => {
|
||||||
|
const tsStartString = new Date(tsStart).toISOString();
|
||||||
|
return (
|
||||||
|
await query<Omit<Aggregate<CalendarKey>, "key">>(`
|
||||||
|
WITH front_option_contract_candlestick AS (
|
||||||
|
SELECT
|
||||||
|
tsStart,
|
||||||
|
open,
|
||||||
|
close,
|
||||||
|
high,
|
||||||
|
low
|
||||||
|
FROM option_contract_aggregates
|
||||||
|
WHERE symbol = '${symbol}'
|
||||||
|
AND type = '${type}'
|
||||||
|
AND strike = '${strike}'
|
||||||
|
AND expirationDate = '${frontExpirationDate}'
|
||||||
|
AND tsStart = '${tsStartString}'
|
||||||
|
),
|
||||||
|
back_option_contract_candlestick AS (
|
||||||
|
SELECT
|
||||||
|
tsStart,
|
||||||
|
open,
|
||||||
|
close,
|
||||||
|
high,
|
||||||
|
low
|
||||||
|
FROM option_contract_aggregates
|
||||||
|
WHERE symbol = '${symbol}'
|
||||||
|
AND type = '${type}'
|
||||||
|
AND strike = '${strike}'
|
||||||
|
AND expirationDate = '${backExpirationDate}'
|
||||||
|
AND tsStart = '${tsStartString}'
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
toUnixTimestamp(front_option_contract_candlestick.tsStart) as tsStart,
|
||||||
|
back_option_contract_candlestick.open - front_option_contract_candlestick.open as open,
|
||||||
|
back_option_contract_candlestick.close - front_option_contract_candlestick.close as close
|
||||||
|
FROM front_option_contract_candlestick
|
||||||
|
INNER JOIN back_option_contract_candlestick
|
||||||
|
ON front_option_contract_candlestick.tsStart = back_option_contract_candlestick.tsStart
|
||||||
|
ORDER BY front_option_contract_candlestick.tsStart ASC
|
||||||
|
`)
|
||||||
|
).map((aggregate) => ({
|
||||||
|
...aggregate,
|
||||||
|
tsStart: aggregate.tsStart * 1000, // unfortunately, `toUnixTimestamp` only returns second-precision
|
||||||
|
}))[0];
|
||||||
|
},
|
||||||
|
getAggregates: async ({
|
||||||
|
key: { symbol, frontExpirationDate, backExpirationDate, strike, type },
|
||||||
|
date,
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
await query<Omit<Aggregate<CalendarKey>, "key">>(`
|
||||||
|
WITH front_option_contract_candlestick AS (
|
||||||
|
SELECT
|
||||||
|
tsStart,
|
||||||
|
open,
|
||||||
|
close,
|
||||||
|
high,
|
||||||
|
low
|
||||||
|
FROM option_contract_aggregates
|
||||||
|
WHERE symbol = '${symbol}'
|
||||||
|
AND type = '${type}'
|
||||||
|
AND strike = '${strike}'
|
||||||
|
AND expirationDate = '${frontExpirationDate}'
|
||||||
|
AND toDate(tsStart) = '${date}'
|
||||||
|
),
|
||||||
|
back_option_contract_candlestick AS (
|
||||||
|
SELECT
|
||||||
|
tsStart,
|
||||||
|
open,
|
||||||
|
close,
|
||||||
|
high,
|
||||||
|
low
|
||||||
|
FROM option_contract_aggregates
|
||||||
|
WHERE symbol = '${symbol}'
|
||||||
|
AND type = '${type}'
|
||||||
|
AND strike = '${strike}'
|
||||||
|
AND expirationDate = '${backExpirationDate}'
|
||||||
|
AND toDate(tsStart) = '${date}'
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
toUnixTimestamp(front_option_contract_candlestick.tsStart) as tsStart,
|
||||||
|
back_option_contract_candlestick.open - front_option_contract_candlestick.open as open,
|
||||||
|
back_option_contract_candlestick.close - front_option_contract_candlestick.close as close
|
||||||
|
FROM front_option_contract_candlestick
|
||||||
|
INNER JOIN back_option_contract_candlestick
|
||||||
|
ON front_option_contract_candlestick.tsStart = back_option_contract_candlestick.tsStart
|
||||||
|
ORDER BY front_option_contract_candlestick.tsStart ASC
|
||||||
|
`)
|
||||||
|
).map((aggregate) => ({
|
||||||
|
...aggregate,
|
||||||
|
tsStart: aggregate.tsStart * 1000, // unfortunately, `toUnixTimestamp` only returns second-precision
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
insertAggregates: async (aggregates) => {
|
||||||
|
// no-op: we insert individual option contracts, not calendars
|
||||||
|
},
|
||||||
|
getClosingPrice: async ({
|
||||||
|
key: { symbol, strike, type, frontExpirationDate, backExpirationDate },
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
await query<{ calendarClosingPrice: number }>(`
|
||||||
|
WITH front_option_contract_candlestick AS (
|
||||||
|
SELECT
|
||||||
|
tsStart,
|
||||||
|
open,
|
||||||
|
close,
|
||||||
|
high,
|
||||||
|
low
|
||||||
|
FROM option_contract_aggregates
|
||||||
|
WHERE symbol = '${symbol}'
|
||||||
|
AND type = '${type}'
|
||||||
|
AND strike = '${strike}'
|
||||||
|
AND expirationDate = '${frontExpirationDate}'
|
||||||
|
AND toDate(tsStart) = '${frontExpirationDate}'
|
||||||
|
),
|
||||||
|
back_option_contract_candlestick AS (
|
||||||
|
SELECT
|
||||||
|
tsStart,
|
||||||
|
open,
|
||||||
|
close,
|
||||||
|
high,
|
||||||
|
low
|
||||||
|
FROM option_contract_aggregates
|
||||||
|
WHERE symbol = '${symbol}'
|
||||||
|
AND type = '${type}'
|
||||||
|
AND strike = '${strike}'
|
||||||
|
AND expirationDate = '${backExpirationDate}'
|
||||||
|
AND toDate(tsStart) = '${frontExpirationDate}'
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
min(back_option_contract_candlestick.close - front_option_contract_candlestick.close) as calendarClosingPrice
|
||||||
|
FROM front_option_contract_candlestick
|
||||||
|
INNER JOIN back_option_contract_candlestick
|
||||||
|
ON front_option_contract_candlestick.tsStart = back_option_contract_candlestick.tsStart
|
||||||
|
`)
|
||||||
|
)[0]?.calendarClosingPrice;
|
||||||
|
},
|
||||||
|
getTargetPriceByProbability: async ({
|
||||||
|
symbol,
|
||||||
|
calendarSpan,
|
||||||
|
strikePercentageFromTheMoney,
|
||||||
|
historicalProbabilityOfSuccess,
|
||||||
|
}) => {
|
||||||
|
return 0.24;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...calendarDatabase,
|
||||||
|
getCalendars: calendarDatabase.getKeys,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const database: CalendarDatabase = makeCalendarDatabase();
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import type { AggregateDatabase } from "../interfaces.js";
|
||||||
|
|
||||||
|
export type CalendarKey = {
|
||||||
|
symbol: string;
|
||||||
|
type: "call" | "put";
|
||||||
|
strike: number;
|
||||||
|
frontExpirationDate: string;
|
||||||
|
backExpirationDate: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CalendarDatabase = AggregateDatabase<CalendarKey> & {
|
||||||
|
getCalendars: AggregateDatabase<CalendarKey>["getKeys"];
|
||||||
|
getTargetPriceByProbability: ({
|
||||||
|
symbol,
|
||||||
|
calendarSpan,
|
||||||
|
strikePercentageFromTheMoney,
|
||||||
|
historicalProbabilityOfSuccess,
|
||||||
|
}: {
|
||||||
|
symbol: string;
|
||||||
|
calendarSpan: number;
|
||||||
|
strikePercentageFromTheMoney: number;
|
||||||
|
historicalProbabilityOfSuccess: number;
|
||||||
|
}) => Promise<number>;
|
||||||
|
};
|
||||||
@@ -0,0 +1,166 @@
|
|||||||
|
import type { CalendarDatabase } from "./interfaces.js";
|
||||||
|
import { open } from "lmdbx";
|
||||||
|
|
||||||
|
const calendarAggregatesDb = open({
|
||||||
|
path: "./calendar-aggregates.db",
|
||||||
|
compression: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const calendarExistenceDb = open({
|
||||||
|
path: "./calendar-existence.db",
|
||||||
|
compression: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** Largest possible key according to the `ordered-binary` (used by lmdbx) docs. */
|
||||||
|
const MAXIMUM_KEY = Buffer.from([0xff]);
|
||||||
|
|
||||||
|
function makeCalendarDatabase(): CalendarDatabase {
|
||||||
|
const calendarDatabase: Omit<CalendarDatabase, "getCalendars"> = {
|
||||||
|
getKeys: async ({ key: { symbol }, date }) => {
|
||||||
|
return calendarExistenceDb
|
||||||
|
.getRange({
|
||||||
|
start: [date, symbol],
|
||||||
|
end: [date, symbol, MAXIMUM_KEY],
|
||||||
|
})
|
||||||
|
.map(({ key }) => ({
|
||||||
|
symbol,
|
||||||
|
frontExpirationDate: key[2],
|
||||||
|
backExpirationDate: key[3],
|
||||||
|
strike: key[4],
|
||||||
|
type: key[5],
|
||||||
|
})).asArray;
|
||||||
|
},
|
||||||
|
getAggregates: async ({
|
||||||
|
key: { symbol, frontExpirationDate, backExpirationDate, strike, type },
|
||||||
|
date,
|
||||||
|
}) => {
|
||||||
|
const startOfDayUnix = new Date(`${date}T00:00:00Z`).valueOf();
|
||||||
|
const endOfDayUnix = startOfDayUnix + 3600 * 24 * 1000;
|
||||||
|
return calendarAggregatesDb
|
||||||
|
.getRange({
|
||||||
|
start: [
|
||||||
|
symbol,
|
||||||
|
frontExpirationDate,
|
||||||
|
backExpirationDate,
|
||||||
|
strike,
|
||||||
|
type,
|
||||||
|
startOfDayUnix,
|
||||||
|
],
|
||||||
|
end: [
|
||||||
|
symbol,
|
||||||
|
frontExpirationDate,
|
||||||
|
backExpirationDate,
|
||||||
|
strike,
|
||||||
|
type,
|
||||||
|
endOfDayUnix,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
.map(({ value }) => ({
|
||||||
|
tsStart: value.tsStart,
|
||||||
|
open: value.open,
|
||||||
|
close: value.close,
|
||||||
|
high: value.high,
|
||||||
|
low: value.low,
|
||||||
|
})).asArray;
|
||||||
|
},
|
||||||
|
getAggregate: async ({
|
||||||
|
key: { symbol, frontExpirationDate, backExpirationDate, strike, type },
|
||||||
|
tsStart,
|
||||||
|
}) => {
|
||||||
|
return await calendarAggregatesDb.get([
|
||||||
|
symbol,
|
||||||
|
frontExpirationDate,
|
||||||
|
backExpirationDate,
|
||||||
|
strike,
|
||||||
|
type,
|
||||||
|
tsStart,
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
insertAggregates: async (aggregates) => {
|
||||||
|
await calendarExistenceDb.batch(() => {
|
||||||
|
for (const aggregate of aggregates) {
|
||||||
|
calendarExistenceDb.put(
|
||||||
|
[
|
||||||
|
new Date(aggregate.tsStart).toISOString().substring(0, 10),
|
||||||
|
aggregate.key.symbol,
|
||||||
|
aggregate.key.frontExpirationDate,
|
||||||
|
aggregate.key.backExpirationDate,
|
||||||
|
aggregate.key.strike,
|
||||||
|
aggregate.key.type,
|
||||||
|
],
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await calendarAggregatesDb.batch(() => {
|
||||||
|
for (const aggregate of aggregates) {
|
||||||
|
calendarAggregatesDb.put(
|
||||||
|
[
|
||||||
|
aggregate.key.symbol,
|
||||||
|
aggregate.key.frontExpirationDate,
|
||||||
|
aggregate.key.backExpirationDate,
|
||||||
|
aggregate.key.strike,
|
||||||
|
aggregate.key.type,
|
||||||
|
aggregate.tsStart,
|
||||||
|
],
|
||||||
|
{
|
||||||
|
open: aggregate.open,
|
||||||
|
close: aggregate.close,
|
||||||
|
high: aggregate.high,
|
||||||
|
low: aggregate.low,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getClosingPrice: async ({
|
||||||
|
key: { symbol, strike, type, frontExpirationDate, backExpirationDate },
|
||||||
|
}) => {
|
||||||
|
const startOfExpirationDateUnix = new Date(
|
||||||
|
`${frontExpirationDate}T23:59:59Z`
|
||||||
|
).valueOf();
|
||||||
|
const endOfExpirationDateUnix = new Date(
|
||||||
|
`${frontExpirationDate}T00:00:00Z`
|
||||||
|
).valueOf();
|
||||||
|
for (const { value } of calendarAggregatesDb.getRange({
|
||||||
|
start: [
|
||||||
|
symbol,
|
||||||
|
frontExpirationDate,
|
||||||
|
backExpirationDate,
|
||||||
|
strike,
|
||||||
|
type,
|
||||||
|
startOfExpirationDateUnix,
|
||||||
|
],
|
||||||
|
end: [
|
||||||
|
symbol,
|
||||||
|
frontExpirationDate,
|
||||||
|
backExpirationDate,
|
||||||
|
strike,
|
||||||
|
type,
|
||||||
|
endOfExpirationDateUnix,
|
||||||
|
],
|
||||||
|
reverse: true,
|
||||||
|
})) {
|
||||||
|
if (value.close > 0) {
|
||||||
|
return value.close;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
getTargetPriceByProbability: async ({
|
||||||
|
symbol,
|
||||||
|
calendarSpan,
|
||||||
|
strikePercentageFromTheMoney,
|
||||||
|
historicalProbabilityOfSuccess,
|
||||||
|
}) => {
|
||||||
|
return 0.24;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...calendarDatabase,
|
||||||
|
getCalendars: calendarDatabase.getKeys,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const database: CalendarDatabase = makeCalendarDatabase();
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
import { database as optionContractDatabase } from "../OptionContract/lmdbx.js";
|
||||||
|
import type { CalendarDatabase } from "./interfaces.js";
|
||||||
|
|
||||||
|
/** Largest possible key according to the `ordered-binary` (used by lmdbx) docs. */
|
||||||
|
const MAXIMUM_KEY = Buffer.from([0xff]);
|
||||||
|
|
||||||
|
function makeCalendarDatabase(): CalendarDatabase {
|
||||||
|
const getAggregatesSync = ({
|
||||||
|
key: { symbol, frontExpirationDate, backExpirationDate, strike, type },
|
||||||
|
date,
|
||||||
|
}) => {
|
||||||
|
const frontOptionContractAggregates =
|
||||||
|
optionContractDatabase.getAggregatesSync({
|
||||||
|
date,
|
||||||
|
key: { symbol, expirationDate: frontExpirationDate, strike, type },
|
||||||
|
});
|
||||||
|
const backOptionContractAggregates =
|
||||||
|
optionContractDatabase.getAggregatesSync({
|
||||||
|
date,
|
||||||
|
key: { symbol, expirationDate: backExpirationDate, strike, type },
|
||||||
|
});
|
||||||
|
const calendarAggregates = [];
|
||||||
|
let i = 0;
|
||||||
|
let j = 0;
|
||||||
|
while (
|
||||||
|
i < frontOptionContractAggregates.length &&
|
||||||
|
j < backOptionContractAggregates.length
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
frontOptionContractAggregates[i].tsStart ===
|
||||||
|
backOptionContractAggregates[j].tsStart
|
||||||
|
) {
|
||||||
|
calendarAggregates.push({
|
||||||
|
tsStart: frontOptionContractAggregates[i].tsStart,
|
||||||
|
open:
|
||||||
|
backOptionContractAggregates[j].open -
|
||||||
|
frontOptionContractAggregates[i].open,
|
||||||
|
close:
|
||||||
|
backOptionContractAggregates[j].close -
|
||||||
|
frontOptionContractAggregates[i].close,
|
||||||
|
// the high and low are not exactly correct since we don't know if each contract's high and low happened at the same moment as the other:
|
||||||
|
high:
|
||||||
|
backOptionContractAggregates[j].high -
|
||||||
|
frontOptionContractAggregates[i].high,
|
||||||
|
low:
|
||||||
|
backOptionContractAggregates[j].low -
|
||||||
|
frontOptionContractAggregates[i].low,
|
||||||
|
});
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
} else if (
|
||||||
|
frontOptionContractAggregates[i].tsStart >
|
||||||
|
backOptionContractAggregates[j].tsStart
|
||||||
|
) {
|
||||||
|
j++;
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return calendarAggregates;
|
||||||
|
};
|
||||||
|
const calendarDatabase: Omit<CalendarDatabase, "getCalendars"> = {
|
||||||
|
getKeys: async ({ key: { symbol }, date }) => {
|
||||||
|
const optionContracts = await optionContractDatabase.getOptionContracts({
|
||||||
|
date,
|
||||||
|
key: { symbol },
|
||||||
|
});
|
||||||
|
return optionContracts.flatMap(
|
||||||
|
(frontOptionContract, i, optionContracts) =>
|
||||||
|
optionContracts
|
||||||
|
.filter(
|
||||||
|
(potientialBackOptionContract) =>
|
||||||
|
frontOptionContract.strike ===
|
||||||
|
potientialBackOptionContract.strike &&
|
||||||
|
frontOptionContract.type ===
|
||||||
|
potientialBackOptionContract.type &&
|
||||||
|
frontOptionContract.expirationDate <
|
||||||
|
potientialBackOptionContract.expirationDate
|
||||||
|
)
|
||||||
|
.map((backOptionContract) => ({
|
||||||
|
symbol,
|
||||||
|
frontExpirationDate: frontOptionContract.expirationDate,
|
||||||
|
backExpirationDate: backOptionContract.expirationDate,
|
||||||
|
strike: frontOptionContract.strike,
|
||||||
|
type: frontOptionContract.type,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
},
|
||||||
|
getAggregates: async ({
|
||||||
|
key: { symbol, frontExpirationDate, backExpirationDate, strike, type },
|
||||||
|
date,
|
||||||
|
}) =>
|
||||||
|
getAggregatesSync({
|
||||||
|
key: { symbol, frontExpirationDate, backExpirationDate, strike, type },
|
||||||
|
date,
|
||||||
|
}),
|
||||||
|
getAggregatesSync,
|
||||||
|
insertAggregates: async (aggregates) => {
|
||||||
|
// right now, no-op
|
||||||
|
},
|
||||||
|
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}T19:30:00Z`
|
||||||
|
).getTime();
|
||||||
|
const endOfLastHourUnix = startOfLastHourUnix + 3600 * 1000;
|
||||||
|
const frontOptionContractAggregates = (
|
||||||
|
await optionContractDatabase.getAggregates({
|
||||||
|
date: frontExpirationDate,
|
||||||
|
key: { symbol, expirationDate: frontExpirationDate, strike, type },
|
||||||
|
})
|
||||||
|
).filter(
|
||||||
|
({ tsStart }) =>
|
||||||
|
tsStart >= startOfLastHourUnix && tsStart < endOfLastHourUnix
|
||||||
|
);
|
||||||
|
const backOptionContractAggregates = (
|
||||||
|
await optionContractDatabase.getAggregates({
|
||||||
|
date: frontExpirationDate,
|
||||||
|
key: { symbol, expirationDate: backExpirationDate, strike, type },
|
||||||
|
})
|
||||||
|
).filter(
|
||||||
|
({ tsStart }) =>
|
||||||
|
tsStart >= startOfLastHourUnix && tsStart < endOfLastHourUnix
|
||||||
|
);
|
||||||
|
let i = 0;
|
||||||
|
let j = 0;
|
||||||
|
let minPrice = 0;
|
||||||
|
while (
|
||||||
|
i < frontOptionContractAggregates.length &&
|
||||||
|
j < backOptionContractAggregates.length
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
frontOptionContractAggregates[i].tsStart ===
|
||||||
|
backOptionContractAggregates[j].tsStart
|
||||||
|
) {
|
||||||
|
const calendarClosePrice =
|
||||||
|
backOptionContractAggregates[j].close -
|
||||||
|
frontOptionContractAggregates[i].close;
|
||||||
|
if (calendarClosePrice < minPrice || minPrice === 0) {
|
||||||
|
minPrice = calendarClosePrice;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
} else if (
|
||||||
|
frontOptionContractAggregates[i].tsStart >
|
||||||
|
backOptionContractAggregates[j].tsStart
|
||||||
|
) {
|
||||||
|
j++;
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return minPrice;
|
||||||
|
},
|
||||||
|
getAggregate: async ({
|
||||||
|
key: { symbol, frontExpirationDate, backExpirationDate, strike, type },
|
||||||
|
tsStart,
|
||||||
|
}) => {
|
||||||
|
const [frontOptionContractAggregate, backOptionContractAggregate] =
|
||||||
|
await Promise.all([
|
||||||
|
optionContractDatabase.getAggregate({
|
||||||
|
key: { symbol, expirationDate: frontExpirationDate, strike, type },
|
||||||
|
tsStart,
|
||||||
|
}),
|
||||||
|
optionContractDatabase.getAggregate({
|
||||||
|
key: { symbol, expirationDate: backExpirationDate, strike, type },
|
||||||
|
tsStart,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
// only return the calendar aggregate if its constituent front and back option contract aggregates exist:
|
||||||
|
if (frontOptionContractAggregate && backOptionContractAggregate) {
|
||||||
|
return {
|
||||||
|
tsStart,
|
||||||
|
open:
|
||||||
|
backOptionContractAggregate.open -
|
||||||
|
frontOptionContractAggregate.open,
|
||||||
|
close:
|
||||||
|
backOptionContractAggregate.close -
|
||||||
|
frontOptionContractAggregate.close,
|
||||||
|
high:
|
||||||
|
backOptionContractAggregate.high -
|
||||||
|
frontOptionContractAggregate.high,
|
||||||
|
low:
|
||||||
|
backOptionContractAggregate.low - frontOptionContractAggregate.low,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
getTargetPriceByProbability: async ({
|
||||||
|
symbol,
|
||||||
|
calendarSpan,
|
||||||
|
strikePercentageFromTheMoney,
|
||||||
|
historicalProbabilityOfSuccess,
|
||||||
|
}) => {
|
||||||
|
return 0.24;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...calendarDatabase,
|
||||||
|
getCalendars: calendarDatabase.getKeys,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const database: CalendarDatabase = makeCalendarDatabase();
|
||||||
+30
-6
@@ -1,9 +1,9 @@
|
|||||||
import type {
|
import type {
|
||||||
OptionContractDatabase,
|
OptionContractDatabase,
|
||||||
OptionContractKey,
|
OptionContractKey,
|
||||||
} from "./optiondb.interfaces.js";
|
} from "./interfaces.js";
|
||||||
import type { Aggregate } from "./interfaces.js";
|
import type { Aggregate } from "../interfaces.js";
|
||||||
import { clickhouse, query } from "./lib/clickhouse.js";
|
import { clickhouse, query } from "../../lib/clickhouse.js";
|
||||||
|
|
||||||
function makeOptionContractDatabase(): OptionContractDatabase {
|
function makeOptionContractDatabase(): OptionContractDatabase {
|
||||||
const optionContractDatabase: Omit<
|
const optionContractDatabase: Omit<
|
||||||
@@ -48,6 +48,31 @@ function makeOptionContractDatabase(): OptionContractDatabase {
|
|||||||
tsStart: aggregate.tsStart * 1000, // unfortunately, `toUnixTimestamp` only returns second-precision
|
tsStart: aggregate.tsStart * 1000, // unfortunately, `toUnixTimestamp` only returns second-precision
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
getAggregate: async ({
|
||||||
|
key: { symbol, expirationDate, strike, type },
|
||||||
|
tsStart,
|
||||||
|
}) => {
|
||||||
|
const tsStartString = new Date(tsStart).toISOString();
|
||||||
|
return (
|
||||||
|
await query<Omit<Aggregate<OptionContractKey>, "key">>(`
|
||||||
|
SELECT
|
||||||
|
open,
|
||||||
|
close,
|
||||||
|
high,
|
||||||
|
low
|
||||||
|
FROM option_contract_aggregates
|
||||||
|
WHERE symbol = '${symbol}'
|
||||||
|
AND type = '${type}'
|
||||||
|
AND strike = '${strike}'
|
||||||
|
AND expirationDate = '${expirationDate}'
|
||||||
|
AND tsStart = '${tsStartString}'
|
||||||
|
ORDER BY tsStart ASC
|
||||||
|
`)
|
||||||
|
).map((aggregate) => ({
|
||||||
|
...aggregate,
|
||||||
|
tsStart,
|
||||||
|
}))[0];
|
||||||
|
},
|
||||||
insertAggregates: async (aggregates) => {
|
insertAggregates: async (aggregates) => {
|
||||||
// stock existence is taken care of by clickhouse materialized view
|
// stock existence is taken care of by clickhouse materialized view
|
||||||
await clickhouse.insert({
|
await clickhouse.insert({
|
||||||
@@ -70,7 +95,7 @@ function makeOptionContractDatabase(): OptionContractDatabase {
|
|||||||
close,
|
close,
|
||||||
high,
|
high,
|
||||||
low,
|
low,
|
||||||
}),
|
})
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -86,5 +111,4 @@ function makeOptionContractDatabase(): OptionContractDatabase {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const optionContractDatabase: OptionContractDatabase =
|
export const database: OptionContractDatabase = makeOptionContractDatabase();
|
||||||
makeOptionContractDatabase();
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import type { AggregateDatabase } from "./interfaces.js";
|
import type { AggregateDatabase } from "../interfaces.js";
|
||||||
|
|
||||||
export type OptionContractKey = {
|
export type OptionContractKey = {
|
||||||
symbol: string;
|
symbol: string;
|
||||||
+42
-22
@@ -1,4 +1,4 @@
|
|||||||
import type { OptionContractDatabase } from "./optiondb.interfaces.js";
|
import type { OptionContractDatabase } from "./interfaces.js";
|
||||||
import { open } from "lmdbx";
|
import { open } from "lmdbx";
|
||||||
|
|
||||||
const optionContractAggregatesDb = open({
|
const optionContractAggregatesDb = open({
|
||||||
@@ -17,6 +17,25 @@ const optionContractExistenceDb = open({
|
|||||||
const MAXIMUM_KEY = Buffer.from([0xff]);
|
const MAXIMUM_KEY = Buffer.from([0xff]);
|
||||||
|
|
||||||
function makeOptionContractDatabase(): OptionContractDatabase {
|
function makeOptionContractDatabase(): OptionContractDatabase {
|
||||||
|
const getAggregatesSync = ({
|
||||||
|
key: { symbol, expirationDate, strike, type },
|
||||||
|
date,
|
||||||
|
}) => {
|
||||||
|
const startOfDayUnix = new Date(`${date}T00:00:00Z`).valueOf();
|
||||||
|
const endOfDayUnix = startOfDayUnix + 3600 * 24 * 1000;
|
||||||
|
return optionContractAggregatesDb
|
||||||
|
.getRange({
|
||||||
|
start: [symbol, expirationDate, strike, type, startOfDayUnix],
|
||||||
|
end: [symbol, expirationDate, strike, type, endOfDayUnix],
|
||||||
|
})
|
||||||
|
.map(({ key, value }) => ({
|
||||||
|
tsStart: key[4],
|
||||||
|
open: value.open,
|
||||||
|
close: value.close,
|
||||||
|
high: value.high,
|
||||||
|
low: value.low,
|
||||||
|
})).asArray;
|
||||||
|
};
|
||||||
const optionContractDatabase: Omit<
|
const optionContractDatabase: Omit<
|
||||||
OptionContractDatabase,
|
OptionContractDatabase,
|
||||||
"getOptionContracts"
|
"getOptionContracts"
|
||||||
@@ -34,25 +53,15 @@ function makeOptionContractDatabase(): OptionContractDatabase {
|
|||||||
type: key[4],
|
type: key[4],
|
||||||
})).asArray;
|
})).asArray;
|
||||||
},
|
},
|
||||||
|
getAggregatesSync,
|
||||||
getAggregates: async ({
|
getAggregates: async ({
|
||||||
key: { symbol, expirationDate, strike, type },
|
key: { symbol, expirationDate, strike, type },
|
||||||
date,
|
date,
|
||||||
}) => {
|
}) =>
|
||||||
const startOfDayUnix = new Date(`${date}T00:00:00Z`).valueOf();
|
getAggregatesSync({
|
||||||
const endOfDayUnix = startOfDayUnix + 3600 * 24 * 1000;
|
key: { symbol, expirationDate, strike, type },
|
||||||
return optionContractAggregatesDb
|
date,
|
||||||
.getRange({
|
}),
|
||||||
start: [symbol, expirationDate, strike, type, startOfDayUnix],
|
|
||||||
end: [symbol, expirationDate, strike, type, endOfDayUnix],
|
|
||||||
})
|
|
||||||
.map(({ value }) => ({
|
|
||||||
tsStart: value.tsStart,
|
|
||||||
open: value.open,
|
|
||||||
close: value.close,
|
|
||||||
high: value.high,
|
|
||||||
low: value.low,
|
|
||||||
})).asArray;
|
|
||||||
},
|
|
||||||
insertAggregates: async (aggregates) => {
|
insertAggregates: async (aggregates) => {
|
||||||
await optionContractExistenceDb.batch(() => {
|
await optionContractExistenceDb.batch(() => {
|
||||||
for (const aggregate of aggregates) {
|
for (const aggregate of aggregates) {
|
||||||
@@ -64,7 +73,7 @@ function makeOptionContractDatabase(): OptionContractDatabase {
|
|||||||
aggregate.key.strike,
|
aggregate.key.strike,
|
||||||
aggregate.key.type,
|
aggregate.key.type,
|
||||||
],
|
],
|
||||||
null,
|
null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -83,7 +92,7 @@ function makeOptionContractDatabase(): OptionContractDatabase {
|
|||||||
close: aggregate.close,
|
close: aggregate.close,
|
||||||
high: aggregate.high,
|
high: aggregate.high,
|
||||||
low: aggregate.low,
|
low: aggregate.low,
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -92,7 +101,7 @@ function makeOptionContractDatabase(): OptionContractDatabase {
|
|||||||
key: { symbol, strike, type, expirationDate },
|
key: { symbol, strike, type, expirationDate },
|
||||||
}) => {
|
}) => {
|
||||||
const startOfLastHourUnix = new Date(
|
const startOfLastHourUnix = new Date(
|
||||||
`${expirationDate}T00:00:00Z`,
|
`${expirationDate}T00:00:00Z`
|
||||||
).valueOf();
|
).valueOf();
|
||||||
const endOfLastHourUnix = startOfLastHourUnix + 3600 * 1000;
|
const endOfLastHourUnix = startOfLastHourUnix + 3600 * 1000;
|
||||||
let minPrice = 0;
|
let minPrice = 0;
|
||||||
@@ -106,6 +115,18 @@ function makeOptionContractDatabase(): OptionContractDatabase {
|
|||||||
}
|
}
|
||||||
return minPrice;
|
return minPrice;
|
||||||
},
|
},
|
||||||
|
getAggregate: async ({
|
||||||
|
key: { symbol, expirationDate, strike, type },
|
||||||
|
tsStart,
|
||||||
|
}) => {
|
||||||
|
return await optionContractAggregatesDb.get([
|
||||||
|
symbol,
|
||||||
|
expirationDate,
|
||||||
|
strike,
|
||||||
|
type,
|
||||||
|
tsStart,
|
||||||
|
]);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -114,5 +135,4 @@ function makeOptionContractDatabase(): OptionContractDatabase {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const optionContractDatabase: OptionContractDatabase =
|
export const database: OptionContractDatabase = makeOptionContractDatabase();
|
||||||
makeOptionContractDatabase();
|
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import type { StockDatabase, StockKey } from "./interfaces.js";
|
||||||
|
import type { Aggregate } from "../interfaces.js";
|
||||||
|
import { clickhouse, query } from "../../lib/clickhouse.js";
|
||||||
|
|
||||||
|
function makeStockDatabase(): StockDatabase {
|
||||||
|
const stockDatabase: Omit<StockDatabase, "getSymbols"> = {
|
||||||
|
getKeys: async ({ date, key }) => {
|
||||||
|
if (key?.symbol) {
|
||||||
|
return [key as StockKey];
|
||||||
|
}
|
||||||
|
return await query(`
|
||||||
|
SELECT DISTINCT symbol FROM stock_aggregates WHERE toDate(tsStart) = '${date}'
|
||||||
|
`);
|
||||||
|
},
|
||||||
|
getAggregates: async ({ key: { symbol }, date }) => {
|
||||||
|
return (
|
||||||
|
await query<Omit<Aggregate<StockKey>, "key">>(`
|
||||||
|
SELECT
|
||||||
|
toUnixTimestamp(tsStart) as tsStart,
|
||||||
|
open,
|
||||||
|
close,
|
||||||
|
high,
|
||||||
|
low
|
||||||
|
FROM stock_aggregates
|
||||||
|
WHERE symbol = '${symbol}'
|
||||||
|
AND toDate(tsStart) = '${date}'
|
||||||
|
ORDER BY tsStart ASC
|
||||||
|
`)
|
||||||
|
).map((aggregate) => ({
|
||||||
|
...aggregate,
|
||||||
|
tsStart: aggregate.tsStart * 1000, // unfortunately, `toUnixTimestamp` only returns second-precision
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
getAggregate: async ({ key: { symbol }, tsStart }) => {
|
||||||
|
return (
|
||||||
|
await query<Omit<Aggregate<StockKey>, "key">>(`
|
||||||
|
SELECT
|
||||||
|
open,
|
||||||
|
close,
|
||||||
|
high,
|
||||||
|
low
|
||||||
|
FROM stock_aggregates
|
||||||
|
WHERE symbol = '${symbol}'
|
||||||
|
AND tsStart = '${tsStart}'
|
||||||
|
`)
|
||||||
|
).map((aggregate) => ({
|
||||||
|
...aggregate,
|
||||||
|
tsStart,
|
||||||
|
}))[0];
|
||||||
|
},
|
||||||
|
insertAggregates: async (aggregates) => {
|
||||||
|
// stock existence is taken care of by clickhouse materialized view
|
||||||
|
await clickhouse.insert({
|
||||||
|
table: "stock_aggregates",
|
||||||
|
values: aggregates.map(
|
||||||
|
({ key: { symbol }, tsStart, open, close, high, low }) => ({
|
||||||
|
symbol,
|
||||||
|
tsStart,
|
||||||
|
open,
|
||||||
|
close,
|
||||||
|
high,
|
||||||
|
low,
|
||||||
|
})
|
||||||
|
),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getClosingPrice: async ({ key }) => {
|
||||||
|
// no-op: not used since stocks don't have a "closing" price, unlike options.
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...stockDatabase,
|
||||||
|
getSymbols: stockDatabase.getKeys,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const database: StockDatabase = makeStockDatabase();
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import type { AggregateDatabase } from "../interfaces.js";
|
||||||
|
|
||||||
|
export type StockKey = { symbol: string };
|
||||||
|
|
||||||
|
export type StockDatabase = AggregateDatabase<StockKey> & {
|
||||||
|
getSymbols: AggregateDatabase<StockKey>["getKeys"];
|
||||||
|
};
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import type { StockDatabase, StockKey } from "./interfaces.js";
|
||||||
|
import { open } from "lmdbx";
|
||||||
|
|
||||||
|
const stockAggregatesDb = open({
|
||||||
|
path: "./stock-aggregates.db",
|
||||||
|
// any options go here, we can turn on compression like this:
|
||||||
|
compression: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const stockExistenceDb = open({
|
||||||
|
path: "./stock-existence.db",
|
||||||
|
// any options go here, we can turn on compression like this:
|
||||||
|
compression: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** Largest possible key according to the `ordered-binary` (used by lmdbx) docs. */
|
||||||
|
const MAXIMUM_KEY = Buffer.from([0xff]);
|
||||||
|
|
||||||
|
function makeStockDatabase(): StockDatabase {
|
||||||
|
const stockDatabase: Omit<StockDatabase, "getSymbols"> = {
|
||||||
|
getKeys: async ({ date, key }) => {
|
||||||
|
if (key?.symbol) {
|
||||||
|
return [key as StockKey];
|
||||||
|
}
|
||||||
|
return stockExistenceDb
|
||||||
|
.getRange({
|
||||||
|
start: [date],
|
||||||
|
end: [date, MAXIMUM_KEY],
|
||||||
|
})
|
||||||
|
.map(({ key }) => ({ symbol: key[1] })).asArray;
|
||||||
|
},
|
||||||
|
getAggregates: async ({ key: { symbol }, date }) => {
|
||||||
|
const startOfDayUnix = new Date(`${date}T00:00:00Z`).valueOf();
|
||||||
|
const endOfDayUnix = startOfDayUnix + 3600 * 24 * 1000;
|
||||||
|
return stockAggregatesDb
|
||||||
|
.getRange({
|
||||||
|
start: [symbol, startOfDayUnix],
|
||||||
|
end: [symbol, endOfDayUnix],
|
||||||
|
})
|
||||||
|
.map(({ key, value }) => ({
|
||||||
|
tsStart: key[1],
|
||||||
|
open: value.open,
|
||||||
|
close: value.close,
|
||||||
|
high: value.high,
|
||||||
|
low: value.low,
|
||||||
|
})).asArray;
|
||||||
|
},
|
||||||
|
getAggregate: async ({ key: { symbol }, tsStart }) => {
|
||||||
|
return stockAggregatesDb.get([symbol, tsStart]);
|
||||||
|
},
|
||||||
|
insertAggregates: async (aggregates) => {
|
||||||
|
await stockExistenceDb.batch(() => {
|
||||||
|
for (const aggregate of aggregates) {
|
||||||
|
stockExistenceDb.put(
|
||||||
|
[
|
||||||
|
new Date(aggregate.tsStart).toISOString().substring(0, 10),
|
||||||
|
aggregate.key.symbol,
|
||||||
|
],
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await stockAggregatesDb.batch(() => {
|
||||||
|
for (const aggregate of aggregates) {
|
||||||
|
stockAggregatesDb.put([aggregate.key.symbol, aggregate.tsStart], {
|
||||||
|
open: aggregate.open,
|
||||||
|
close: aggregate.close,
|
||||||
|
high: aggregate.high,
|
||||||
|
low: aggregate.low,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getClosingPrice: async ({ key }) => {
|
||||||
|
// no-op: not used since stocks don't have a "closing" price, unlike options.
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...stockDatabase,
|
||||||
|
getSymbols: stockDatabase.getKeys,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const database: StockDatabase = makeStockDatabase();
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
export type Candlestick = {
|
||||||
|
open: number;
|
||||||
|
close: number;
|
||||||
|
high: number;
|
||||||
|
low: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Aggregate<T> = {
|
||||||
|
key: T;
|
||||||
|
/** UNIX time in milliseconds */
|
||||||
|
tsStart: number;
|
||||||
|
} & Candlestick;
|
||||||
|
|
||||||
|
export type AggregateDatabase<T> = {
|
||||||
|
getKeys: ({
|
||||||
|
key,
|
||||||
|
date,
|
||||||
|
}: {
|
||||||
|
key?: T | Partial<T>;
|
||||||
|
date?: string;
|
||||||
|
}) => Promise<Array<T>>;
|
||||||
|
getAggregates: ({
|
||||||
|
key,
|
||||||
|
date,
|
||||||
|
}: {
|
||||||
|
key: T;
|
||||||
|
date: string;
|
||||||
|
}) => Promise<Array<Omit<Aggregate<T>, "key">>>;
|
||||||
|
/** Since an aggregate may not exist at the specified `tsStart`, return `undefined` if it doesn't exist. */
|
||||||
|
getAggregate: ({
|
||||||
|
key,
|
||||||
|
tsStart,
|
||||||
|
}: {
|
||||||
|
key: T;
|
||||||
|
tsStart: number;
|
||||||
|
}) => Promise<Omit<Aggregate<T>, "key"> | undefined>;
|
||||||
|
getAggregatesSync?: ({
|
||||||
|
key,
|
||||||
|
date,
|
||||||
|
}: {
|
||||||
|
key: T;
|
||||||
|
date: string;
|
||||||
|
}) => Array<Omit<Aggregate<T>, "key">>;
|
||||||
|
insertAggregates: (aggregates: Array<Aggregate<T>>) => Promise<void>;
|
||||||
|
getClosingPrice: ({ key }: { key: T }) => Promise<number>;
|
||||||
|
};
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import { query } from "./lib/clickhouse.js";
|
||||||
|
import { publicProcedure, RpcType, router } from "./trpc.js";
|
||||||
|
import {
|
||||||
|
Object as ObjectT,
|
||||||
|
String as StringT,
|
||||||
|
Number as NumberT,
|
||||||
|
} from "@sinclair/typebox";
|
||||||
|
|
||||||
|
/** Gets a list of symbols that have at least one option contract */
|
||||||
|
export const getAvailableUnderlyings = publicProcedure.query(async (opts) => {
|
||||||
|
// return (
|
||||||
|
// await query<{ symbol: string }>(`
|
||||||
|
// SELECT DISTINCT(symbol) as symbol FROM option_contract_existences WHERE asOfDate = (SELECT max(asOfDate) FROM option_contract_existences)
|
||||||
|
// `)
|
||||||
|
// ).map(({ symbol }) => symbol);
|
||||||
|
return ["SPY"];
|
||||||
|
});
|
||||||
|
|
||||||
|
export const getAvailableAsOfDates = publicProcedure
|
||||||
|
.input(RpcType(ObjectT({ underlying: StringT() })))
|
||||||
|
.query(async (opts) => {
|
||||||
|
const underlying = opts.input.underlying;
|
||||||
|
return (
|
||||||
|
await query<{ asOfDate: string }>(`
|
||||||
|
SELECT
|
||||||
|
DISTINCT(asOfDate) as asOfDate
|
||||||
|
FROM option_contract_existences
|
||||||
|
WHERE symbol = '${underlying}'
|
||||||
|
ORDER BY asOfDate
|
||||||
|
`)
|
||||||
|
).map(({ asOfDate }) => asOfDate);
|
||||||
|
});
|
||||||
|
|
||||||
|
export const getExpirationsForUnderlying = publicProcedure
|
||||||
|
.input(
|
||||||
|
RpcType(
|
||||||
|
ObjectT({
|
||||||
|
underlying: StringT({ maxLength: 5 }),
|
||||||
|
asOfDate: StringT(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.query(async (opts) => {
|
||||||
|
const { underlying, asOfDate } = opts.input;
|
||||||
|
return (
|
||||||
|
await query<{ expirationDate: string }>(`
|
||||||
|
SELECT
|
||||||
|
DISTINCT(expirationDate) as expirationDate
|
||||||
|
FROM option_contract_existences
|
||||||
|
WHERE symbol = '${underlying}'
|
||||||
|
AND asOfDate = '${asOfDate}'
|
||||||
|
ORDER BY expirationDate
|
||||||
|
`)
|
||||||
|
).map(({ expirationDate }) => expirationDate);
|
||||||
|
});
|
||||||
|
|
||||||
|
export const getStrikesForUnderlying = publicProcedure
|
||||||
|
.input(
|
||||||
|
RpcType(
|
||||||
|
ObjectT({
|
||||||
|
underlying: StringT({ maxLength: 5 }),
|
||||||
|
asOfDate: StringT(),
|
||||||
|
expirationDate: StringT(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.query(async (opts) => {
|
||||||
|
const { underlying, asOfDate, expirationDate } = opts.input;
|
||||||
|
return (
|
||||||
|
await query<{ strike: string }>(`
|
||||||
|
SELECT
|
||||||
|
DISTINCT(strike) as strike
|
||||||
|
FROM option_contract_existences
|
||||||
|
WHERE symbol = '${underlying}'
|
||||||
|
AND asOfDate = '${asOfDate}'
|
||||||
|
AND expirationDate = '${expirationDate}'
|
||||||
|
ORDER BY strike
|
||||||
|
`)
|
||||||
|
).map(({ strike }) => strike);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router({
|
||||||
|
getAvailableUnderlyings,
|
||||||
|
getAvailableAsOfDates,
|
||||||
|
getExpirationsForUnderlying,
|
||||||
|
getStrikesForUnderlying,
|
||||||
|
});
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { query } from "./lib/clickhouse.js";
|
||||||
|
import { publicProcedure, RpcType, router } from "./trpc.js";
|
||||||
|
import {
|
||||||
|
Object as ObjectT,
|
||||||
|
String as StringT,
|
||||||
|
Number as NumberT,
|
||||||
|
} from "@sinclair/typebox";
|
||||||
|
|
||||||
|
export const getChartData = publicProcedure
|
||||||
|
.input(
|
||||||
|
RpcType(
|
||||||
|
ObjectT({
|
||||||
|
underlying: StringT({ maxLength: 5 }),
|
||||||
|
daysToFrontExpiration: NumberT(),
|
||||||
|
daysBetweenFrontAndBackExpiration: NumberT(),
|
||||||
|
lookbackPeriodStart: StringT({
|
||||||
|
pattern: "[0-9]{4}-[0-9]{2}-[0-9]{2}",
|
||||||
|
}),
|
||||||
|
lookbackPeriodEnd: StringT({ pattern: "[0-9]{4}-[0-9]{2}-[0-9]{2}" }),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.query(async (opts) => {
|
||||||
|
const {
|
||||||
|
underlying,
|
||||||
|
daysToFrontExpiration,
|
||||||
|
daysBetweenFrontAndBackExpiration,
|
||||||
|
lookbackPeriodStart,
|
||||||
|
lookbackPeriodEnd,
|
||||||
|
} = opts.input;
|
||||||
|
return await query<[number, number, number]>(
|
||||||
|
`
|
||||||
|
SELECT
|
||||||
|
moniness*100 as x,
|
||||||
|
FLOOR(price, 1) as y,
|
||||||
|
sum(number_of_quotes) as n
|
||||||
|
FROM calendar_stats
|
||||||
|
WHERE dte = ${daysToFrontExpiration}
|
||||||
|
AND moniness >= -0.05
|
||||||
|
AND moniness <= 0.05
|
||||||
|
AND span = ${daysBetweenFrontAndBackExpiration}
|
||||||
|
AND date >= '${lookbackPeriodStart}'
|
||||||
|
AND date <= '${lookbackPeriodEnd}'
|
||||||
|
GROUP BY x, y
|
||||||
|
ORDER BY x ASC, y ASC
|
||||||
|
`,
|
||||||
|
"JSONEachRow"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router({
|
||||||
|
getChartData,
|
||||||
|
});
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import { query } from "./lib/clickhouse.js";
|
||||||
|
import { publicProcedure, RpcType, router } from "./trpc.js";
|
||||||
|
import {
|
||||||
|
Object as ObjectT,
|
||||||
|
String as StringT,
|
||||||
|
Number as NumberT,
|
||||||
|
} from "@sinclair/typebox";
|
||||||
|
|
||||||
|
/** Returns prices for all matching calendars (i.e. those with similar
|
||||||
|
* characteristics to those given) */
|
||||||
|
export const getChartData = publicProcedure
|
||||||
|
.input(
|
||||||
|
RpcType(
|
||||||
|
ObjectT({
|
||||||
|
underlying: StringT({ maxLength: 5 }),
|
||||||
|
daysToFrontExpiration: NumberT(),
|
||||||
|
daysBetweenFrontAndBackExpiration: NumberT(),
|
||||||
|
strikePercentageFromUnderlyingPriceRangeMin: NumberT(),
|
||||||
|
strikePercentageFromUnderlyingPriceRangeMax: NumberT(),
|
||||||
|
lookbackPeriodStart: StringT(),
|
||||||
|
lookbackPeriodEnd: StringT(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.query(async (opts) => {
|
||||||
|
const {
|
||||||
|
underlying,
|
||||||
|
daysToFrontExpiration,
|
||||||
|
daysBetweenFrontAndBackExpiration,
|
||||||
|
strikePercentageFromUnderlyingPriceRangeMin,
|
||||||
|
strikePercentageFromUnderlyingPriceRangeMax,
|
||||||
|
lookbackPeriodStart,
|
||||||
|
lookbackPeriodEnd,
|
||||||
|
} = opts.input;
|
||||||
|
return await query<[number, number]>(
|
||||||
|
`
|
||||||
|
SELECT
|
||||||
|
toUnixTimestamp(date) as x,
|
||||||
|
price as y
|
||||||
|
FROM calendar_stats
|
||||||
|
WHERE dte = ${daysToFrontExpiration}
|
||||||
|
AND moniness >= ${strikePercentageFromUnderlyingPriceRangeMin}
|
||||||
|
AND moniness <= ${strikePercentageFromUnderlyingPriceRangeMax}
|
||||||
|
AND span = ${daysBetweenFrontAndBackExpiration}
|
||||||
|
AND date >= '${lookbackPeriodStart}'
|
||||||
|
AND date <= '${lookbackPeriodEnd}'
|
||||||
|
`,
|
||||||
|
"JSONEachRow"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router({
|
||||||
|
getChartData,
|
||||||
|
});
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { query } from "./lib/clickhouse.js";
|
||||||
|
import { publicProcedure, RpcType, router } from "./trpc.js";
|
||||||
|
import { Object as ObjectT, String as StringT } from "@sinclair/typebox";
|
||||||
|
|
||||||
|
export const getChartData = publicProcedure
|
||||||
|
.input(
|
||||||
|
RpcType(
|
||||||
|
ObjectT({
|
||||||
|
underlying: StringT({ maxLength: 5 }),
|
||||||
|
lookbackPeriodStart: StringT(),
|
||||||
|
lookbackPeriodEnd: StringT(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.query(async (opts) => {
|
||||||
|
const { underlying, lookbackPeriodStart, lookbackPeriodEnd } = opts.input;
|
||||||
|
return await query<[number, number]>(
|
||||||
|
`
|
||||||
|
SELECT
|
||||||
|
toUnixTimestamp(toStartOfHour(ts)) as x,
|
||||||
|
avg(price) as y
|
||||||
|
FROM stock_aggregates_filled
|
||||||
|
WHERE symbol = '${underlying}'
|
||||||
|
AND ts >= '${lookbackPeriodStart} 00:00:00'
|
||||||
|
AND ts <= '${lookbackPeriodEnd} 00:00:00'
|
||||||
|
GROUP BY x
|
||||||
|
ORDER BY x ASC
|
||||||
|
`,
|
||||||
|
"JSONCompactEachRow"
|
||||||
|
// "JSONEachRow"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router({
|
||||||
|
getChartData,
|
||||||
|
});
|
||||||
+35
-36
@@ -1,23 +1,23 @@
|
|||||||
import { stockDatabase } from "./stockdb.clickhouse.js";
|
import { database as stockDatabase } from "./AggregateDatabase/Stock/lmdbx.js";
|
||||||
import { calendarDatabase } from "./calendardb.optiondb.lmdbx.js";
|
import { database as calendarDatabase } from "./AggregateDatabase/Calendar/optiondb-lmdbx.js";
|
||||||
import type { CalendarKey } from "./calendardb.interfaces.js";
|
import type { CalendarKey } from "./AggregateDatabase/Calendar/interfaces.js";
|
||||||
import type { Aggregate } from "./interfaces.js";
|
import { nextDate } from "./lib/utils/nextDate.js";
|
||||||
import { nextDate } from "./lib/util.js";
|
|
||||||
|
|
||||||
type BacktestInput = {
|
export type BacktestInput = {
|
||||||
symbol: string;
|
symbol: string;
|
||||||
startDate: string;
|
startDate: string;
|
||||||
endDate: string;
|
endDate: string;
|
||||||
/** Between 0 and 1. The frequency that similar calendars have historically ended (i.e. within the last hour) at a higher price than the current calendar's price. */
|
/** Between 0 and 1. The frequency that similar calendars have historically ended (i.e. within the last hour) at a higher price than the current calendar's price. */
|
||||||
historicalProbabilityOfSuccess?: number;
|
historicalProbabilityOfSuccess?: number;
|
||||||
initialAvailableValue?: number;
|
initialBuyingPower?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function backtest({
|
export async function backtest({
|
||||||
symbol,
|
symbol,
|
||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
historicalProbabilityOfSuccess = 0.8,
|
historicalProbabilityOfSuccess = 0.8,
|
||||||
initialAvailableValue: initialBuyingPower = 2000,
|
initialBuyingPower = 2000,
|
||||||
}: BacktestInput) {
|
}: BacktestInput) {
|
||||||
let buyingPower = initialBuyingPower;
|
let buyingPower = initialBuyingPower;
|
||||||
const portfolio = new Set<CalendarKey>();
|
const portfolio = new Set<CalendarKey>();
|
||||||
@@ -27,59 +27,56 @@ export async function backtest({
|
|||||||
date <= endDate;
|
date <= endDate;
|
||||||
date = nextDate(date), didBuyCalendar = false
|
date = nextDate(date), didBuyCalendar = false
|
||||||
) {
|
) {
|
||||||
console.log("Current Date:", date);
|
|
||||||
const calendars = await calendarDatabase.getCalendars({
|
const calendars = await calendarDatabase.getCalendars({
|
||||||
key: { symbol },
|
key: { symbol },
|
||||||
date,
|
date,
|
||||||
});
|
});
|
||||||
const stockAggregates = await stockDatabase.getAggregates({
|
const stockAggregates = await stockDatabase.getAggregates({
|
||||||
key: symbol,
|
key: { symbol },
|
||||||
date,
|
date,
|
||||||
});
|
});
|
||||||
const calendarsAggregates = new Map<
|
|
||||||
CalendarKey,
|
|
||||||
Array<Pick<Aggregate<CalendarKey>, "tsStart" | "open" | "close">>
|
|
||||||
>();
|
|
||||||
for (const calendar of calendars) {
|
|
||||||
calendarsAggregates.set(
|
|
||||||
calendar,
|
|
||||||
await calendarDatabase.getAggregates({
|
|
||||||
key: {
|
|
||||||
...calendar,
|
|
||||||
},
|
|
||||||
date,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// for each minute of that day for which we have a stock candlestick:
|
// for each minute of that day for which we have a stock candlestick:
|
||||||
for (const stockAggregate of stockAggregates) {
|
for (const stockAggregate of stockAggregates) {
|
||||||
// console.log("Current Time:", new Date(stockAggregate.tsStart));
|
// console.log("Current Time:", new Date(stockAggregate.tsStart));
|
||||||
// filter-out calendars that are far-from-the-money (10%)
|
// filter-out calendars that are far-from-the-money (5%)
|
||||||
const calendarsNearTheMoney = calendars.filter(
|
const calendarsNearTheMoney = calendars.filter(
|
||||||
({ strike }) =>
|
({ strike }) =>
|
||||||
Math.abs((stockAggregate.open - strike) / stockAggregate.open) < 0.1
|
Math.abs((stockAggregate.open - strike) / stockAggregate.open) < 0.05
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
"Current Date:",
|
||||||
|
new Intl.DateTimeFormat("en-US", {
|
||||||
|
timeZone: "America/New_York",
|
||||||
|
dateStyle: "full",
|
||||||
|
timeStyle: "long",
|
||||||
|
}).format(new Date(stockAggregate.tsStart)),
|
||||||
|
";",
|
||||||
|
`${calendarsNearTheMoney.length} Calendars Near The Money`
|
||||||
);
|
);
|
||||||
// for each relevant calendar on that day:
|
// for each relevant calendar on that day:
|
||||||
for (const calendar of calendarsNearTheMoney) {
|
for (const calendar of calendarsNearTheMoney) {
|
||||||
const strikePercentageFromTheMoney = Math.abs(
|
const strikePercentageFromTheMoney = Math.abs(
|
||||||
(stockAggregate.open - calendar.strike) / stockAggregate.open
|
(stockAggregate.open - calendar.strike) / stockAggregate.open
|
||||||
);
|
);
|
||||||
/** In days. */
|
/** Number of days between the back and front expiration dates. */
|
||||||
const calendarSpan =
|
const calendarSpanInDays =
|
||||||
(new Date(calendar.backExpirationDate).valueOf() -
|
(new Date(calendar.backExpirationDate).valueOf() -
|
||||||
new Date(calendar.frontExpirationDate).valueOf()) /
|
new Date(calendar.frontExpirationDate).valueOf()) /
|
||||||
(1000 * 60 * 60 * 24);
|
(1000 * 60 * 60 * 24);
|
||||||
const targetCalendarPrice =
|
const targetCalendarPrice =
|
||||||
await calendarDatabase.getTargetPriceByProbability({
|
await calendarDatabase.getTargetPriceByProbability({
|
||||||
symbol,
|
symbol,
|
||||||
calendarSpan,
|
calendarSpan: calendarSpanInDays,
|
||||||
strikePercentageFromTheMoney,
|
strikePercentageFromTheMoney,
|
||||||
historicalProbabilityOfSuccess,
|
historicalProbabilityOfSuccess,
|
||||||
});
|
});
|
||||||
const calendarAggregates = calendarsAggregates.get(calendar);
|
const calendarAggregateAtCurrentTime =
|
||||||
const calendarAggregateAtCurrentTime = calendarAggregates.find(
|
await calendarDatabase.getAggregate({
|
||||||
({ tsStart }) => tsStart === stockAggregate.tsStart
|
key: {
|
||||||
);
|
...calendar,
|
||||||
|
},
|
||||||
|
tsStart: stockAggregate.tsStart,
|
||||||
|
});
|
||||||
// if there exists a matching calendar candlestick for the current minute:
|
// if there exists a matching calendar candlestick for the current minute:
|
||||||
if (calendarAggregateAtCurrentTime) {
|
if (calendarAggregateAtCurrentTime) {
|
||||||
// if the current candlestick is a good price (i.e. less than the target price):
|
// if the current candlestick is a good price (i.e. less than the target price):
|
||||||
@@ -142,6 +139,8 @@ export async function backtest({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Ending Buying Power:", buyingPower);
|
return {
|
||||||
console.log("Portfolio:", portfolio.values());
|
endingBuyingPower: buyingPower,
|
||||||
|
portfolio: Array.from(portfolio.values()),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,142 +0,0 @@
|
|||||||
import type { CalendarDatabase, CalendarKey } from "./calendardb.interfaces.js";
|
|
||||||
import type { Aggregate } from "./interfaces.js";
|
|
||||||
import { query } from "./lib/clickhouse.js";
|
|
||||||
|
|
||||||
function makeCalendarDatabase(): CalendarDatabase {
|
|
||||||
const calendarDatabase: Omit<CalendarDatabase, "getCalendars"> = {
|
|
||||||
getKeys: async ({ key: { symbol }, date }) => {
|
|
||||||
const calendarsForSymbolOnDate = await query<
|
|
||||||
Omit<CalendarKey, "symbol">
|
|
||||||
>(`
|
|
||||||
WITH today_option_contracts AS (
|
|
||||||
SELECT expirationDate, strike, type
|
|
||||||
FROM option_contract_existences
|
|
||||||
WHERE symbol = '${symbol}'
|
|
||||||
AND asOfDate = '${date}'
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
front_option_contract.type as type,
|
|
||||||
front_option_contract.strike as strike,
|
|
||||||
front_option_contract.expirationDate as frontExpirationDate,
|
|
||||||
back_option_contract.expirationDate as backExpirationDate
|
|
||||||
FROM today_option_contracts AS front_option_contract
|
|
||||||
ASOF INNER JOIN today_option_contracts AS back_option_contract
|
|
||||||
ON front_option_contract.type = back_option_contract.type
|
|
||||||
AND front_option_contract.strike = back_option_contract.strike
|
|
||||||
AND front_option_contract.expirationDate < back_option_contract.expirationDate
|
|
||||||
`);
|
|
||||||
|
|
||||||
return calendarsForSymbolOnDate.map((calendarWithoutSymbol) => ({
|
|
||||||
...calendarWithoutSymbol,
|
|
||||||
symbol,
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
getAggregates: async ({
|
|
||||||
key: { symbol, frontExpirationDate, backExpirationDate, strike, type },
|
|
||||||
date,
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
await query<Omit<Aggregate<CalendarKey>, "key">>(`
|
|
||||||
WITH front_option_contract_candlestick AS (
|
|
||||||
SELECT
|
|
||||||
tsStart,
|
|
||||||
open,
|
|
||||||
close,
|
|
||||||
high,
|
|
||||||
low
|
|
||||||
FROM option_contract_aggregates
|
|
||||||
WHERE symbol = '${symbol}'
|
|
||||||
AND type = '${type}'
|
|
||||||
AND strike = '${strike}'
|
|
||||||
AND expirationDate = '${frontExpirationDate}'
|
|
||||||
AND toDate(tsStart) = '${date}'
|
|
||||||
),
|
|
||||||
back_option_contract_candlestick AS (
|
|
||||||
SELECT
|
|
||||||
tsStart,
|
|
||||||
open,
|
|
||||||
close,
|
|
||||||
high,
|
|
||||||
low
|
|
||||||
FROM option_contract_aggregates
|
|
||||||
WHERE symbol = '${symbol}'
|
|
||||||
AND type = '${type}'
|
|
||||||
AND strike = '${strike}'
|
|
||||||
AND expirationDate = '${backExpirationDate}'
|
|
||||||
AND toDate(tsStart) = '${date}'
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
toUnixTimestamp(front_option_contract_candlestick.tsStart) as tsStart,
|
|
||||||
back_option_contract_candlestick.open - front_option_contract_candlestick.open as open,
|
|
||||||
back_option_contract_candlestick.close - front_option_contract_candlestick.close as close
|
|
||||||
FROM front_option_contract_candlestick
|
|
||||||
INNER JOIN back_option_contract_candlestick
|
|
||||||
ON front_option_contract_candlestick.tsStart = back_option_contract_candlestick.tsStart
|
|
||||||
ORDER BY front_option_contract_candlestick.tsStart ASC
|
|
||||||
`)
|
|
||||||
).map((aggregate) => ({
|
|
||||||
...aggregate,
|
|
||||||
tsStart: aggregate.tsStart * 1000, // unfortunately, `toUnixTimestamp` only returns second-precision
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
insertAggregates: async (aggregates) => {
|
|
||||||
// no-op: we insert individual option contracts, not calendars
|
|
||||||
},
|
|
||||||
getClosingPrice: async ({
|
|
||||||
key: { symbol, strike, type, frontExpirationDate, backExpirationDate },
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
await query<{ calendarClosingPrice: number }>(`
|
|
||||||
WITH front_option_contract_candlestick AS (
|
|
||||||
SELECT
|
|
||||||
tsStart,
|
|
||||||
open,
|
|
||||||
close,
|
|
||||||
high,
|
|
||||||
low
|
|
||||||
FROM option_contract_aggregates
|
|
||||||
WHERE symbol = '${symbol}'
|
|
||||||
AND type = '${type}'
|
|
||||||
AND strike = '${strike}'
|
|
||||||
AND expirationDate = '${frontExpirationDate}'
|
|
||||||
AND toDate(tsStart) = '${frontExpirationDate}'
|
|
||||||
),
|
|
||||||
back_option_contract_candlestick AS (
|
|
||||||
SELECT
|
|
||||||
tsStart,
|
|
||||||
open,
|
|
||||||
close,
|
|
||||||
high,
|
|
||||||
low
|
|
||||||
FROM option_contract_aggregates
|
|
||||||
WHERE symbol = '${symbol}'
|
|
||||||
AND type = '${type}'
|
|
||||||
AND strike = '${strike}'
|
|
||||||
AND expirationDate = '${backExpirationDate}'
|
|
||||||
AND toDate(tsStart) = '${frontExpirationDate}'
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
min(back_option_contract_candlestick.close - front_option_contract_candlestick.close) as calendarClosingPrice
|
|
||||||
FROM front_option_contract_candlestick
|
|
||||||
INNER JOIN back_option_contract_candlestick
|
|
||||||
ON front_option_contract_candlestick.tsStart = back_option_contract_candlestick.tsStart
|
|
||||||
`)
|
|
||||||
)[0]?.calendarClosingPrice;
|
|
||||||
},
|
|
||||||
getTargetPriceByProbability: async ({
|
|
||||||
symbol,
|
|
||||||
calendarSpan,
|
|
||||||
strikePercentageFromTheMoney,
|
|
||||||
historicalProbabilityOfSuccess,
|
|
||||||
}) => {
|
|
||||||
return 0.24;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
...calendarDatabase,
|
|
||||||
getCalendars: calendarDatabase.getKeys,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const calendarDatabase: CalendarDatabase = makeCalendarDatabase();
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import type { AggregateDatabase } from "./interfaces.js";
|
|
||||||
|
|
||||||
export type CalendarKey = {
|
|
||||||
symbol: string;
|
|
||||||
type: "call" | "put";
|
|
||||||
strike: number;
|
|
||||||
frontExpirationDate: string;
|
|
||||||
backExpirationDate: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type CalendarDatabase = AggregateDatabase<CalendarKey> & {
|
|
||||||
getCalendars: AggregateDatabase<CalendarKey>["getKeys"];
|
|
||||||
getTargetPriceByProbability: ({
|
|
||||||
symbol,
|
|
||||||
calendarSpan,
|
|
||||||
strikePercentageFromTheMoney,
|
|
||||||
historicalProbabilityOfSuccess,
|
|
||||||
}: {
|
|
||||||
symbol: string;
|
|
||||||
calendarSpan: number;
|
|
||||||
strikePercentageFromTheMoney: number;
|
|
||||||
historicalProbabilityOfSuccess: number;
|
|
||||||
}) => Promise<number>;
|
|
||||||
};
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
import type { CalendarDatabase } from "./calendardb.interfaces.js";
|
|
||||||
import { open } from "lmdbx";
|
|
||||||
|
|
||||||
const calendarAggregatesDb = open({
|
|
||||||
path: "./calendar-aggregates.db",
|
|
||||||
// any options go here, we can turn on compression like this:
|
|
||||||
compression: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const calendarExistenceDb = open({
|
|
||||||
path: "./calendar-existence.db",
|
|
||||||
// any options go here, we can turn on compression like this:
|
|
||||||
compression: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
/** Largest possible key according to the `ordered-binary` (used by lmdbx) docs. */
|
|
||||||
const MAXIMUM_KEY = Buffer.from([0xff]);
|
|
||||||
|
|
||||||
function makeCalendarDatabase(): CalendarDatabase {
|
|
||||||
const calendarDatabase: Omit<CalendarDatabase, "getCalendars"> = {
|
|
||||||
getKeys: async ({ key: { symbol }, date }) => {
|
|
||||||
return calendarExistenceDb
|
|
||||||
.getRange({
|
|
||||||
start: [date, symbol],
|
|
||||||
end: [date, symbol, MAXIMUM_KEY],
|
|
||||||
})
|
|
||||||
.map(({ key }) => ({
|
|
||||||
symbol,
|
|
||||||
frontExpirationDate: key[2],
|
|
||||||
backExpirationDate: key[3],
|
|
||||||
strike: key[4],
|
|
||||||
type: key[5],
|
|
||||||
})).asArray;
|
|
||||||
},
|
|
||||||
getAggregates: async ({
|
|
||||||
key: { symbol, frontExpirationDate, backExpirationDate, strike, type },
|
|
||||||
date,
|
|
||||||
}) => {
|
|
||||||
const startOfDayUnix = new Date(`${date}T00:00:00Z`).valueOf();
|
|
||||||
const endOfDayUnix = startOfDayUnix + 3600 * 24 * 1000;
|
|
||||||
return calendarAggregatesDb
|
|
||||||
.getRange({
|
|
||||||
start: [
|
|
||||||
symbol,
|
|
||||||
frontExpirationDate,
|
|
||||||
backExpirationDate,
|
|
||||||
strike,
|
|
||||||
type,
|
|
||||||
startOfDayUnix,
|
|
||||||
],
|
|
||||||
end: [
|
|
||||||
symbol,
|
|
||||||
frontExpirationDate,
|
|
||||||
backExpirationDate,
|
|
||||||
strike,
|
|
||||||
type,
|
|
||||||
endOfDayUnix,
|
|
||||||
],
|
|
||||||
})
|
|
||||||
.map(({ value }) => ({
|
|
||||||
tsStart: value.tsStart,
|
|
||||||
open: value.open,
|
|
||||||
close: value.close,
|
|
||||||
high: value.high,
|
|
||||||
low: value.low,
|
|
||||||
})).asArray;
|
|
||||||
},
|
|
||||||
insertAggregates: async (aggregates) => {
|
|
||||||
await calendarExistenceDb.batch(() => {
|
|
||||||
for (const aggregate of aggregates) {
|
|
||||||
calendarExistenceDb.put(
|
|
||||||
[
|
|
||||||
new Date(aggregate.tsStart).toISOString().substring(0, 10),
|
|
||||||
aggregate.key.symbol,
|
|
||||||
aggregate.key.frontExpirationDate,
|
|
||||||
aggregate.key.backExpirationDate,
|
|
||||||
aggregate.key.strike,
|
|
||||||
aggregate.key.type,
|
|
||||||
],
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
await calendarAggregatesDb.batch(() => {
|
|
||||||
for (const aggregate of aggregates) {
|
|
||||||
calendarAggregatesDb.put(
|
|
||||||
[
|
|
||||||
aggregate.key.symbol,
|
|
||||||
aggregate.key.frontExpirationDate,
|
|
||||||
aggregate.key.backExpirationDate,
|
|
||||||
aggregate.key.strike,
|
|
||||||
aggregate.key.type,
|
|
||||||
aggregate.tsStart,
|
|
||||||
],
|
|
||||||
{
|
|
||||||
open: aggregate.open,
|
|
||||||
close: aggregate.close,
|
|
||||||
high: aggregate.high,
|
|
||||||
low: aggregate.low,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
getClosingPrice: async ({
|
|
||||||
key: { symbol, strike, type, frontExpirationDate, backExpirationDate },
|
|
||||||
}) => {
|
|
||||||
const startOfLastHourUnix = new Date(
|
|
||||||
`${frontExpirationDate}T00:00:00Z`,
|
|
||||||
).valueOf();
|
|
||||||
const endOfLastHourUnix = startOfLastHourUnix + 3600 * 1000;
|
|
||||||
let minPrice = 0;
|
|
||||||
for (const { value } of calendarAggregatesDb.getRange({
|
|
||||||
start: [
|
|
||||||
symbol,
|
|
||||||
frontExpirationDate,
|
|
||||||
backExpirationDate,
|
|
||||||
strike,
|
|
||||||
type,
|
|
||||||
startOfLastHourUnix,
|
|
||||||
],
|
|
||||||
end: [
|
|
||||||
symbol,
|
|
||||||
frontExpirationDate,
|
|
||||||
backExpirationDate,
|
|
||||||
strike,
|
|
||||||
type,
|
|
||||||
endOfLastHourUnix,
|
|
||||||
],
|
|
||||||
})) {
|
|
||||||
if (value.close < minPrice || minPrice === 0) {
|
|
||||||
minPrice = value.close;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return minPrice;
|
|
||||||
},
|
|
||||||
getTargetPriceByProbability: async ({
|
|
||||||
symbol,
|
|
||||||
calendarSpan,
|
|
||||||
strikePercentageFromTheMoney,
|
|
||||||
historicalProbabilityOfSuccess,
|
|
||||||
}) => {
|
|
||||||
return 0.24;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
...calendarDatabase,
|
|
||||||
getCalendars: calendarDatabase.getKeys,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const calendarDatabase: CalendarDatabase = makeCalendarDatabase();
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
import { optionContractDatabase } from "./optiondb.lmdbx.js";
|
|
||||||
import type { CalendarDatabase } from "./calendardb.interfaces.js";
|
|
||||||
|
|
||||||
/** Largest possible key according to the `ordered-binary` (used by lmdbx) docs. */
|
|
||||||
const MAXIMUM_KEY = Buffer.from([0xff]);
|
|
||||||
|
|
||||||
function makeCalendarDatabase(): CalendarDatabase {
|
|
||||||
const calendarDatabase: Omit<CalendarDatabase, "getCalendars"> = {
|
|
||||||
getKeys: async ({ key: { symbol }, date }) => {
|
|
||||||
const optionContracts = await optionContractDatabase.getOptionContracts({
|
|
||||||
date,
|
|
||||||
key: { symbol },
|
|
||||||
});
|
|
||||||
return optionContracts.flatMap(
|
|
||||||
(frontOptionContract, i, optionContracts) =>
|
|
||||||
optionContracts
|
|
||||||
.filter((_, j) => i !== j)
|
|
||||||
.map((backOptionContract) => ({
|
|
||||||
symbol,
|
|
||||||
frontExpirationDate: frontOptionContract.expirationDate,
|
|
||||||
backExpirationDate: backOptionContract.expirationDate,
|
|
||||||
strike: frontOptionContract.strike,
|
|
||||||
type: frontOptionContract.type,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
getAggregates: async ({
|
|
||||||
key: { symbol, frontExpirationDate, backExpirationDate, strike, type },
|
|
||||||
date,
|
|
||||||
}) => {
|
|
||||||
const frontOptionContractAggregates =
|
|
||||||
await optionContractDatabase.getAggregates({
|
|
||||||
date,
|
|
||||||
key: { symbol, expirationDate: frontExpirationDate, strike, type },
|
|
||||||
});
|
|
||||||
const backOptionContractAggregates =
|
|
||||||
await optionContractDatabase.getAggregates({
|
|
||||||
date,
|
|
||||||
key: { symbol, expirationDate: backExpirationDate, strike, type },
|
|
||||||
});
|
|
||||||
const calendarAggregates = [];
|
|
||||||
let i = 0;
|
|
||||||
let j = 0;
|
|
||||||
while (
|
|
||||||
i < frontOptionContractAggregates.length &&
|
|
||||||
j < backOptionContractAggregates.length
|
|
||||||
) {
|
|
||||||
if (
|
|
||||||
frontOptionContractAggregates[i].tsStart ===
|
|
||||||
backOptionContractAggregates[j].tsStart
|
|
||||||
) {
|
|
||||||
calendarAggregates.push({
|
|
||||||
tsStart: frontOptionContractAggregates[i].tsStart,
|
|
||||||
open:
|
|
||||||
backOptionContractAggregates[j].open -
|
|
||||||
frontOptionContractAggregates[i].open,
|
|
||||||
close:
|
|
||||||
backOptionContractAggregates[j].close -
|
|
||||||
frontOptionContractAggregates[i].close,
|
|
||||||
// the high and low are not exactly correct since we don't know if each contract's high and low happened at the same moment as the other:
|
|
||||||
high:
|
|
||||||
backOptionContractAggregates[j].high -
|
|
||||||
frontOptionContractAggregates[i].high,
|
|
||||||
low:
|
|
||||||
backOptionContractAggregates[j].low -
|
|
||||||
frontOptionContractAggregates[i].low,
|
|
||||||
});
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
} else if (
|
|
||||||
frontOptionContractAggregates[i].tsStart >
|
|
||||||
backOptionContractAggregates[j].tsStart
|
|
||||||
) {
|
|
||||||
j++;
|
|
||||||
} else {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return calendarAggregates;
|
|
||||||
},
|
|
||||||
insertAggregates: async (aggregates) => {
|
|
||||||
// right now, no-op
|
|
||||||
},
|
|
||||||
getClosingPrice: async ({
|
|
||||||
key: { symbol, strike, type, frontExpirationDate, backExpirationDate },
|
|
||||||
}) => {
|
|
||||||
const startOfLastHourUnix = new Date(
|
|
||||||
`${frontExpirationDate}T00:00:00Z`,
|
|
||||||
).valueOf();
|
|
||||||
const endOfLastHourUnix = startOfLastHourUnix + 3600 * 1000;
|
|
||||||
const frontOptionContractAggregates = (
|
|
||||||
await optionContractDatabase.getAggregates({
|
|
||||||
date: frontExpirationDate,
|
|
||||||
key: { symbol, expirationDate: frontExpirationDate, strike, type },
|
|
||||||
})
|
|
||||||
).filter(
|
|
||||||
({ tsStart }) =>
|
|
||||||
tsStart >= startOfLastHourUnix && tsStart < endOfLastHourUnix,
|
|
||||||
);
|
|
||||||
const backOptionContractAggregates = (
|
|
||||||
await optionContractDatabase.getAggregates({
|
|
||||||
date: frontExpirationDate,
|
|
||||||
key: { symbol, expirationDate: backExpirationDate, strike, type },
|
|
||||||
})
|
|
||||||
).filter(
|
|
||||||
({ tsStart }) =>
|
|
||||||
tsStart >= startOfLastHourUnix && tsStart < endOfLastHourUnix,
|
|
||||||
);
|
|
||||||
let i = 0;
|
|
||||||
let j = 0;
|
|
||||||
let minPrice = 0;
|
|
||||||
while (
|
|
||||||
i < frontOptionContractAggregates.length &&
|
|
||||||
j < backOptionContractAggregates.length
|
|
||||||
) {
|
|
||||||
if (
|
|
||||||
frontOptionContractAggregates[i].tsStart ===
|
|
||||||
backOptionContractAggregates[j].tsStart
|
|
||||||
) {
|
|
||||||
const calendarClosePrice =
|
|
||||||
backOptionContractAggregates[j].close -
|
|
||||||
frontOptionContractAggregates[j].close;
|
|
||||||
if (calendarClosePrice < minPrice || minPrice === 0) {
|
|
||||||
minPrice = calendarClosePrice;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
} else if (
|
|
||||||
frontOptionContractAggregates[i].tsStart >
|
|
||||||
backOptionContractAggregates[j].tsStart
|
|
||||||
) {
|
|
||||||
j++;
|
|
||||||
} else {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return minPrice;
|
|
||||||
},
|
|
||||||
getTargetPriceByProbability: async ({
|
|
||||||
symbol,
|
|
||||||
calendarSpan,
|
|
||||||
strikePercentageFromTheMoney,
|
|
||||||
historicalProbabilityOfSuccess,
|
|
||||||
}) => {
|
|
||||||
return 0.24;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
...calendarDatabase,
|
|
||||||
getCalendars: calendarDatabase.getKeys,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const calendarDatabase: CalendarDatabase = makeCalendarDatabase();
|
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
import React, { useState, useEffect } from "react";
|
||||||
|
import { render, Box, Text, useInput, useApp } from "ink";
|
||||||
|
import TextInput from "ink-text-input";
|
||||||
|
import type { BacktestInput } from "./backtest.js";
|
||||||
|
import { backtest } from "./backtest.js";
|
||||||
|
|
||||||
|
const App = () => {
|
||||||
|
const [step, setStep] = useState(0);
|
||||||
|
const [input, setInput] = useState<Partial<BacktestInput>>({});
|
||||||
|
const [result, setResult] = useState<string>("");
|
||||||
|
const { exit } = useApp();
|
||||||
|
|
||||||
|
const steps = [
|
||||||
|
{ prompt: "Enter symbol:", key: "symbol" },
|
||||||
|
{ prompt: "Enter start date (YYYY-MM-DD):", key: "startDate" },
|
||||||
|
{ prompt: "Enter end date (YYYY-MM-DD):", key: "endDate" },
|
||||||
|
{
|
||||||
|
prompt: "Enter historical probability of success (0-1, default 0.8):",
|
||||||
|
key: "historicalProbabilityOfSuccess",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prompt: "Enter initial buying power (default 2000):",
|
||||||
|
key: "initialBuyingPower",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
useInput((input, key) => {
|
||||||
|
if (key.escape) {
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (step === steps.length) {
|
||||||
|
const runBacktest = async () => {
|
||||||
|
try {
|
||||||
|
const backtestResult = await backtest(input as BacktestInput);
|
||||||
|
setResult(JSON.stringify(backtestResult, null, 2));
|
||||||
|
} catch (error) {
|
||||||
|
setResult(`Error: ${error.message}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
runBacktest();
|
||||||
|
}
|
||||||
|
}, [step, input]);
|
||||||
|
|
||||||
|
const handleSubmit = (value: string) => {
|
||||||
|
const currentStep = steps[step];
|
||||||
|
let parsedValue: string | number = value;
|
||||||
|
|
||||||
|
if (
|
||||||
|
currentStep.key === "historicalProbabilityOfSuccess" ||
|
||||||
|
currentStep.key === "initialBuyingPower"
|
||||||
|
) {
|
||||||
|
parsedValue = Number.parseFloat(value) || undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
setInput({ ...input, [currentStep.key]: parsedValue });
|
||||||
|
setStep(step + 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (step < steps.length) {
|
||||||
|
return (
|
||||||
|
<Box flexDirection="column">
|
||||||
|
<Text>{steps[step].prompt}</Text>
|
||||||
|
<TextInput
|
||||||
|
value={(input[steps[step].key] as string) || ""}
|
||||||
|
onChange={(value) =>
|
||||||
|
setInput((prev) => ({ ...prev, [steps[step].key]: value }))
|
||||||
|
}
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box flexDirection="column">
|
||||||
|
<Text>Backtest Results:</Text>
|
||||||
|
<Text>{result}</Text>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
render(<App />);
|
||||||
+76
-305
@@ -1,311 +1,82 @@
|
|||||||
import { publicProcedure, router } from "./trpc.js";
|
import { publicProcedure, router, RpcType } from "./trpc.js";
|
||||||
import { query } from "./lib/clickhouse.js";
|
import { query } from "./lib/clickhouse.js";
|
||||||
import { createHTTPHandler } from "@trpc/server/adapters/standalone";
|
import { createHTTPHandler } from "@trpc/server/adapters/standalone";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import {
|
import {
|
||||||
Object as ObjectT,
|
Object as ObjectT,
|
||||||
String as StringT,
|
String as StringT,
|
||||||
type TSchema,
|
Number as NumberT,
|
||||||
Number as NumberT,
|
|
||||||
} from "@sinclair/typebox";
|
} from "@sinclair/typebox";
|
||||||
import { TypeCompiler } from "@sinclair/typebox/compiler";
|
|
||||||
import { TRPCError } from "@trpc/server";
|
|
||||||
import { createServer } from "node:http";
|
import { createServer } from "node:http";
|
||||||
import { Env } from "@humanwhocodes/env";
|
import { Env } from "@humanwhocodes/env";
|
||||||
|
import StockPriceChart from "./StockPriceChart.js";
|
||||||
|
import SimilarCalendarPriceChart from "./SimilarCalendarPriceChart.js";
|
||||||
|
import CalendarExitPriceChart from "./CalendarExitPriceChart.js";
|
||||||
|
import CalendarCharacteristicsForm from "./CalendarCharacteristicsForm.js";
|
||||||
|
|
||||||
const env = new Env();
|
const env = new Env();
|
||||||
|
|
||||||
const LISTEN_PORT = env.get("LISTEN_PORT", 3005);
|
const LISTEN_PORT = env.get("LISTEN_PORT", 3005);
|
||||||
|
|
||||||
/**
|
export const getOpensForUnderlying = publicProcedure
|
||||||
* Generate a TRPC-compatible validator function given a Typebox schema.
|
.input(
|
||||||
* This was copied from [https://github.com/sinclairzx81/typebox/blob/6cfcdc02cc813af2f1be57407c771fc4fadfc34a/example/trpc/readme.md].
|
RpcType(
|
||||||
* @param schema A Typebox schema
|
ObjectT({
|
||||||
* @returns A TRPC-compatible validator function
|
underlying: StringT({ maxLength: 5 }),
|
||||||
*/
|
})
|
||||||
export function RpcType<T extends TSchema>(schema: T) {
|
)
|
||||||
const check = TypeCompiler.Compile(schema);
|
)
|
||||||
return (value: unknown) => {
|
.query(async (opts) => {
|
||||||
if (check.Check(value)) return value;
|
const { underlying } = opts.input;
|
||||||
const { path, message } = check.Errors(value).First();
|
return await query<{ x: number; y: number }>(
|
||||||
throw new TRPCError({
|
`
|
||||||
message: `${message} for ${path}`,
|
SELECT
|
||||||
code: "BAD_REQUEST",
|
toUnixTimestamp(tsStart) as x,
|
||||||
});
|
open as y
|
||||||
};
|
FROM stock_aggregates
|
||||||
}
|
WHERE symbol = '${underlying}'
|
||||||
|
ORDER BY tsStart ASC
|
||||||
|
`,
|
||||||
|
"JSONEachRow"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export const getOpensForOptionContract = publicProcedure
|
||||||
|
.input(
|
||||||
|
RpcType(
|
||||||
|
ObjectT({
|
||||||
|
underlying: StringT({ maxLength: 5 }),
|
||||||
|
expirationDate: StringT(),
|
||||||
|
strike: NumberT(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.query(async (opts) => {
|
||||||
|
const { underlying, expirationDate, strike } = opts.input;
|
||||||
|
return await query<{ x: number; y: number }>(
|
||||||
|
`
|
||||||
|
SELECT
|
||||||
|
toUnixTimestamp(tsStart) as x,
|
||||||
|
open as y
|
||||||
|
FROM option_contract_aggregates
|
||||||
|
WHERE symbol = '${underlying}'
|
||||||
|
AND expirationDate = '${expirationDate}'
|
||||||
|
AND strike = ${strike}
|
||||||
|
AND type = 'call'
|
||||||
|
ORDER BY tsStart ASC
|
||||||
|
`,
|
||||||
|
"JSONEachRow"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
const appRouter = router({
|
const appRouter = router({
|
||||||
getAvailableUnderlyings: publicProcedure.query(async (opts) => {
|
CalendarCharacteristicsForm,
|
||||||
// return (
|
StockPriceChart,
|
||||||
// await query<{ symbol: string }>(`
|
SimilarCalendarPriceChart,
|
||||||
// SELECT DISTINCT(symbol) as symbol FROM option_contract_existences WHERE asOfDate = (SELECT max(asOfDate) FROM option_contract_existences)
|
CalendarExitPriceChart,
|
||||||
// `)
|
|
||||||
// ).map(({ symbol }) => symbol);
|
getOpensForUnderlying,
|
||||||
return ["AAPL", "AMD", "GOOGL", "MSFT", "NFLX"];
|
getOpensForOptionContract,
|
||||||
}),
|
|
||||||
getAvailableAsOfDates: publicProcedure
|
|
||||||
.input(RpcType(ObjectT({ underlying: StringT() })))
|
|
||||||
.query(async (opts) => {
|
|
||||||
const underlying = opts.input.underlying;
|
|
||||||
return (
|
|
||||||
await query<{ asOfDate: string }>(`
|
|
||||||
SELECT
|
|
||||||
DISTINCT(asOfDate) as asOfDate
|
|
||||||
FROM option_contract_existences
|
|
||||||
WHERE symbol = '${underlying}'
|
|
||||||
ORDER BY asOfDate
|
|
||||||
`)
|
|
||||||
).map(({ asOfDate }) => asOfDate);
|
|
||||||
}),
|
|
||||||
getExpirationsForUnderlying: publicProcedure
|
|
||||||
.input(
|
|
||||||
RpcType(
|
|
||||||
ObjectT({
|
|
||||||
underlying: StringT({ maxLength: 5 }),
|
|
||||||
asOfDate: StringT(),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.query(async (opts) => {
|
|
||||||
const { underlying, asOfDate } = opts.input;
|
|
||||||
return (
|
|
||||||
await query<{ expirationDate: string }>(`
|
|
||||||
SELECT
|
|
||||||
DISTINCT(expirationDate) as expirationDate
|
|
||||||
FROM option_contract_existences
|
|
||||||
WHERE symbol = '${underlying}'
|
|
||||||
AND asOfDate = '${asOfDate}'
|
|
||||||
ORDER BY expirationDate
|
|
||||||
`)
|
|
||||||
).map(({ expirationDate }) => expirationDate);
|
|
||||||
}),
|
|
||||||
getStrikesForUnderlying: publicProcedure
|
|
||||||
.input(
|
|
||||||
RpcType(
|
|
||||||
ObjectT({
|
|
||||||
underlying: StringT({ maxLength: 5 }),
|
|
||||||
asOfDate: StringT(),
|
|
||||||
expirationDate: StringT(),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.query(async (opts) => {
|
|
||||||
const { underlying, asOfDate, expirationDate } = opts.input;
|
|
||||||
return (
|
|
||||||
await query<{ strike: string }>(`
|
|
||||||
SELECT
|
|
||||||
DISTINCT(strike) as strike
|
|
||||||
FROM option_contract_existences
|
|
||||||
WHERE symbol = '${underlying}'
|
|
||||||
AND asOfDate = '${asOfDate}'
|
|
||||||
AND expirationDate = '${expirationDate}'
|
|
||||||
ORDER BY strike
|
|
||||||
`)
|
|
||||||
).map(({ strike }) => strike);
|
|
||||||
}),
|
|
||||||
getOpensForUnderlying: publicProcedure
|
|
||||||
.input(
|
|
||||||
RpcType(
|
|
||||||
ObjectT({
|
|
||||||
underlying: StringT({ maxLength: 5 }),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.query(async (opts) => {
|
|
||||||
const { underlying } = opts.input;
|
|
||||||
return await query<{ x: number; y: number }>(
|
|
||||||
`
|
|
||||||
SELECT
|
|
||||||
toUnixTimestamp(tsStart) as x,
|
|
||||||
open as y
|
|
||||||
FROM stock_aggregates
|
|
||||||
WHERE symbol = '${underlying}'
|
|
||||||
ORDER BY tsStart ASC
|
|
||||||
`,
|
|
||||||
"JSONEachRow",
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
getOpensForOptionContract: publicProcedure
|
|
||||||
.input(
|
|
||||||
RpcType(
|
|
||||||
ObjectT({
|
|
||||||
underlying: StringT({ maxLength: 5 }),
|
|
||||||
expirationDate: StringT(),
|
|
||||||
strike: NumberT(),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.query(async (opts) => {
|
|
||||||
const { underlying, expirationDate, strike } = opts.input;
|
|
||||||
return await query<{ x: number; y: number }>(
|
|
||||||
`
|
|
||||||
SELECT
|
|
||||||
toUnixTimestamp(tsStart) as x,
|
|
||||||
open as y
|
|
||||||
FROM option_contract_aggregates
|
|
||||||
WHERE symbol = '${underlying}'
|
|
||||||
AND expirationDate = '${expirationDate}'
|
|
||||||
AND strike = ${strike}
|
|
||||||
AND type = 'call'
|
|
||||||
ORDER BY tsStart ASC
|
|
||||||
`,
|
|
||||||
"JSONEachRow",
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
getHistoricalCalendarPrices: publicProcedure
|
|
||||||
.input(
|
|
||||||
RpcType(
|
|
||||||
ObjectT({
|
|
||||||
underlying: StringT({ maxLength: 5 }),
|
|
||||||
daysToFrontExpiration: NumberT(),
|
|
||||||
daysBetweenFrontAndBackExpiration: NumberT(),
|
|
||||||
strikePercentageFromUnderlyingPriceRangeMin: NumberT(),
|
|
||||||
strikePercentageFromUnderlyingPriceRangeMax: NumberT(),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.query(async (opts) => {
|
|
||||||
const {
|
|
||||||
underlying,
|
|
||||||
daysToFrontExpiration,
|
|
||||||
daysBetweenFrontAndBackExpiration,
|
|
||||||
strikePercentageFromUnderlyingPriceRangeMin,
|
|
||||||
strikePercentageFromUnderlyingPriceRangeMax,
|
|
||||||
} = opts.input;
|
|
||||||
return (
|
|
||||||
await query<[number, number]>(
|
|
||||||
`
|
|
||||||
SELECT
|
|
||||||
toUnixTimestamp(tsStart) as asOfTs,
|
|
||||||
calendarPrice
|
|
||||||
FROM calendar_histories
|
|
||||||
WHERE symbol = '${underlying}'
|
|
||||||
AND daysToFrontExpiration = ${daysToFrontExpiration}
|
|
||||||
AND strikePercentageFromUnderlyingPrice >= ${strikePercentageFromUnderlyingPriceRangeMin}
|
|
||||||
AND strikePercentageFromUnderlyingPrice <= ${strikePercentageFromUnderlyingPriceRangeMax}
|
|
||||||
AND daysBetweenFrontAndBackExpiration = ${daysBetweenFrontAndBackExpiration}
|
|
||||||
`,
|
|
||||||
"JSONCompactEachRow",
|
|
||||||
)
|
|
||||||
).reduce(
|
|
||||||
(columns, row) => {
|
|
||||||
columns[0].push(row[0]);
|
|
||||||
columns[1].push(row[1]);
|
|
||||||
return columns;
|
|
||||||
},
|
|
||||||
[[], []],
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
getHistoricalStockQuoteChartData: publicProcedure
|
|
||||||
.input(
|
|
||||||
RpcType(
|
|
||||||
ObjectT({
|
|
||||||
underlying: StringT({ maxLength: 5 }),
|
|
||||||
lookbackPeriodStart: StringT(),
|
|
||||||
lookbackPeriodEnd: StringT(),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.query(async (opts) => {
|
|
||||||
const { underlying, lookbackPeriodStart, lookbackPeriodEnd } = opts.input;
|
|
||||||
return await query<[number, number]>(
|
|
||||||
`
|
|
||||||
SELECT
|
|
||||||
toUnixTimestamp(tsStart) as x,
|
|
||||||
open as y
|
|
||||||
FROM stock_aggregates
|
|
||||||
WHERE symbol = '${underlying}'
|
|
||||||
AND tsStart >= '${lookbackPeriodStart} 00:00:00'
|
|
||||||
AND tsStart <= '${lookbackPeriodEnd} 00:00:00'
|
|
||||||
ORDER BY x ASC
|
|
||||||
`,
|
|
||||||
"JSONEachRow",
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
getHistoricalCalendarQuoteChartData: publicProcedure
|
|
||||||
.input(
|
|
||||||
RpcType(
|
|
||||||
ObjectT({
|
|
||||||
underlying: StringT({ maxLength: 5 }),
|
|
||||||
daysToFrontExpiration: NumberT(),
|
|
||||||
daysBetweenFrontAndBackExpiration: NumberT(),
|
|
||||||
strikePercentageFromUnderlyingPriceRangeMin: NumberT(),
|
|
||||||
strikePercentageFromUnderlyingPriceRangeMax: NumberT(),
|
|
||||||
lookbackPeriodStart: StringT(),
|
|
||||||
lookbackPeriodEnd: StringT(),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.query(async (opts) => {
|
|
||||||
const {
|
|
||||||
underlying,
|
|
||||||
daysToFrontExpiration,
|
|
||||||
daysBetweenFrontAndBackExpiration,
|
|
||||||
strikePercentageFromUnderlyingPriceRangeMin,
|
|
||||||
strikePercentageFromUnderlyingPriceRangeMax,
|
|
||||||
lookbackPeriodStart,
|
|
||||||
lookbackPeriodEnd,
|
|
||||||
} = opts.input;
|
|
||||||
return await query<[number, number]>(
|
|
||||||
`
|
|
||||||
SELECT
|
|
||||||
toUnixTimestamp(tsStart) as x,
|
|
||||||
truncate(calendarPrice, 2) as y
|
|
||||||
FROM calendar_histories
|
|
||||||
WHERE symbol = '${underlying}'
|
|
||||||
AND daysToFrontExpiration = ${daysToFrontExpiration}
|
|
||||||
AND strikePercentageFromUnderlyingPrice >= ${strikePercentageFromUnderlyingPriceRangeMin}
|
|
||||||
AND strikePercentageFromUnderlyingPrice <= ${strikePercentageFromUnderlyingPriceRangeMax}
|
|
||||||
AND daysBetweenFrontAndBackExpiration = ${daysBetweenFrontAndBackExpiration}
|
|
||||||
AND tsStart >= '${lookbackPeriodStart} 00:00:00'
|
|
||||||
AND tsStart <= '${lookbackPeriodEnd} 00:00:00'
|
|
||||||
`,
|
|
||||||
"JSONEachRow",
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
getHistoricalCalendarExitQuoteChartData: publicProcedure
|
|
||||||
.input(
|
|
||||||
RpcType(
|
|
||||||
ObjectT({
|
|
||||||
underlying: StringT({ maxLength: 5 }),
|
|
||||||
daysToFrontExpiration: NumberT(),
|
|
||||||
daysBetweenFrontAndBackExpiration: NumberT(),
|
|
||||||
lookbackPeriodStart: StringT({
|
|
||||||
pattern: "[0-9]{4}-[0-9]{2}-[0-9]{2}",
|
|
||||||
}),
|
|
||||||
lookbackPeriodEnd: StringT({ pattern: "[0-9]{4}-[0-9]{2}-[0-9]{2}" }),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.query(async (opts) => {
|
|
||||||
const {
|
|
||||||
underlying,
|
|
||||||
daysToFrontExpiration,
|
|
||||||
daysBetweenFrontAndBackExpiration,
|
|
||||||
lookbackPeriodStart,
|
|
||||||
lookbackPeriodEnd,
|
|
||||||
} = opts.input;
|
|
||||||
return await query<[number, number, number]>(
|
|
||||||
`
|
|
||||||
SELECT
|
|
||||||
FLOOR(strikePercentageFromUnderlyingPrice, 1) as x,
|
|
||||||
FLOOR(calendarPrice, 1) as y,
|
|
||||||
count(*) as n
|
|
||||||
FROM calendar_histories
|
|
||||||
WHERE symbol = '${underlying}'
|
|
||||||
AND daysToFrontExpiration = ${daysToFrontExpiration}
|
|
||||||
AND strikePercentageFromUnderlyingPrice >= -5.0
|
|
||||||
AND strikePercentageFromUnderlyingPrice <= 5.0
|
|
||||||
AND daysBetweenFrontAndBackExpiration = ${daysBetweenFrontAndBackExpiration}
|
|
||||||
AND tsStart >= '${lookbackPeriodStart} 00:00:00'
|
|
||||||
AND tsStart <= '${lookbackPeriodEnd} 00:00:00'
|
|
||||||
GROUP BY x, y
|
|
||||||
ORDER BY x ASC, y ASC
|
|
||||||
`,
|
|
||||||
"JSONEachRow",
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Export type router type signature,
|
// Export type router type signature,
|
||||||
@@ -313,20 +84,20 @@ const appRouter = router({
|
|||||||
export type AppRouter = typeof appRouter;
|
export type AppRouter = typeof appRouter;
|
||||||
|
|
||||||
const handler = createHTTPHandler({
|
const handler = createHTTPHandler({
|
||||||
middleware: cors(),
|
middleware: cors(),
|
||||||
router: appRouter,
|
router: appRouter,
|
||||||
createContext() {
|
createContext() {
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const server = createServer((req, res) => {
|
const server = createServer((req, res) => {
|
||||||
if (req.url.startsWith("/healthz")) {
|
if (req.url.startsWith("/healthz")) {
|
||||||
res.statusCode = 200;
|
res.statusCode = 200;
|
||||||
res.end("OK");
|
res.end("OK");
|
||||||
} else {
|
} else {
|
||||||
handler(req, res);
|
handler(req, res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(Number.parseInt(LISTEN_PORT));
|
server.listen(Number.parseInt(LISTEN_PORT));
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
export type Candlestick = {
|
|
||||||
open: number;
|
|
||||||
close: number;
|
|
||||||
high: number;
|
|
||||||
low: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Aggregate<T> = {
|
|
||||||
key: T;
|
|
||||||
/** UNIX time in milliseconds */
|
|
||||||
tsStart: number;
|
|
||||||
} & Candlestick;
|
|
||||||
|
|
||||||
export type AggregateDatabase<T> = {
|
|
||||||
getKeys: ({
|
|
||||||
key,
|
|
||||||
date,
|
|
||||||
}: { key?: T | Partial<T>; date?: string }) => Promise<Array<T>>;
|
|
||||||
getAggregates: ({
|
|
||||||
key,
|
|
||||||
date,
|
|
||||||
}: { key: T; date: string }) => Promise<Array<Omit<Aggregate<T>, "key">>>;
|
|
||||||
insertAggregates: (aggregates: Array<Aggregate<T>>) => Promise<void>;
|
|
||||||
getClosingPrice: ({ key }: { key: T }) => Promise<number>;
|
|
||||||
};
|
|
||||||
@@ -1,31 +1,38 @@
|
|||||||
import { createClient as createClickhouseClient } from "@clickhouse/client";
|
import { createClient as createClickhouseClient } from "@clickhouse/client";
|
||||||
import type { DataFormat } from "@clickhouse/client";
|
import type { DataFormat } from "@clickhouse/client";
|
||||||
import { Env } from "@humanwhocodes/env";
|
import { Env } from "@humanwhocodes/env";
|
||||||
|
import { retry } from "./utils/retry.js";
|
||||||
|
|
||||||
const env = new Env();
|
const env = new Env();
|
||||||
|
|
||||||
const { CLICKHOUSE_USER, CLICKHOUSE_PASS } = env.required;
|
const { CLICKHOUSE_USER, CLICKHOUSE_PASS } = env.required;
|
||||||
const CLICKHOUSE_HOST = env.get("CLICKHOUSE_HOST", "http://localhost:8123");
|
const CLICKHOUSE_URL = env.get("CLICKHOUSE_URL", "http://localhost:8123");
|
||||||
|
|
||||||
export const clickhouse = createClickhouseClient({
|
export const clickhouse = createClickhouseClient({
|
||||||
host: CLICKHOUSE_HOST,
|
url: CLICKHOUSE_URL,
|
||||||
username: CLICKHOUSE_USER,
|
username: CLICKHOUSE_USER,
|
||||||
password: CLICKHOUSE_PASS,
|
password: CLICKHOUSE_PASS,
|
||||||
|
keep_alive: {
|
||||||
|
enabled: true,
|
||||||
|
// socket_ttl: 2500,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function query<T>(
|
export async function query<T>(
|
||||||
queryString: string,
|
queryString: string,
|
||||||
format: DataFormat = "JSONEachRow"
|
format: DataFormat = "JSONEachRow"
|
||||||
): Promise<Array<T>> {
|
): Promise<Array<T>> {
|
||||||
return await (
|
return await retry(
|
||||||
await clickhouse.query({
|
async () => {
|
||||||
query: queryString,
|
const result = await clickhouse.query({
|
||||||
format,
|
query: queryString,
|
||||||
clickhouse_settings: {
|
format,
|
||||||
output_format_json_quote_64bit_integers: 0,
|
clickhouse_settings: {
|
||||||
//output_format_json_quote_64bit_floats: false,
|
output_format_json_quote_64bit_integers: 0,
|
||||||
//output_format_json_quote_64bit_decimals: false,
|
},
|
||||||
},
|
});
|
||||||
})
|
return await result.json();
|
||||||
).json();
|
},
|
||||||
|
{ maxRetries: 5 }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
type RetryDecision = {
|
||||||
|
shouldRetry: boolean;
|
||||||
|
maxRetries?: number;
|
||||||
|
delay?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type RetryOptions = {
|
||||||
|
maxRetries?: number;
|
||||||
|
delay?: number;
|
||||||
|
shouldRetry?: (error: unknown) => RetryDecision;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function retry<T>(
|
||||||
|
fn: () => Promise<T>,
|
||||||
|
options: RetryOptions = {},
|
||||||
|
): Promise<T> {
|
||||||
|
const {
|
||||||
|
maxRetries: defaultMaxRetries = 3,
|
||||||
|
delay: defaultDelay = 1000,
|
||||||
|
shouldRetry = retryOnAnyError,
|
||||||
|
} = options;
|
||||||
|
|
||||||
|
let attempt = 1;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
return await fn();
|
||||||
|
} catch (error) {
|
||||||
|
const decision = shouldRetry(error);
|
||||||
|
if (!decision.shouldRetry) throw error;
|
||||||
|
|
||||||
|
const currentMaxRetries = decision.maxRetries ?? defaultMaxRetries;
|
||||||
|
const currentDelay = decision.delay ?? defaultDelay;
|
||||||
|
|
||||||
|
if (attempt >= currentMaxRetries) throw error;
|
||||||
|
|
||||||
|
console.warn(
|
||||||
|
`Error occurred, retrying (attempt ${attempt}/${currentMaxRetries})...`,
|
||||||
|
);
|
||||||
|
console.error(error);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, currentDelay));
|
||||||
|
attempt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const retryOnAnyError = (): RetryDecision => ({ shouldRetry: true });
|
||||||
|
export const retryOnTimeout = (error: unknown): RetryDecision =>
|
||||||
|
error instanceof Error && error.message.includes("timeout")
|
||||||
|
? { shouldRetry: true, maxRetries: 5, delay: 2000 }
|
||||||
|
: { shouldRetry: false };
|
||||||
|
export const retryOnErrorType =
|
||||||
|
(errorType: new () => Error, options?: Partial<RetryDecision>) =>
|
||||||
|
(error: unknown) =>
|
||||||
|
error instanceof errorType
|
||||||
|
? { shouldRetry: true, ...options }
|
||||||
|
: { shouldRetry: false };
|
||||||
|
export const retryOnErrorSubstring =
|
||||||
|
(substring: string, options?: Partial<RetryDecision>) => (error: unknown) =>
|
||||||
|
error instanceof Error && error.message.includes(substring)
|
||||||
|
? { shouldRetry: true, ...options }
|
||||||
|
: { shouldRetry: false };
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
import type { AggregateDatabase } from "../interfaces.js";
|
import type { AggregateDatabase } from "../AggregateDatabase/interfaces.js";
|
||||||
// import { stockDatabase as stockDatabaseClickhouse } from "../stockdb.clickhouse.js";
|
import { database as stockDatabaseClickhouse } from "../AggregateDatabase/Stock/clickhouse.js";
|
||||||
// import { stockDatabase as stockDatabaseLmdbx } from "../stockdb.lmdbx.js";
|
import { database as stockDatabaseLmdbx } from "../AggregateDatabase/Stock/lmdbx.js";
|
||||||
import { optionContractDatabase as optionContractDatabaseClickhouse } from "../optiondb.clickhouse.js";
|
// import { optionContractDatabase as optionContractDatabaseClickhouse } from "../optiondb.clickhouse.js";
|
||||||
import { optionContractDatabase as optionContractDatabaseLmdbx } from "../optiondb.lmdbx.js";
|
// import { optionContractDatabase as optionContractDatabaseLmdbx } from "../optiondb.lmdbx.js";
|
||||||
import { nextDate } from "../lib/util.js";
|
import { nextDate } from "../lib/utils/nextDate.js";
|
||||||
|
import { retry, retryOnTimeout } from "../lib/utils/retry.js";
|
||||||
|
import type { OptionContractKey } from "../AggregateDatabase/OptionContract/interfaces.js";
|
||||||
|
import type { StockKey } from "../AggregateDatabase/Stock/interfaces.js";
|
||||||
|
|
||||||
async function syncAggregates<T>({
|
async function syncAggregates<T>({
|
||||||
fromDatabase,
|
fromDatabase,
|
||||||
@@ -23,7 +26,13 @@ async function syncAggregates<T>({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const symbols = ["AMD", "AAPL", "MSFT", "GOOGL", "NFLX", "NVDA"];
|
const symbols = ["AMD", "AAPL", "MSFT", "GOOGL", "NFLX", "NVDA"];
|
||||||
async function run() {
|
async function run<T extends StockKey | OptionContractKey>({
|
||||||
|
fromDatabase,
|
||||||
|
toDatabase,
|
||||||
|
}: {
|
||||||
|
fromDatabase: AggregateDatabase<T>;
|
||||||
|
toDatabase: AggregateDatabase<T>;
|
||||||
|
}) {
|
||||||
const startDate = process.argv[2];
|
const startDate = process.argv[2];
|
||||||
const endDate = process.argv[3];
|
const endDate = process.argv[3];
|
||||||
|
|
||||||
@@ -36,21 +45,33 @@ async function run() {
|
|||||||
// const symbols = await stockDatabaseClickhouse.getSymbols({ date });
|
// const symbols = await stockDatabaseClickhouse.getSymbols({ date });
|
||||||
for (const symbol of symbols) {
|
for (const symbol of symbols) {
|
||||||
console.log(date, symbol);
|
console.log(date, symbol);
|
||||||
const keys = await optionContractDatabaseClickhouse.getKeys({
|
const keys = await retry(
|
||||||
key: { symbol },
|
() =>
|
||||||
date,
|
fromDatabase.getKeys({
|
||||||
});
|
key: { symbol } as T,
|
||||||
|
date,
|
||||||
|
}),
|
||||||
|
{ shouldRetry: retryOnTimeout }
|
||||||
|
);
|
||||||
|
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
// console.log(date, symbol, key.expirationDate, key.strike, key.type);
|
// console.log(date, symbol, key.expirationDate, key.strike, key.type);
|
||||||
await syncAggregates({
|
await retry(
|
||||||
fromDatabase: optionContractDatabaseClickhouse,
|
() =>
|
||||||
toDatabase: optionContractDatabaseLmdbx,
|
syncAggregates({
|
||||||
key,
|
fromDatabase,
|
||||||
date,
|
toDatabase,
|
||||||
});
|
key,
|
||||||
|
date,
|
||||||
|
}),
|
||||||
|
{ shouldRetry: retryOnTimeout }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await run();
|
await run({
|
||||||
|
fromDatabase: stockDatabaseClickhouse,
|
||||||
|
toDatabase: stockDatabaseLmdbx,
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
import type { StockDatabase, StockKey } from "./stockdb.interfaces.js";
|
|
||||||
import type { Aggregate } from "./interfaces.js";
|
|
||||||
import { clickhouse, query } from "./lib/clickhouse.js";
|
|
||||||
|
|
||||||
function makeStockDatabase(): StockDatabase {
|
|
||||||
const stockDatabase: Omit<StockDatabase, "getSymbols"> = {
|
|
||||||
getKeys: async ({ date }) => {
|
|
||||||
return (
|
|
||||||
await query(`
|
|
||||||
SELECT DISTINCT symbol FROM stock_aggregates WHERE toDate(tsStart) = '${date}'
|
|
||||||
`)
|
|
||||||
).map(({ symbol }) => symbol);
|
|
||||||
},
|
|
||||||
getAggregates: async ({ key: symbol, date }) => {
|
|
||||||
return (
|
|
||||||
await query<Omit<Aggregate<StockKey>, "key">>(`
|
|
||||||
SELECT
|
|
||||||
toUnixTimestamp(tsStart) as tsStart,
|
|
||||||
open,
|
|
||||||
close,
|
|
||||||
high,
|
|
||||||
low
|
|
||||||
FROM stock_aggregates
|
|
||||||
WHERE symbol = '${symbol}'
|
|
||||||
AND toDate(tsStart) = '${date}'
|
|
||||||
ORDER BY tsStart ASC
|
|
||||||
`)
|
|
||||||
).map((aggregate) => ({
|
|
||||||
...aggregate,
|
|
||||||
tsStart: aggregate.tsStart * 1000, // unfortunately, `toUnixTimestamp` only returns second-precision
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
insertAggregates: async (aggregates) => {
|
|
||||||
// stock existence is taken care of by clickhouse materialized view
|
|
||||||
await clickhouse.insert({
|
|
||||||
table: "stock_aggregates",
|
|
||||||
values: aggregates.map(({ key, tsStart, open, close, high, low }) => ({
|
|
||||||
symbol: key,
|
|
||||||
tsStart,
|
|
||||||
open,
|
|
||||||
close,
|
|
||||||
high,
|
|
||||||
low,
|
|
||||||
})),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
getClosingPrice: async ({ key }) => {
|
|
||||||
// no-op: not used since stocks don't have a "closing" price, unlike options.
|
|
||||||
return 0;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
...stockDatabase,
|
|
||||||
getSymbols: stockDatabase.getKeys,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const stockDatabase: StockDatabase = makeStockDatabase();
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import type { AggregateDatabase } from "./interfaces.js";
|
|
||||||
|
|
||||||
export type StockKey = string;
|
|
||||||
|
|
||||||
export type StockDatabase = AggregateDatabase<StockKey> & {
|
|
||||||
getSymbols: AggregateDatabase<StockKey>["getKeys"];
|
|
||||||
};
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
import type { StockDatabase } from "./stockdb.interfaces.js";
|
|
||||||
import { open } from "lmdbx";
|
|
||||||
|
|
||||||
const stockAggregatesDb = open({
|
|
||||||
path: "/tmp/stock-aggregates.db",
|
|
||||||
// any options go here, we can turn on compression like this:
|
|
||||||
compression: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const stockExistenceDb = open({
|
|
||||||
path: "/tmp/stock-existence.db",
|
|
||||||
// any options go here, we can turn on compression like this:
|
|
||||||
compression: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
/** Largest possible key according to the `ordered-binary` (used by lmdbx) docs. */
|
|
||||||
const MAXIMUM_KEY = Buffer.from([0xff]);
|
|
||||||
|
|
||||||
function makeStockDatabase(): StockDatabase {
|
|
||||||
const stockDatabase: Omit<StockDatabase, "getSymbols"> = {
|
|
||||||
getKeys: async ({ date }) => {
|
|
||||||
return stockExistenceDb
|
|
||||||
.getRange({
|
|
||||||
start: [date],
|
|
||||||
end: [date, MAXIMUM_KEY],
|
|
||||||
})
|
|
||||||
.map(({ key }) => key[1]).asArray;
|
|
||||||
},
|
|
||||||
getAggregates: async ({ key: symbol, date }) => {
|
|
||||||
const startOfDayUnix = new Date(`${date}T00:00:00Z`).valueOf();
|
|
||||||
const endOfDayUnix = startOfDayUnix + 3600 * 24 * 1000;
|
|
||||||
return stockAggregatesDb
|
|
||||||
.getRange({
|
|
||||||
start: [symbol, startOfDayUnix],
|
|
||||||
end: [symbol, endOfDayUnix],
|
|
||||||
})
|
|
||||||
.map(({ key, value }) => ({
|
|
||||||
tsStart: key[1],
|
|
||||||
open: value.open,
|
|
||||||
close: value.close,
|
|
||||||
high: value.high,
|
|
||||||
low: value.low,
|
|
||||||
})).asArray;
|
|
||||||
},
|
|
||||||
insertAggregates: async (aggregates) => {
|
|
||||||
await stockExistenceDb.batch(() => {
|
|
||||||
for (const aggregate of aggregates) {
|
|
||||||
stockExistenceDb.put(
|
|
||||||
[
|
|
||||||
new Date(aggregate.tsStart).toISOString().substring(0, 10),
|
|
||||||
aggregate.key,
|
|
||||||
],
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
await stockAggregatesDb.batch(() => {
|
|
||||||
for (const aggregate of aggregates) {
|
|
||||||
stockAggregatesDb.put([aggregate.key, aggregate.tsStart], {
|
|
||||||
open: aggregate.open,
|
|
||||||
close: aggregate.close,
|
|
||||||
high: aggregate.high,
|
|
||||||
low: aggregate.low,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
getClosingPrice: async ({ key }) => {
|
|
||||||
// no-op: not used since stocks don't have a "closing" price, unlike options.
|
|
||||||
return 0;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
...stockDatabase,
|
|
||||||
getSymbols: stockDatabase.getKeys,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const stockDatabase: StockDatabase = makeStockDatabase();
|
|
||||||
+25
-4
@@ -1,14 +1,35 @@
|
|||||||
import { initTRPC } from '@trpc/server';
|
import { initTRPC } from "@trpc/server";
|
||||||
|
import { TypeCompiler } from "@sinclair/typebox/compiler";
|
||||||
|
import { TRPCError } from "@trpc/server";
|
||||||
|
import type { TSchema } from "@sinclair/typebox";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialization of tRPC backend
|
* Initialization of tRPC backend
|
||||||
* Should be done only once per backend!
|
* Should be done only once per backend!
|
||||||
*/
|
*/
|
||||||
const t = initTRPC.create();
|
const t = initTRPC.create();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export reusable router and procedure helpers
|
* Export reusable router and procedure helpers
|
||||||
* that can be used throughout the router
|
* that can be used throughout the router
|
||||||
*/
|
*/
|
||||||
export const router = t.router;
|
export const router = t.router;
|
||||||
export const publicProcedure = t.procedure;
|
export const publicProcedure = t.procedure;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a TRPC-compatible validator function given a Typebox schema.
|
||||||
|
* This was copied from [https://github.com/sinclairzx81/typebox/blob/6cfcdc02cc813af2f1be57407c771fc4fadfc34a/example/trpc/readme.md].
|
||||||
|
* @param schema A Typebox schema
|
||||||
|
* @returns A TRPC-compatible validator function
|
||||||
|
*/
|
||||||
|
export function RpcType<T extends TSchema>(schema: T) {
|
||||||
|
const check = TypeCompiler.Compile(schema);
|
||||||
|
return (value: unknown) => {
|
||||||
|
if (check.Check(value)) return value;
|
||||||
|
const { path, message } = check.Errors(value).First();
|
||||||
|
throw new TRPCError({
|
||||||
|
message: `${message} for ${path}`,
|
||||||
|
code: "BAD_REQUEST",
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
+11
-10
@@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2020",
|
"jsx": "react",
|
||||||
"module": "ESNext",
|
"target": "ES2020",
|
||||||
"moduleResolution": "bundler",
|
"module": "ESNext",
|
||||||
"noEmit": true,
|
"moduleResolution": "bundler",
|
||||||
"allowJs": true,
|
"noEmit": true,
|
||||||
"checkJs": true,
|
"allowJs": true,
|
||||||
"lib": ["es2022"]
|
"checkJs": false,
|
||||||
},
|
"lib": ["es2022"]
|
||||||
"include": ["**/*"]
|
},
|
||||||
|
"include": ["src/**/*"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user