Replies: 1 comment
-
Finding Competitors/Peers Using SIC CodesEdgarTools has a built-in solution for finding competitors/peers! Companies are classified by SIC (Standard Industrial Classification) codes, which group companies by industry. Quick Examplefrom edgar import Company
from edgar.reference import get_company_dataset
import pyarrow.compute as pc
# Get your company's SIC code
company = Company("AAPL") # Apple
sic = company.sic
print(f"Apple SIC: {sic}") # 3571 - Electronic Computers
# Load company dataset (builds on first use, ~30 seconds)
companies = get_company_dataset()
# Find competitors with same SIC code
competitors = companies.filter(pc.field('sic') == sic)
print(f"Found {len(competitors)} companies in the same industry")
# View the results
import pandas as pd
df = competitors.to_pandas()
print(df[['name', 'tickers', 'sic_description']].head(10))Output ExampleAdvanced: Find Similar Companies by SIC RangeSIC codes are hierarchical - the first 2 digits indicate broad industry: # Find all computer & office equipment companies (SIC 357X)
tech_hardware = companies.filter(
pc.field('sic').between(3570, 3579)
)
print(f"Found {len(tech_hardware)} tech hardware companies")Performance
Common SIC Code Ranges
Finding Specific CompetitorsIf you want to find the top competitors by a specific metric (like market cap), you can:
# Get pharmaceutical competitors
pharma = companies.filter(pc.field('sic').between(2834, 2836))
# Filter to Nasdaq-listed only
nasdaq_pharma = pharma.filter(
pc.field('exchanges').contains('Nasdaq')
)
# Get tickers
tickers_df = nasdaq_pharma.to_pandas()
competitor_tickers = [
ticker for tickers in tickers_df['tickers'].dropna()
for ticker in tickers.split('|')
]
print(f"Competitor tickers: {competitor_tickers}")Bonus: Get All Filings from CompetitorsOnce you have competitor tickers, you can fetch their filings: # Get competitor tickers
competitor_tickers = ['IBM', 'DELL', 'HPQ']
# Fetch recent filings from all competitors
for ticker in competitor_tickers:
company = Company(ticker)
recent_filings = company.get_filings(form='10-K').latest(1)
print(f"{ticker}: {recent_filings}")First-Time SetupIf you haven't used the dataset before: # Download SEC submissions data (one-time, ~500 MB)
from edgar.storage import download_submissions
download_submissions()
# Then use get_company_dataset() - it will build automaticallySummary: Use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Intro
There are actually multiple options of how to use $state and $derived with different implications. Following decision trees help narrowing down when to use which option. There is a summary at the bottom with default recommendations when starting out.
Its tl;dr is:
When starting out...
$state({ value: 0 })or$state([0, 0])or$state([{ value: 0 }])() => someStateIf you don't understand the terms in the decision trees you can find examples below the trees.
There are even more options than described but I limited the trees to those options you are going to use IRL and where high flexibility, less boilerplate and overall DX are key.
$state
Examples and docs for each option:
$state(0)docs$state({ value: 0 })docsclass Something { value = $state(0); d = $derived(this.value) }docsYou get most features with
classand the ability to create multiple instances but it has the most boilerplate and the most minimal type hints, actually none except the class name; $state primitive is pretty bare bone and needs to be refactored if you want more but it's lean and a $state object is somewhere in the middle with very slight performance overhead but gives you way better type hints than a class.You can still use $state objects when needing $derived, you just embed a function instead. Putting a $derived outside as a dedicated constant declaration doesn't always work because it can't be exported. So, with option 2 and you might rarely run into limitations and don't need to refactor while with option 1 things are much more limited. Option 2 seems to offer the most balanced package regarding features, flexibility, performance and DX.
Bonus tip: Always use arrow functions within classes, so
thisrefers to the lexical scope or where the function was defined.Here the same info as a comparison chart:
*This is actually "State needs write access and to be exported" but since $state always needs some write access at some point (otherwise why would I use $state?) it is shortened to "State needs to be exported".
$derived/$derived.by
Examples:
const someDerivedState = $derived(someState)export const someDerivedState = () => someStateorexport const objectState = { someDerivedState: () => someState }class ClassWRunes { someDerivedState = $derived(someState) }; export const classWRunes = new ClassWithRunes()Once you want to export a $derived you need to embed it into a class with Runes which again has the most boilerplate and no type hints. It is easier to just use a function which can be embedded into $state object or just left outside and still be exported, in contrast to $derived.
Summary
While Runes give quite some options how to work with them it can be overwhelming when you just get started. All options have their place but to reduce complexity and mental overhead, you should have one default option in your mind and deviate when appropriate:
Beta Was this translation helpful? Give feedback.
All reactions