some R codes for stock trading