clean up dividend page
This commit is contained in:
parent
c6940ca6ae
commit
818f3f27bc
@ -247,7 +247,7 @@ onMount( async() => {
|
||||
<Card.Root >
|
||||
<Card.Header class="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<Card.Title class="text-start text-[1rem] sm:text-xl font-semibold">
|
||||
<a href="/market-mover" class="sm:hover:underline">Biggest Winner</a>
|
||||
<a href="/market-mover" class="sm:hover:underline">Winner</a>
|
||||
</Card.Title>
|
||||
<Crown class="h-4 w-4 shrink-0" />
|
||||
</Card.Header>
|
||||
@ -268,7 +268,7 @@ onMount( async() => {
|
||||
<Card.Root>
|
||||
<Card.Header class="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<Card.Title class="text-start text-[1rem] sm:text-xl font-semibold">
|
||||
<a href="/market-mover" class="sm:hover:underline">Biggest Loser</a>
|
||||
<a href="/market-mover" class="sm:hover:underline">Loser</a>
|
||||
</Card.Title>
|
||||
<Bomb class="h-4 w-4 shrink-0" />
|
||||
</Card.Header>
|
||||
|
||||
@ -13,7 +13,7 @@ use([LineChart, BarChart, TooltipComponent, GridComponent, CanvasRenderer])
|
||||
export let data;
|
||||
|
||||
let dateDistance;
|
||||
let stockDividends = data?.getStockDividend?.at(0);
|
||||
let stockDividends = data?.getStockDividend?.at(0)?.filter(item => item?.recordDate && item?.paymentDate);
|
||||
let optionsDividend;
|
||||
|
||||
|
||||
@ -26,12 +26,11 @@ let payoutRatio = 'n/a';
|
||||
let dividendGrowth = 'n/a';
|
||||
|
||||
let dividendList = [];
|
||||
let growthList = [];
|
||||
let dateList = [];
|
||||
|
||||
|
||||
|
||||
async function plotDividend(dividendList, growthList, dateList) {
|
||||
async function plotDividend(dividendList, dateList) {
|
||||
const options = {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
@ -106,10 +105,9 @@ const handleMessage = async (event) => {
|
||||
payoutRatio = finalData?.payoutRatio;
|
||||
dateDistance = finalData?.dateDistance;
|
||||
dividendList = finalData?.dividendList;
|
||||
growthList = finalData?.growthList;
|
||||
dateList = finalData?.dateList;
|
||||
annualDividend = finalData?.annualDividend;
|
||||
optionsDividend = await plotDividend(dividendList, growthList, dateList)
|
||||
optionsDividend = await plotDividend(dividendList, dateList)
|
||||
//console.log('Message from worker:', chartData);
|
||||
|
||||
};
|
||||
|
||||
@ -15,19 +15,9 @@ function plotDividend(stockDividends) {
|
||||
|
||||
for (let i = 0; i < reverseData?.length; i++) {
|
||||
const currentDividend = reverseData[i]?.dividend;
|
||||
const previousDividend = i === 0 ? 0 : reverseData[i - 1]?.dividend;
|
||||
|
||||
dateList.push(reverseData[i]?.paymentDate);
|
||||
dividendList?.push(currentDividend);
|
||||
|
||||
|
||||
if (currentDividend !== null && previousDividend !== null && previousDividend !== 0) {
|
||||
const growthRate = (((currentDividend - previousDividend) / previousDividend) * 100 )?.toFixed(2);
|
||||
growthList?.push(growthRate);
|
||||
} else {
|
||||
growthList?.push(0); // Pushing null if the growth calculation is not possible
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -36,29 +26,29 @@ function plotDividend(stockDividends) {
|
||||
|
||||
onmessage = async (event: MessageEvent) => {
|
||||
const data = event.data?.message;
|
||||
const stockDividends = data?.at(0);
|
||||
const stockDividends = data?.at(0)?.filter(item => item?.recordDate && item?.paymentDate);
|
||||
const eps = data?.at(1);
|
||||
const currentPrice = data?.at(2);
|
||||
|
||||
const payoutFrequency = stockDividends?.filter(entry => entry.date.includes('2022'))?.length;
|
||||
const payoutFrequency = stockDividends?.filter(entry => entry.date.includes('2023'))?.length;
|
||||
const amount = stockDividends[0]?.adjDividend;
|
||||
const annualDividend = (amount * payoutFrequency)?.toFixed(2)
|
||||
const dividendYield = ((annualDividend / currentPrice )*100)?.toFixed(2)
|
||||
const exDividendDate = stockDividends[0]?.date
|
||||
const payoutRatio = ((1 - ( eps - annualDividend)/eps)*100)?.toFixed(2)
|
||||
|
||||
const previousIndex = stockDividends?.findIndex(entry => entry.date.includes('2022'));
|
||||
const previousIndex = stockDividends?.findIndex(entry => entry.date.includes('2023'));
|
||||
|
||||
const previousAnnualDividend = stockDividends[previousIndex]?.adjDividend * payoutFrequency;
|
||||
|
||||
const dividendGrowth= (( (annualDividend - previousAnnualDividend) / previousAnnualDividend ) *100)?.toFixed(2);
|
||||
|
||||
const {dividendList, growthList, dateList} = plotDividend(stockDividends)
|
||||
const {dividendList, dateList} = plotDividend(stockDividends)
|
||||
|
||||
//Check if the last dividend is older than 12 months
|
||||
const dateDistance = new Date(stockDividends?.at(0)?.date) < new Date(new Date().setFullYear(new Date().getFullYear() - 1)) ? true : false;
|
||||
|
||||
let finalData = { annualDividend, payoutFrequency, exDividendDate, dividendYield, dividendGrowth, payoutRatio , dateDistance, dividendList, growthList, dateList};
|
||||
let finalData = { annualDividend, payoutFrequency, exDividendDate, dividendYield, dividendGrowth, payoutRatio , dateDistance, dividendList, dateList};
|
||||
postMessage({ message: 'success', finalData});
|
||||
|
||||
// Sending data back to the main thread
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user