for csv files
Create the following monthly price and total return csv file for Apple.
Date,Price Return,Total Return, 2007/01/31,1.0490 ,1.0490 , 2007/02/28,-1.3064 ,-1.3064 , 2007/03/30,9.8097 ,9.8097 , 2007/04/30,7.4158 ,7.4158 , 2007/05/31,21.4339 ,21.4339 , 2007/06/29,0.7005 ,0.7005 , 2007/07/31,7.9646 ,7.9646 , 2007/08/31,5.1002 ,5.1002 , 2007/09/28,10.8247 ,10.8247 , 2007/10/31,23.7701 ,23.7701 , 2007/11/30,-4.0695 ,-4.0695 , 2007/12/31,8.7038 ,8.7038 , 2008/01/31,-31.6640 ,-31.6640 , 2008/02/29,-7.6389 ,-7.6389 , 2008/03/31,14.7816 ,14.7816 , 2008/04/30,21.2195 ,21.2195 , 2008/05/30,8.5082 ,8.5082 , 2008/06/30,-11.2901 ,-11.2901 , 2008/07/31,-5.0705 ,-5.0705 , 2008/08/29,6.6562 ,6.6562 , 2008/09/30,-32.9558 ,-32.9558 , 2008/10/31,-5.3405 ,-5.3405 , 2008/11/28,-13.8675 ,-13.8675 , 2008/12/31,-7.8990 ,-7.8990 , 2009/01/30,5.6005 ,5.6005 , 2009/02/27,-0.9098 ,-0.9098 , 2009/03/31,17.7024 ,17.7024 , 2009/04/30,19.7013 ,19.7013 , 2009/05/29,7.9313 ,7.9313 , 2009/06/30,4.8745 ,4.8745 , 2009/07/31,14.7160 ,14.7160 , 2009/08/31,2.9500 ,2.9500 , 2009/09/30,10.1896 ,10.1896 , 2009/10/30,1.6995 ,1.6995 , 2009/11/30,6.0531 ,6.0531 , 2009/12/31,5.4134 ,5.4134 , 2010/01/29,-8.8591 ,-8.8591 , 2010/02/26,6.5380 ,6.5380 , 2010/03/31,14.8470 ,14.8470 , 2010/04/30,11.1021 ,11.1021 , 2010/05/28,-1.6125 ,-1.6125 , 2010/06/30,-2.0827 ,-2.0827 , 2010/07/30,2.2741 ,2.2741 , 2010/08/31,-5.5005 ,-5.5005 , 2010/09/30,16.7215 ,16.7215 , 2010/10/29,6.0722 ,6.0722 , 2010/11/30,3.3790 ,3.3790 , 2010/12/31,3.6670 ,3.6670 , 2011/01/31,5.1959 ,5.1959 , 2011/02/28,4.0935 ,4.0935 , 2011/03/31,-1.3314 ,-1.3314 , 2011/04/29,0.4656 ,0.4656 , 2011/05/31,-0.6569 ,-0.6569 , 2011/06/30,-3.4960 ,-3.4960 , 2011/07/29,16.3285 ,16.3285 , 2011/08/31,-1.4469 ,-1.4469 , 2011/09/30,-0.9121 ,-0.9121 , 2011/10/31,6.1523 ,6.1523 , 2011/11/30,-5.5783 ,-5.5783 , 2011/12/30,5.9655 ,5.9655 , 2012/01/31,12.7111 ,12.7111 , 2012/02/29,18.8311 ,18.8311 , 2012/03/30,10.5284 ,10.5284 , 2012/04/30,-2.5969 ,-2.5969 , 2012/05/31,-1.0702 ,-1.0702 , 2012/06/29,1.0853 ,1.0853 , 2012/07/31,4.5822 ,4.5822 , 2012/08/31,8.9200 ,9.3850 , 2012/09/28,0.2803 ,0.2803 , 2012/10/31,-10.7607 ,-10.7607 , 2012/11/30,-1.6865 ,-1.2196 , 2012/12/31,-9.0738 ,-9.0738 , 2013/01/31,-14.4094 ,-14.4094 , 2013/02/28,-3.0934 ,-2.5449 , 2013/03/28,0.2855 ,0.2855 , 2013/04/30,0.0271 ,0.0271 , 2013/05/31,1.5708 ,2.2490 , 2013/06/28,-11.8303 ,-11.8303 , 2013/07/31,14.1225 ,14.1225 , 2013/08/30,7.6649 ,8.3772 , 2013/09/30,-2.1481 ,-2.1481 , 2013/10/31,9.6386 ,9.6386 , 2013/11/29,6.3838 ,7.0066 , 2013/12/31,0.8902 ,0.8902 , 2014/01/31,-10.7697 ,-10.7697 , 2014/02/28,5.1219 ,5.7474 , 2014/03/31,1.9953 ,1.9953 , 2014/04/30,9.9396 ,9.9396 , 2014/05/30,7.2718 ,7.8720 , 2014/06/30,2.7662 ,2.7662 , 2014/07/31,2.8731 ,2.8731 , 2014/08/29,7.2176 ,7.7509 , 2014/09/30,-1.7073 ,-1.7073 , 2014/10/31,7.1960 ,7.1960 , 2014/11/28,10.1204 ,10.5965 , 2014/12/31,-7.1891 ,-7.1891 , 2015/01/30,6.1424 ,6.1424 , 2015/02/27,9.6449 ,10.0746 , 2015/03/31,-3.1372 ,-3.1372 , 2015/04/30,0.5786 ,0.5786 , 2015/05/29,4.0991 ,4.5312 , |
# load the csv file with the header in the first row aapl <- read.table("AAPL.csv", header=T, sep=",") aapl |
Date Price.Return Total.Return 1 20061229 -7.4405 -7.4405 2 20070131 1.0490 1.0490 3 20070228 -1.3064 -1.3064 4 20070330 9.8097 9.8097 5 20070430 7.4158 7.4158 6 20070531 21.4339 21.4339 7 20070629 0.7005 0.7005 8 20070731 7.9646 7.9646 9 20070831 5.1002 5.1002 10 20070928 10.8247 10.8247 11 20071031 23.7701 23.7701 12 20071130 -4.0695 -4.0695 13 20071231 8.7038 8.7038 14 20080131 -31.6640 -31.6640 15 20080229 -7.6389 -7.6389 16 20080331 14.7816 14.7816 17 20080430 21.2195 21.2195 18 20080530 8.5082 8.5082 19 20080630 -11.2901 -11.2901 20 20080731 -5.0705 -5.0705 21 20080829 6.6562 6.6562 22 20080930 -32.9558 -32.9558 23 20081031 -5.3405 -5.3405 24 20081128 -13.8675 -13.8675 25 20081231 -7.8990 -7.8990 26 20090130 5.6005 5.6005 27 20090227 -0.9098 -0.9098 28 20090331 17.7024 17.7024 29 20090430 19.7013 19.7013 30 20090529 7.9313 7.9313 31 20090630 4.8745 4.8745 32 20090731 14.7160 14.7160 33 20090831 2.9500 2.9500 34 20090930 10.1896 10.1896 35 20091030 1.6995 1.6995 36 20091130 6.0531 6.0531 37 20091231 5.4134 5.4134 38 20100129 -8.8591 -8.8591 39 20100226 6.5380 6.5380 40 20100331 14.8470 14.8470 41 20100430 11.1021 11.1021 42 20100528 -1.6125 -1.6125 43 20100630 -2.0827 -2.0827 44 20100730 2.2741 2.2741 45 20100831 -5.5005 -5.5005 46 20100930 16.7215 16.7215 47 20101029 6.0722 6.0722 48 20101130 3.3790 3.3790 49 20101231 3.6670 3.6670 50 20110131 5.1959 5.1959 51 20110228 4.0935 4.0935 52 20110331 -1.3314 -1.3314 53 20110429 0.4656 0.4656 54 20110531 -0.6569 -0.6569 55 20110630 -3.4960 -3.4960 56 20110729 16.3285 16.3285 57 20110831 -1.4469 -1.4469 58 20110930 -0.9121 -0.9121 59 20111031 6.1523 6.1523 60 20111130 -5.5783 -5.5783 61 20111230 5.9655 5.9655 62 20120131 12.7111 12.7111 63 20120229 18.8311 18.8311 64 20120330 10.5284 10.5284 65 20120430 -2.5969 -2.5969 66 20120531 -1.0702 -1.0702 67 20120629 1.0853 1.0853 68 20120731 4.5822 4.5822 69 20120831 8.9200 9.3850 70 20120928 0.2803 0.2803 71 20121031 -10.7607 -10.7607 72 20121130 -1.6865 -1.2196 73 20121231 -9.0738 -9.0738 74 20130131 -14.4094 -14.4094 75 20130228 -3.0934 -2.5449 76 20130328 0.2855 0.2855 77 20130430 0.0271 0.0271 78 20130531 1.5708 2.2490 79 20130628 -11.8303 -11.8303 80 20130731 14.1225 14.1225 81 20130830 7.6649 8.3772 82 20130930 -2.1481 -2.1481 83 20131031 9.6386 9.6386 84 20131129 6.3838 7.0066 85 20131231 0.8902 0.8902 86 20140131 -10.7697 -10.7697 87 20140228 5.1219 5.7474 88 20140331 1.9953 1.9953 89 20140430 9.9396 9.9396 90 20140530 7.2718 7.8720 91 20140630 2.7662 2.7662 92 20140731 2.8731 2.8731 93 20140829 7.2176 7.7509 94 20140930 -1.7073 -1.7073 95 20141031 7.1960 7.1960 96 20141128 10.1204 10.5965 97 20141231 -7.1891 -7.1891 98 20150130 6.1424 6.1424 99 20150227 9.6449 10.0746 100 20150331 -3.1372 -3.1372 101 20150430 0.5786 0.5786 102 20150529 4.0991 4.5312 |
read.table()
for tab-separated files
Create the following monthly price and total return tab-separated file for Apple.
Date Price Return Total Return 2007/01/31 1.0490 1.0490 2007/02/28 -1.3064 -1.3064 2007/03/30 9.8097 9.8097 2007/04/30 7.4158 7.4158 2007/05/31 21.4339 21.4339 2007/06/29 0.7005 0.7005 2007/07/31 7.9646 7.9646 2007/08/31 5.1002 5.1002 2007/09/28 10.8247 10.8247 2007/10/31 23.7701 23.7701 2007/11/30 -4.0695 -4.0695 2007/12/31 8.7038 8.7038 2008/01/31 -31.6640 -31.6640 2008/02/29 -7.6389 -7.6389 2008/03/31 14.7816 14.7816 2008/04/30 21.2195 21.2195 2008/05/30 8.5082 8.5082 2008/06/30 -11.2901 -11.2901 2008/07/31 -5.0705 -5.0705 2008/08/29 6.6562 6.6562 2008/09/30 -32.9558 -32.9558 2008/10/31 -5.3405 -5.3405 2008/11/28 -13.8675 -13.8675 2008/12/31 -7.8990 -7.8990 2009/01/30 5.6005 5.6005 2009/02/27 -0.9098 -0.9098 2009/03/31 17.7024 17.7024 2009/04/30 19.7013 19.7013 2009/05/29 7.9313 7.9313 2009/06/30 4.8745 4.8745 2009/07/31 14.7160 14.7160 2009/08/31 2.9500 2.9500 2009/09/30 10.1896 10.1896 2009/10/30 1.6995 1.6995 2009/11/30 6.0531 6.0531 2009/12/31 5.4134 5.4134 2010/01/29 -8.8591 -8.8591 2010/02/26 6.5380 6.5380 2010/03/31 14.8470 14.8470 2010/04/30 11.1021 11.1021 2010/05/28 -1.6125 -1.6125 2010/06/30 -2.0827 -2.0827 2010/07/30 2.2741 2.2741 2010/08/31 -5.5005 -5.5005 2010/09/30 16.7215 16.7215 2010/10/29 6.0722 6.0722 2010/11/30 3.3790 3.3790 2010/12/31 3.6670 3.6670 2011/01/31 5.1959 5.1959 2011/02/28 4.0935 4.0935 2011/03/31 -1.3314 -1.3314 2011/04/29 0.4656 0.4656 2011/05/31 -0.6569 -0.6569 2011/06/30 -3.4960 -3.4960 2011/07/29 16.3285 16.3285 2011/08/31 -1.4469 -1.4469 2011/09/30 -0.9121 -0.9121 2011/10/31 6.1523 6.1523 2011/11/30 -5.5783 -5.5783 2011/12/30 5.9655 5.9655 2012/01/31 12.7111 12.7111 2012/02/29 18.8311 18.8311 2012/03/30 10.5284 10.5284 2012/04/30 -2.5969 -2.5969 2012/05/31 -1.0702 -1.0702 2012/06/29 1.0853 1.0853 2012/07/31 4.5822 4.5822 2012/08/31 8.9200 9.3850 2012/09/28 0.2803 0.2803 2012/10/31 -10.7607 -10.7607 2012/11/30 -1.6865 -1.2196 2012/12/31 -9.0738 -9.0738 2013/01/31 -14.4094 -14.4094 2013/02/28 -3.0934 -2.5449 2013/03/28 0.2855 0.2855 2013/04/30 0.0271 0.0271 2013/05/31 1.5708 2.2490 2013/06/28 -11.8303 -11.8303 2013/07/31 14.1225 14.1225 2013/08/30 7.6649 8.3772 2013/09/30 -2.1481 -2.1481 2013/10/31 9.6386 9.6386 2013/11/29 6.3838 7.0066 2013/12/31 0.8902 0.8902 2014/01/31 -10.7697 -10.7697 2014/02/28 5.1219 5.7474 2014/03/31 1.9953 1.9953 2014/04/30 9.9396 9.9396 2014/05/30 7.2718 7.8720 2014/06/30 2.7662 2.7662 2014/07/31 2.8731 2.8731 2014/08/29 7.2176 7.7509 2014/09/30 -1.7073 -1.7073 2014/10/31 7.1960 7.1960 2014/11/28 10.1204 10.5965 2014/12/31 -7.1891 -7.1891 2015/01/30 6.1424 6.1424 2015/02/27 9.6449 10.0746 2015/03/31 -3.1372 -3.1372 2015/04/30 0.5786 0.5786 2015/05/29 4.0991 4.5312 |
# load the tab-separated file with the header in the first row aapl <- read.table("AAPL.txt", header=T, sep="\t") aapl |
Date Price.Return Total.Return 1 2007/01/31 1.0490 1.0490 2 2007/02/28 -1.3064 -1.3064 3 2007/03/30 9.8097 9.8097 4 2007/04/30 7.4158 7.4158 5 2007/05/31 21.4339 21.4339 6 2007/06/29 0.7005 0.7005 7 2007/07/31 7.9646 7.9646 8 2007/08/31 5.1002 5.1002 9 2007/09/28 10.8247 10.8247 10 2007/10/31 23.7701 23.7701 11 2007/11/30 -4.0695 -4.0695 12 2007/12/31 8.7038 8.7038 13 2008/01/31 -31.6640 -31.6640 14 2008/02/29 -7.6389 -7.6389 15 2008/03/31 14.7816 14.7816 16 2008/04/30 21.2195 21.2195 17 2008/05/30 8.5082 8.5082 18 2008/06/30 -11.2901 -11.2901 19 2008/07/31 -5.0705 -5.0705 20 2008/08/29 6.6562 6.6562 21 2008/09/30 -32.9558 -32.9558 22 2008/10/31 -5.3405 -5.3405 23 2008/11/28 -13.8675 -13.8675 24 2008/12/31 -7.8990 -7.8990 25 2009/01/30 5.6005 5.6005 26 2009/02/27 -0.9098 -0.9098 27 2009/03/31 17.7024 17.7024 28 2009/04/30 19.7013 19.7013 29 2009/05/29 7.9313 7.9313 30 2009/06/30 4.8745 4.8745 31 2009/07/31 14.7160 14.7160 32 2009/08/31 2.9500 2.9500 33 2009/09/30 10.1896 10.1896 34 2009/10/30 1.6995 1.6995 35 2009/11/30 6.0531 6.0531 36 2009/12/31 5.4134 5.4134 37 2010/01/29 -8.8591 -8.8591 38 2010/02/26 6.5380 6.5380 39 2010/03/31 14.8470 14.8470 40 2010/04/30 11.1021 11.1021 41 2010/05/28 -1.6125 -1.6125 42 2010/06/30 -2.0827 -2.0827 43 2010/07/30 2.2741 2.2741 44 2010/08/31 -5.5005 -5.5005 45 2010/09/30 16.7215 16.7215 46 2010/10/29 6.0722 6.0722 47 2010/11/30 3.3790 3.3790 48 2010/12/31 3.6670 3.6670 49 2011/01/31 5.1959 5.1959 50 2011/02/28 4.0935 4.0935 51 2011/03/31 -1.3314 -1.3314 52 2011/04/29 0.4656 0.4656 53 2011/05/31 -0.6569 -0.6569 54 2011/06/30 -3.4960 -3.4960 55 2011/07/29 16.3285 16.3285 56 2011/08/31 -1.4469 -1.4469 57 2011/09/30 -0.9121 -0.9121 58 2011/10/31 6.1523 6.1523 59 2011/11/30 -5.5783 -5.5783 60 2011/12/30 5.9655 5.9655 61 2012/01/31 12.7111 12.7111 62 2012/02/29 18.8311 18.8311 63 2012/03/30 10.5284 10.5284 64 2012/04/30 -2.5969 -2.5969 65 2012/05/31 -1.0702 -1.0702 66 2012/06/29 1.0853 1.0853 67 2012/07/31 4.5822 4.5822 68 2012/08/31 8.9200 9.3850 69 2012/09/28 0.2803 0.2803 70 2012/10/31 -10.7607 -10.7607 71 2012/11/30 -1.6865 -1.2196 72 2012/12/31 -9.0738 -9.0738 73 2013/01/31 -14.4094 -14.4094 74 2013/02/28 -3.0934 -2.5449 75 2013/03/28 0.2855 0.2855 76 2013/04/30 0.0271 0.0271 77 2013/05/31 1.5708 2.2490 78 2013/06/28 -11.8303 -11.8303 79 2013/07/31 14.1225 14.1225 80 2013/08/30 7.6649 8.3772 81 2013/09/30 -2.1481 -2.1481 82 2013/10/31 9.6386 9.6386 83 2013/11/29 6.3838 7.0066 84 2013/12/31 0.8902 0.8902 85 2014/01/31 -10.7697 -10.7697 86 2014/02/28 5.1219 5.7474 87 2014/03/31 1.9953 1.9953 88 2014/04/30 9.9396 9.9396 89 2014/05/30 7.2718 7.8720 90 2014/06/30 2.7662 2.7662 91 2014/07/31 2.8731 2.8731 92 2014/08/29 7.2176 7.7509 93 2014/09/30 -1.7073 -1.7073 94 2014/10/31 7.1960 7.1960 95 2014/11/28 10.1204 10.5965 96 2014/12/31 -7.1891 -7.1891 97 2015/01/30 6.1424 6.1424 98 2015/02/27 9.6449 10.0746 99 2015/03/31 -3.1372 -3.1372 100 2015/04/30 0.5786 0.5786 101 2015/05/29 4.0991 4.5312 |
names()
Show the column names.
names(aapl) |
[1] "Date" "Price.Return" "Total.Return" |
subset()
Extract data which meet specified criteria.
# Extract months with (monthly total return) <= -10 aapl_d <- subset(aapl,aapl[,3]<=-10) aapl_d |
Date Price.Return Total.Return 13 2008/01/31 -31.6640 -31.6640 18 2008/06/30 -11.2901 -11.2901 21 2008/09/30 -32.9558 -32.9558 23 2008/11/28 -13.8675 -13.8675 70 2012/10/31 -10.7607 -10.7607 73 2013/01/31 -14.4094 -14.4094 78 2013/06/28 -11.8303 -11.8303 85 2014/01/31 -10.7697 -10.7697 |
# Extract months with (monthly total return) >= +10 aapl_u <- subset(aapl,aapl[,3]>=+10) aapl_u |
Date Price.Return Total.Return 5 2007/05/31 21.4339 21.4339 9 2007/09/28 10.8247 10.8247 10 2007/10/31 23.7701 23.7701 15 2008/03/31 14.7816 14.7816 16 2008/04/30 21.2195 21.2195 27 2009/03/31 17.7024 17.7024 28 2009/04/30 19.7013 19.7013 31 2009/07/31 14.7160 14.7160 33 2009/09/30 10.1896 10.1896 39 2010/03/31 14.8470 14.8470 40 2010/04/30 11.1021 11.1021 45 2010/09/30 16.7215 16.7215 55 2011/07/29 16.3285 16.3285 61 2012/01/31 12.7111 12.7111 62 2012/02/29 18.8311 18.8311 63 2012/03/30 10.5284 10.5284 79 2013/07/31 14.1225 14.1225 95 2014/11/28 10.1204 10.5965 98 2015/02/27 9.6449 10.0746 |
No comments:
Post a Comment