R Code for trading