Dagger
Search

GetStocks

Overview:
This module finds and returns the top N S&P 500 index stocks in sectors of your choosing grouped by sector

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, and returns the top investment options 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.
- `top (int)`: The number of top stocks to return for each sector.

Return:
- The `stocks` function returns a JSON formatted string representing the top N investment options for each sector based on average returns. Each investment option is a dictionary containing the stock symbol, its average annual return, current price, and monthly returns.

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

Installation

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

Entrypoint

Return Type
GetStocks !
Example
dagger -m github.com/EmmS21/daggerverse/GetStocks@b0d2c698f17f700657f6a12f07f98833a198b570 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
topInteger !-No description provided
Example
dagger -m github.com/EmmS21/daggerverse/GetStocks@b0d2c698f17f700657f6a12f07f98833a198b570 call \
 stocks --sectors-of-interest string --period integer --top integer
func (m *myModule) example(ctx context.Context, sectorsOfInterest string, period int, top int) string  {
	return dag.
			GetStocks().
			Stocks(ctx, sectorsOfInterest, period, top)
}
@function
async def example(sectors_of_interest: str, period: int, top: int) -> str:
	return await (
		dag.get_stocks()
		.stocks(sectors_of_interest, period, top)
	)
@func()
async example(sectorsOfInterest: string, period: number, top: number): Promise<string> {
	return dag
		.getStocks()
		.stocks(sectorsOfInterest, period, top)
}