From 668aaa10d9db58b3f990274ffb123f504726ef9c Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Thu, 29 Aug 2024 15:48:23 +0200 Subject: [PATCH] add new rules to stock screener --- .../stock-screener/[strategyId]/+page.svelte | 160 ++++++++++++++++-- 1 file changed, 143 insertions(+), 17 deletions(-) diff --git a/src/routes/stock-screener/[strategyId]/+page.svelte b/src/routes/stock-screener/[strategyId]/+page.svelte index 4b506354..66ecfd65 100644 --- a/src/routes/stock-screener/[strategyId]/+page.svelte +++ b/src/routes/stock-screener/[strategyId]/+page.svelte @@ -18,13 +18,10 @@ const title = data?.getStrategy?.title; let stockScreenerData = data?.getStockScreenerData?.filter(item => - item?.ratingRecommendation !== null && - item?.trendAnalysis?.accuracy !== null && - item?.fundamentalAnalysis?.accuracy !== null && - item?.dividendYield !== null && - item?.annualDividend !== null && - item?.dividendGrowth !== null && - item?.payoutRatio !== null + Object?.values(item)?.every(value => + value !== null && value !== undefined && + (typeof value !== 'object' || Object?.values(value)?.every(subValue => subValue !== null && subValue !== undefined)) + ) ); @@ -113,6 +110,11 @@ const getStockScreenerData = async (rules) => { var: (ruleOfList?.find(item => item.name === "var") || { condition: 'above' }).condition, trendAnalysis: (ruleOfList?.find(item => item.name === "trendAnalysis") || { condition: 'above' }).condition, fundamentalAnalysis: (ruleOfList?.find(item => item.name === "fundamentalAnalysis") || { condition: 'above' }).condition, + currentRatio: (ruleOfList?.find(item => item.name === "currentRatio") || { condition: 'above' }).condition, + quickRatio: (ruleOfList?.find(item => item.name === "quickRatio") || { condition: 'above' }).condition, + debtEquityRatio: (ruleOfList?.find(item => item.name === "debtEquityRatio") || { condition: 'above' }).condition, + debtRatio: (ruleOfList?.find(item => item.name === "debtRatio") || { condition: 'above' }).condition, + }; let ruleTrend = { @@ -174,7 +176,12 @@ const getStockScreenerData = async (rules) => { { rule: 'var', label: 'Value at Risk (VaR)', category: 'fund' }, { rule: 'trendAnalysis', label: 'AI Trend Analysis (Bullish)', category: 'ai' }, { rule: 'fundamentalAnalysis', label: 'AI Fundamental Analysis (Bullish)', category: 'ai' }, - { rule: 'ratingRecommendation', label: 'Analyst Rating', category: 'fund'} + { rule: 'ratingRecommendation', label: 'Analyst Rating', category: 'fund'}, + { rule: 'currentRatio', label: 'Current Ratio',category: 'fund' }, + { rule: 'quickRatio', label: 'Quick Ratio',category: 'fund' }, + { rule: 'debtEquityRatio', label: 'Debt Equity Ratio',category: 'fund' }, + { rule: 'debtRatio', label: 'Debt Ratio',category: 'fund' }, + ]; // Creating the ruleMappings object from allRows @@ -232,6 +239,11 @@ const getStockScreenerData = async (rules) => { let valueDividendGrowth = (ruleOfList?.find(item => item.name === "dividendGrowth") || { value: 5 }).value; let valuePayoutRatio = (ruleOfList?.find(item => item.name === "payoutRatio") || { value: 20 }).value; + let valueCurrentRatio = (ruleOfList?.find(item => item.name === "currentRatio") || { value: 1 }).value; + let valueQuickRatio = (ruleOfList?.find(item => item.name === "quickRatio") || { value: 1 }).value; + let valueDebtEquityRatio = (ruleOfList?.find(item => item.name === "debtEquityRatio") || { value: 1 }).value; + let valueDebtRatio = (ruleOfList?.find(item => item.name === "debtRatio") || { value: 1 }).value; + let valueEPS = (ruleOfList?.find(item => item.name === "eps") || { value: 2 }).value; let valueGrowthEPS = (ruleOfList?.find(item => item.name === "growthEPS") || { value: 10 }).value; let valuePE = (ruleOfList?.find(item => item.name === "pe") || { value: 10 }).value; @@ -342,6 +354,10 @@ const valueMappings = { var: valueVaR, trendAnalysis: valueTrendAnalysis, fundamentalAnalysis: valueFundamentalAnalysis, + currentRatio: valueCurrentRatio, + quickRatio: valueQuickRatio, + debtEquityRatio: valueDebtEquityRatio, + debtRatio: valueDebtRatio, }; const conditions = { @@ -394,6 +410,11 @@ const conditions = { var: ruleCondition.var, trendAnalysis: ruleCondition.trendAnalysis, fundamentalAnalysis: ruleCondition.fundamentalAnalysis, + currentRatio: ruleCondition.currentRatio, + quickRatio: ruleCondition.quickRatio, + debtEquityRatio: ruleCondition.debtEquityRatio, + debtRatio: ruleCondition.debtRatio, + }; @@ -453,14 +474,11 @@ async function updateStockScreenerData() { try { const newData = await getStockScreenerData(ruleOfList); stockScreenerData = newData?.filter(item => - item?.ratingRecommendation !== null && - item?.trendAnalysis?.accuracy !== null && - item?.fundamentalAnalysis?.accuracy !== null && - item?.dividendYield !== null && - item?.annualDividend !== null && - item?.dividendGrowth !== null && - item?.payoutRatio !== null - ); + Object.values(item).every(value => + value !== null && value !== undefined && + (typeof value !== 'object' || Object.values(value).every(subValue => subValue !== null && subValue !== undefined)) + ) + ); filteredData = filterStockScreenerData(); displayResults = filteredData?.slice(0, 50); @@ -771,6 +789,18 @@ $: { case 'fundamentalAnalysis': ruleToUpdate.value = valueFundamentalAnalysis; break; + case 'currentRatio': + ruleToUpdate.value = valueCurrentRatio; + break; + case 'quickRatio': + ruleToUpdate.value = valueQuickRatio; + break; + case 'debtEquityRatio': + ruleToUpdate.value = valueDebtEquityRatio; + break; + case 'debtRatio': + ruleToUpdate.value = valueDebtRatio; + break; default: // Handle any case not explicitly mentioned break; @@ -852,7 +882,7 @@ function filterStockScreenerData() { } let order = 'highToLow'; -let sortBy = 'change'; // Default sorting by change percentage +let sortBy = ''; // Default sorting by change percentage function changeOrder(state:string) { if (state === 'highToLow') @@ -1605,7 +1635,103 @@ $: charNumber = $screenWidth < 640 ? 20 : 40; {/if} + {#if ruleName === 'currentRatio'} +
+ Current Ratio {ruleCondition[ruleName]} {valueCurrentRatio} + + + + +
+ + +
+ + +
+ + {/if} + + {#if ruleName === 'quickRatio'} + +
+ Quick Ratio {ruleCondition[ruleName]} {valueQuickRatio} + + + + +
+ + +
+ + +
+ + {/if} + + {#if ruleName === 'debtRatio'} + +
+ Debt Ratio {ruleCondition[ruleName]} {valueDebtRatio} + + + + +
+ + +
+ + +
+ + {/if} + + + {#if ruleName === 'debtEquityRatio'} + +
+ Debt Equity Ratio {ruleCondition[ruleName]} {valueDebtEquityRatio} + + + + +
+ + +
+ + +
+ + {/if} + {#if ruleName === 'payoutRatio'}