23 February 2016

Simple way to download and export stock data using R - Method 3


you can read the method 1 here: http://www.iamsulthan.in/2016/04/step-by-step-tutorial-to-download.html If you have missed it.

In Security analysis and Portfolio management , the historical prices of a stock or indices is the base data for analysis in that case any researcher want to download and organize the data. Mostly they prefer to save the data in .csv file which is universally imported in any software. A difficulty or time consuming task for such researchers is to organize the data. for example: to check for any missing prices or to organize the closing prices in single worksheet for all companies in case of a multivariate analysis.

Using the following code you can download and export the data to .csv format which can be later used in any other data analysis softwares if you wish whereas R can do almost what other softwares do . It just need proper command to execute your research objectives.



Github link for the code can be located here: download-historical-stock-data-in-R

Use the following code:

========================================================================

####Using quantmod####
####Single Stock data####
if(!require(quantmod)){install.packages("quantmod")}
getSymbols("WIPRO.NS", from="2015-01-01", to= Sys.Date())

#### multiple Stocks data Method-1 (each as seperate dataset) ####
getSymbols("WIPRO.NS;TCS.NS;INFY.NS", from="2015-01-01", to= Sys.Date())

#### multiple Stocks Method-2 (using list)####
stocklist <- c("WIPRO.NS","TCS.NS","INFY.NS","AAPL" )
getSymbols(stocklist, from="2015-01-01", to= Sys.Date())

####multiple Stocks Method-3####
stocklist <- c("WIPRO.NS","TCS.NS","INFY.NS","AAPL") # create list of stock tickers
Adjclose <- NULL
for (Ticker in stocklist)
  Adjclose <- cbind(Adjclose,getSymbols.yahoo(Ticker, from="2015-01-01", to= Sys.Date(), verbose=FALSE, auto.assign=FALSE)[,6]) #get data for companies in list, [,6] = keep the adjusted prices
FinalAdjclose <- na.locf(Adjclose) #copy last traded price in empty cell
FinalAdjclose1 <- Adjclose[apply(Adjclose,1,function(x) all(!is.na(x))),] #keep only dates having closing price
####Export the data to excel####
if(!require(timeSeries)){install.packages("timeSeries")}
data <- as.timeSeries(FinalAdjclose1)
write.csv(data, "data.csv")
========================================================================

22 February 2016

Why R? Pros and Con


R is a open source programming software for statistical computing and graphics. You can download and install R in any platform either it may be Windows, Mac or Linux. the free and official download of the software can be done in the following link https://cran.r-project.org/ .

Installed R then its always recommended to use a IDE for R. there are few good IDE for R most of them are open source and you can find it at no cost. My best choice and I hope most agree with me that RStudio is the best IDE for R programming. you can download the RStudio using the link : https://www.rstudio.com/

Pros of using R:

1. Suits for statistical analysis: The environment in R is well suited for statistical analysis and it does handle big data quiet fast and ease.
2. open source and cross platforms: R is open source and do work in cross platforms. regardless of any OS whether it may be in Windows, Mac or Linux(debian, redhat, suse, ubuntu).
3. add-ons: This is the important reason that I recommend using R. researcher around the globe develop and distribute the packages in CRAN (Comprehensive R Archive Network). two useful websites where you find addons are here:
                                    Comprehensive R Archive Network                                   Crantastic
these networks grow very fast and The packages number are increasing day by day. 
4. Flexibility: Because R is programmed by users the package is very flexible and when you make use of the available scripts it will save you a huge time .

Con of using R

1.Minimal GUI: you cant simply say that R is completely command based. there are few GUI that makes analysis easy. (for ex: Rcmdr). people used to work with GUI will find it hard when the task is to be done in command based environment.


Over all I would say that for researchers who are interested in exploring the data will feel R as very helpful and It can help you to develop your ideas in to package and share it with CRAN which makes your research significant among the users. 

16 February 2016

Tips on Night reading / to avoid strain in eyes

I read pdf daily it would be a Journal, Book, report , Encyclopedia and/or etc.., The problem I face while reading pdf in my laptop or tablet is that my eyes feels strain very soon after reading quite for sometime. The reason for this because of the white background in the pages of pdf file. So, here I got some tips to modify your settings in adobe reader which will help your eyes from getting strained. Follow the procedures below.

1. Default look of a pdf in Adobe reader


2. go to Edit> preferences 


3. In custom color by default the Page background will be White and Document Text will be Black


4. Change the page background to black and Document text to white


5. there u can see the change and its better now for yours eyes and you can keep reading for long time without strain on your eyes.


Note: after the change the images in the pdf may not look the same it may disappear because of setting and when you reset the settings you can have a look at images in pdf.