0

I am working with financial data on R and I need to know what is the percentage of days with a stock return larger than 5% in absolute value.

I have the variable "returns" and my intuition is that I should create another variable for which the absolute value of the return is larger than 5% and then see how many elements would that variable vector contain and compute the ratio between its length and the total number of observations. However, I need help with the commands I should use on R.

(I know this may sound very easy but I am not used to analysing financial data with R)

wlog
  • 25
  • 3
  • 1
    Hi, and welcome to SO! In general, you should review [How to Ask](https://stackoverflow.com/help/how-to-ask), and in particular it is more likely to get an answer if you describe what you have tried already so we know where you are stuck. – Calum You Jan 30 '19 at 23:17

1 Answers1

0

If you just want a number and returns is a numeric vector, you could try

sum(abs(returns) > 0.05) / length(returns)

where we are counting the number of absolute returns greater than 5% in the numerator and dividing by the number of observations, as you described. Try using ?sum, ?abs, ?length for more documentation on what these functions do.

Calum You
  • 14,687
  • 4
  • 23
  • 42