-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
416 additions
and
90 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { HistoricalSeason } from '@/components/HistoricalSeason'; | ||
import { TickerSearchNavigation } from '@/components/TickerSearchNavigation'; | ||
import { getSeasonalView } from '@/lib/tradierService'; | ||
|
||
export default async function Page({ params }: { params: { symbol: string } }) { | ||
const { symbol } = params; | ||
const dt = await getSeasonalView(symbol, '5y', 'monthly'); | ||
return <> | ||
{/* not working due to clientside and serverside battle.. let's look at it later */} | ||
{/* <TickerSearchNavigation basePath='/seasonal' /> */} | ||
<HistoricalSeason data={dt} /> | ||
</> | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use client'; | ||
import { TickerSearch } from '@/components/TickerSearch'; | ||
import { useRouter } from 'next/navigation'; | ||
|
||
export default function Page() { | ||
const router = useRouter(); | ||
return <div> | ||
<TickerSearch onChange={(v) => router.push(`/seasonal/${v.symbol}`)} /> | ||
</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
'use client' | ||
|
||
import { HistoricalDataResponse } from "@/lib/types" | ||
import { GridColDef, DataGrid, gridClasses } from "@mui/x-data-grid"; | ||
import dayjs from "dayjs"; | ||
import { ConditionalFormattingBox } from "./ConditionalFormattingBox"; | ||
import { numberFormatter, percentageFormatter } from "@/lib/formatters"; | ||
|
||
|
||
const months = [ | ||
'January', | ||
'February', | ||
'March', | ||
'April', | ||
'May', | ||
'June', | ||
'July', | ||
'August', | ||
'September', | ||
'October', | ||
'November', | ||
'December', | ||
]; | ||
|
||
export const HistoricalSeason = (props: { data: HistoricalDataResponse }) => { | ||
const currentYear = dayjs().year(); | ||
// use to render the graph/chart | ||
// const dkk = dt.history.day.reduce((acc: Record<string, number[]>, current) => { | ||
// const year = dayjs(current.date).format('YYYY'); | ||
// if (!acc[year]) { | ||
// const currentMonth = dayjs().month(); | ||
// if (year === `${currentYear}`) { | ||
// acc[year] = new Array(currentMonth + 1).fill(0); | ||
// } else { | ||
// acc[year] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
// } | ||
// }; | ||
// const pm = ((current.close - current.open) / current.open) * 100; | ||
// const month = dayjs(current.date).month(); | ||
// acc[year][month] = pm; | ||
// return acc; | ||
// }, {}); | ||
|
||
/* | ||
{month: 'Jan', d2022: 1, d2023: 1.6...}, | ||
{} | ||
const seriesData = Object.keys(dkk).map(year => ({ | ||
label: year, | ||
data: dkk[year] | ||
})); | ||
*/ | ||
const dt = props.data; | ||
const years: string[] = [] | ||
const dkk = dt.history.day.reduce((acc: { id: string }[], current) => { | ||
const year = dayjs(current.date).format('YYYY'); | ||
const pm = ((current.close - current.open) / current.open); | ||
const month = dayjs(current.date).month(); | ||
(acc.find(j => j.id === months[month]) as any)[`d${year}`] = pm.toFixed(2); | ||
if (!years.includes(year)) years.push(year); | ||
return acc | ||
}, months.map(j => ({ id: j }))); | ||
debugger; | ||
|
||
const columns: GridColDef[] = [ | ||
{ field: 'id', width: 120, headerName: 'month' }, | ||
...years.map(j => { | ||
return { | ||
field: `d${j}`, width: 120, headerName: j, | ||
valueFormatter: percentageFormatter, | ||
type: 'number', | ||
renderCell: (p) => <ConditionalFormattingBox value={p.value} formattedValue={p.formattedValue} /> | ||
} as GridColDef | ||
}) | ||
] | ||
|
||
return <div> | ||
<DataGrid rows={dkk} | ||
disableColumnMenu={true} | ||
disableColumnFilter={true} | ||
disableColumnSorting={true} | ||
columns={columns} | ||
density="compact" | ||
disableRowSelectionOnClick | ||
columnHeaderHeight={32} | ||
rowHeight={32} | ||
hideFooter={true} | ||
showColumnVerticalBorder={true} | ||
showCellVerticalBorder={true} | ||
sx={{ | ||
[`& .${gridClasses.cell}:focus, & .${gridClasses.cell}:focus-within`]: { | ||
outline: 'none', | ||
}, | ||
[`& .${gridClasses.columnHeader}:focus, & .${gridClasses.columnHeader}:focus-within`]: | ||
{ | ||
outline: 'none', | ||
}, | ||
[`& .${gridClasses.columnHeader}`]: | ||
{ | ||
fontSize: '0.7rem', | ||
fontWeight: 500 | ||
}, | ||
[`& .${gridClasses.cell}`]: | ||
{ | ||
fontSize: '0.7rem', | ||
padding: 0 | ||
}, | ||
}} | ||
/> | ||
</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { TickerSearch } from '@/components/TickerSearch'; | ||
import { useRouter } from 'next/navigation'; | ||
|
||
interface ITickerProps { | ||
basePath: string, | ||
label?: string | ||
} | ||
|
||
export const TickerSearchNavigation = (props: ITickerProps) => { | ||
const router = useRouter(); | ||
return <TickerSearch onChange={(v) => router.push(`${props.basePath}/${v.symbol}`)} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters