Dagger
Search

GetStocks

Overview:
This module returns S&P 500 index stocks in sectors of your choosing grouped by sector (in terms of average_return)

Functionality:
- Scrapes the S&P 500 company symbols from Wikipedia.
- Fetches historical stock data for each symbol using `yfinance`.
- Calculates the average annual return for each stock based on monthly closing prices.
- Groups stocks by sector, ranks them by their average annual returns for each sector

Args:
- `sectors_of_interest (str)`: A string containing a list of all sectors you want to filter for.
- `period (int)`: The number of years of historical data to fetch.

Return:
- The `stocks` function returns a JSON containing all stocks grouped by sector and ranked by average return. Each stock is returned as a dictionary containing the stock symbol, average return, industry, stock prices and monthly return.

Example Call:
dagger call stocks --sectors_of_interest="Health Care,Information Technology,Financials,Energy" --period=5

Installation

dagger install github.com/EmmS21/daggerverse/GetStocks@v0.0.8

Entrypoint

Return Type
GetStocks !
Example
dagger -m github.com/EmmS21/daggerverse/GetStocks@cb7961bb0021b5513a4322bdd370863bd067dde5 call \
func (m *myModule) example() *GetStocks  {
	return dag.
			GetStocks()
}
@function
def example() -> dag.GetStocks:
	return (
		dag.get_stocks()
	)
@func()
example(): GetStocks {
	return dag
		.getStocks()
}

Types

GetStocks 🔗

stocks() 🔗

Return Type
String !
Arguments
NameTypeDefault ValueDescription
sectorsOfInterestString !-No description provided
periodInteger !-No description provided
Example
dagger -m github.com/EmmS21/daggerverse/GetStocks@cb7961bb0021b5513a4322bdd370863bd067dde5 call \
 stocks --sectors-of-interest string --period integer
func (m *myModule) example(ctx context.Context, sectorsOfInterest string, period int) string  {
	return dag.
			GetStocks().
			Stocks(ctx, sectorsOfInterest, period)
}
@function
async def example(sectors_of_interest: str, period: int) -> str:
	return await (
		dag.get_stocks()
		.stocks(sectors_of_interest, period)
	)
@func()
async example(sectorsOfInterest: string, period: number): Promise<string> {
	return dag
		.getStocks()
		.stocks(sectorsOfInterest, period)
}