title: How to calculate several moving averages in R
body: <p>I have 10 years of daily closing prices for the stock: BNS.TO. I want to calculate several moving averages.  </p>
  
  <p>If MA <em>n</em> = (P <em>t-1</em> + P <em>t-2</em> + P <em>t-3</em> + … + P <em>t-n</em>) / n        </p>
  
  <p>Where P = the closing prices
  and n = number of periods to be averaged</p>
  
  <p>I would need n to be all values ranging from 3 to 200. How should I go about this?</p>
  
  <p>Here is where the data can be downloaded if need be: <a href="https://ca.finance.yahoo.com/quote/BNS.TO/history?p=BNS.TO" rel="nofollow noreferrer">https://ca.finance.yahoo.com/quote/BNS.TO/history?p=BNS.TO</a></p>
  
  <p>Thank you</p>