Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. // compute SMA using standard summation
  2. simple_moving_average(data, w, averages);
  3.  
  4. unsigned n_SMAs = 1000; // # of SMA indicators to evaluate
  5. unsigned len = 2000; // # of stock prices per indicator
  6. unsigned w = 6; // window size
  7.  
  8. // generate stock prices: [0..10]
  9. af::array data = af::randu(n_SMAs, len) * 10;
  10.  
  11. // compute inclusive prefix sums along colums of the matrix
  12. af::array s = af::accum(data, 1);
  13.  
  14. // compute the average
  15. af::array avg = (s.cols(w, af::end) - s.cols(0, af::end - w)) / w;
  16. af::eval(avg);
  17.  
  18. std::cout << avg.dims() << "n" << avg << "n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement