,

@maureen

To compile a list or dataframe of the lowest 50 RSI (Relative Strength Index) values of NASDAQ stocks for a specific period in R, you can follow these steps:

**Install and load required packages**: Install the quantmod package if not already installed and then load it using the library() function.

1 2 |
install.packages("quantmod") library(quantmod) |

**Get the list of NASDAQ symbols**: Use the nasdaqtraded function from the quantmod package to get a dataframe of all NASDAQ-listed stocks.

```
1
``` |
nasdaq_list <- nasdaqtraded() |

**Filter NASDAQ symbols**: Extract the symbols (ticker names) from the nasdaq_list dataframe.

```
1
``` |
symbols <- nasdaq_list$Symbol |

**Retrieve RSI for each stock**: Use a loop to iterate over the symbols and retrieve the RSI values using the RSI() function from the quantmod package. Store the RSI values in a new dataframe.

1 2 3 4 5 6 7 8 9 10 11 |
rsi_data <- data.frame() for (symbol in symbols) { tryCatch({ data <- getSymbols(symbol, from = "2021-01-01", to = "2021-12-31", auto.assign = FALSE) rsi <- RSI(Cl(data), n = 14) # Assuming a period of 14 for RSI calculation last_rsi <- tail(rsi, 1) rsi_data <- rbind(rsi_data, data.frame(symbol = symbol, rsi = last_rsi)) }, error = function(e) { # Ignore symbols that throw errors }) } |

Note: The `tryCatch`

block is used to handle any errors that may occur while retrieving data for a particular stock. This allows the loop to continue and collect data for other stocks even if there are errors for some of them.

**Sort and select lowest 50 RSI values**: Sort the rsi_data dataframe based on the RSI values in ascending order and select the lowest 50 RSI values using the head() function.

```
1
``` |
lowest_50_rsi <- head(rsi_data[order(rsi_data$rsi), ], 50) |

**View the resulting dataframe**: Print or view the lowest_50_rsi dataframe to see the symbols and corresponding RSI values.

```
1
``` |
print(lowest_50_rsi) |

This process retrieves the RSI values of NASDAQ stocks for a specified period, selects the lowest 50 RSI values, and stores them in a dataframe for further analysis or use.

Please note that the above code is for educational purposes and may require modifications based on your specific needs or preferences.

,

@maureen

To compile a list or dataframe of the lowest 50 RSI (Relative Strength Index) values of NASDAQ stocks for a specific period in R, you can follow the steps outlined below. This code is based on the guidance provided:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# Install and load required packages if (!requireNamespace("quantmod", quietly = TRUE)) { install.packages("quantmod") } library(quantmod) # Get the list of NASDAQ symbols nasdaq_list <- nasdaqtraded() # Filter NASDAQ symbols symbols <- nasdaq_list$Symbol # Create an empty dataframe to store RSI data rsi_data <- data.frame() # Retrieve RSI for each stock for (symbol in symbols) { tryCatch({ data <- getSymbols(symbol, from = "2021-01-01", to = "2021-12-31", auto.assign = FALSE) if (!is.null(data)) { rsi <- RSI(Cl(data), n = 14) # Assuming a period of 14 for RSI calculation last_rsi <- tail(rsi, 1) rsi_data <- rbind(rsi_data, data.frame(symbol = symbol, rsi = last_rsi)) } }, error = function(e) { # Ignore symbols that throw errors }) } # Sort and select lowest 50 RSI values lowest_50_rsi <- head(rsi_data[order(rsi_data$rsi), ], 50) # View the resulting dataframe print(lowest_50_rsi) |

In this code snippet:

- We start by loading the required quantmod package and fetching the list of NASDAQ symbols.
- We iterate over each symbol, retrieve the RSI values for the specified period, and store them in a dataframe.
- Any symbols that throw errors during data retrieval are ignored.
- The resulting dataframe is then sorted based on RSI values in ascending order, and the lowest 50 RSI values are selected.
- Finally, the dataframe containing the lowest 50 RSI values for NASDAQ stocks is printed for viewing.

You can run this code in your R environment after making necessary modifications and adjustments according to your requirements. Remember to replace the date range, RSI period, or any other parameters as needed for your analysis.

15