coursera compfinace course: Some R code translated to python