diff --git a/src/lib/components/RuleControl.svelte b/src/lib/components/RuleControl.svelte index e0304648..cf1dc006 100644 --- a/src/lib/components/RuleControl.svelte +++ b/src/lib/components/RuleControl.svelte @@ -10,15 +10,15 @@ export let unit = ''; export let condition; - console.log(condition) const dispatch = createEventDispatcher(); function changeRuleCondition(newCondition) { + condition = newCondition dispatch('changeCondition', { rule: ruleName, condition: newCondition }); } - function changeValue(event) { - dispatch('changeValue', { rule: ruleName, value: Number(event.target.value) }); + function changeValue(val) { + dispatch('changeValue', { rule: ruleName, value: val }); } @@ -57,8 +57,14 @@
diff --git a/src/routes/stock-screener/[strategyId]/+page.svelte b/src/routes/stock-screener/[strategyId]/+page.svelte index 3c7f25d6..98aa2728 100644 --- a/src/routes/stock-screener/[strategyId]/+page.svelte +++ b/src/routes/stock-screener/[strategyId]/+page.svelte @@ -4,7 +4,6 @@ import { screenWidth, strategyId, numberOfUnreadNotification, getCache, setCache} from '$lib/store'; import toast from 'svelte-french-toast'; import { abbreviateNumber, formatRuleValue } from '$lib/utils'; - import RuleControl from '$lib/components/RuleControl.svelte'; //const userConfirmation = confirm('Unsaved changes detected. Leaving now will discard your strategy. Continue?'); @@ -13,7 +12,7 @@ $strategyId = data?.getStrategyId; let ruleOfList = data?.getStrategy?.rules ?? []; - + let displayRules = []; const title = data?.getStrategy?.title; @@ -125,6 +124,8 @@ const getStockScreenerData = async (rules) => { let ruleTrend = { ratingRecommendation: 'Hold', }; + + let allRows = [ @@ -144,7 +145,7 @@ const getStockScreenerData = async (rules) => { { rule: 'change6M', label: 'Price Change 6M [%]', max: "200", min:"-100", step:"2", unit: '%',category: 'ta' }, { rule: 'change1Y', label: 'Price Change 1Y [%]', max: "200", min:"-100", step:"2", unit: '%',category: 'ta' }, { rule: 'change3Y', label: 'Price Change 3Y [%]', max: "200", min:"-100", step:"2", unit: '%',category: 'ta' }, - { rule: 'marketCap', label: 'Market Cap', max: "800", min:"10", step:"10", unit: 'Bn', category: 'fund'}, + { rule: 'marketCap', label: 'Market Cap', step: [100,50,10,1], unit: 'B', category: 'fund'}, { rule: 'revenue', label: 'Revenue', max: "800", min:"-100", step:"10", unit: 'Bn', category: 'fund' }, { rule: 'growthRevenue', label: 'Revenue Growth [%]', max: "200", min:"-100", step:"2", unit: '%', category: 'fund' }, { rule: 'costOfRevenue', label: 'Cost of Revenue', max: "800", min:"-100", step:"10", unit: 'Bn', category: 'fund' }, @@ -174,7 +175,7 @@ const getStockScreenerData = async (rules) => { { rule: 'forwardPE', label: 'Forward PE', max: "100", min:"-100", step:"2", category: 'fund'}, { rule: 'priceToBookRatio', label: 'P/B', max: "50", min:"0", step:"0.5", category: 'fund'}, { rule: 'priceToSalesRatio', label: 'P/S', max: "50", min:"0", step:"0.5", category: 'fund'}, - { rule: 'beta', label: 'Beta', max: "10", min:"-10", step:"0.1", category: 'fund'}, + { rule: 'beta', label: 'Beta', step: [10,5,1,-5, -10], unit:'', category: 'fund'}, { rule: 'ebitda', label: 'EBITDA', max: "800", min:"-100", step:"10", unit: 'Bn', category: 'fund'}, { rule: 'growthEBITDA', label: 'EBITDA Growth [%]', max: "200", min:"-100", step:"2", unit: '%', category: 'fund'}, { rule: 'var', label: 'VaR', max: "0", min:"-20", step:"1", unit: '%', category: 'fund' }, @@ -193,13 +194,8 @@ const getStockScreenerData = async (rules) => { { rule: 'priceToFreeCashFlowsRatio', label: 'Price / FCF', max: "100", min:"-100", step:"2", category: 'fund' }, ]; - // Creating the ruleMappings object from allRows - const ruleMappings = allRows.reduce((acc, row) => { - acc[row.rule] = row.label; - return acc; - }, {}); - - + + allRows?.sort((a, b) => a.label.localeCompare(b.label)); let filteredRows; let searchTerm = ''; @@ -210,14 +206,8 @@ const getStockScreenerData = async (rules) => { taRows?.sort((a, b) => a.label.localeCompare(b.label)); fundRows?.sort((a, b) => a.label.localeCompare(b.label)); */ - - function changeRuleCondition(state: string) { - ruleCondition[ruleName] = state; - } - - - let ruleName = ''; + let ruleName = 'marketCap'; // Define your default values @@ -703,6 +693,7 @@ $: { ruleOfList = [...ruleOfList]; } + displayRules = allRows.filter(row => ruleOfList.some(rule => rule.name === row.rule)); filteredData = filterStockScreenerData(); if (ruleOfList?.some(item => item?.name === 'ratingRecommendation')) { @@ -729,10 +720,12 @@ function filterStockScreenerData() { 'grossProfit' ]?.includes(rule.name)) { - if (rule.condition === "over" && item[rule.name] !== null && item[rule.name] <= rule.value * 10**(9)) { + if (rule.condition === "over" && item[rule.name] !== null && item[rule.name] <= rule.value * 10**(9)) { + //console.log('over filter', rule) return false; } else if (rule.condition === "under" && item[rule.name] !== null && item[rule.name] > rule.value * 10**(9)) { + //console.log('under filter', rule) return false; } } @@ -856,12 +849,16 @@ $: isSaved = !ruleOfList; $: charNumber = $screenWidth < 640 ? 20 : 40; -function handleChangeCondition(event) { - ruleCondition[event.detail.rule] = event.detail.condition; - } +function changeRuleCondition(name:string, state: string) { + ruleName = name; + ruleCondition[ruleName] = state; + +} + + +function handleChangeValue(value) { + const rule = ruleName -function handleChangeValue(event) { - const { rule, value } = event.detail; if (rule in valueMappings) { valueMappings[rule] = value; // If you need to keep the separate variables in sync: @@ -1058,6 +1055,8 @@ function handleChangeValue(event) { // Optionally handle unknown rules here } } + + @@ -1127,40 +1126,103 @@ function handleChangeValue(event) {
- + + + + + {#if ruleOfList?.length !== 0} + + {/if} + +
- {#each allRows as row (row.rule)} - {#if ruleOfList.some(rule => rule.name === row.rule)} - - {/if} + {#each displayRules as row (row?.rule)} + +
+
+ {row?.label?.replace('[%]','')} +
+
+ +
+
ruleName = row?.rule} class="dropdown dropdown-end"> + + + +
+
+
+
+ {/each}
@@ -1308,15 +1370,6 @@ function handleChangeValue(event) { -
- -
- -