nepse_daily: Nepal Stock Exchange Daily Stock Quote

Description Usage Arguments Details Value Author(s) References Examples

View source: R/nepse_daily.R

Description

nepse_daily downloads the daily stock quote from the Nepal Stock Exchange.

Usage

1

Arguments

symbol

a character string naming the symbol of stock to be loaded

date

date expressed in ISO CCYY-MM-DD format (e.g., "2015-07-08"). The data is not available for the date prior to "2010-05-09".

Details

The nepse_daily downloads the daily stock quote for a given stock symbol and given date from Nepal Stock Exchange. The nepse_daily will first check whether the entered symbol is the valid stock symbol by looking through all stocks symbols listed in NEPSE. The nepse_daily will issue an error with message if symbol is invalid but date is in valid format. It will also issue an error with message if symbol is valid but date is not in valid format. If the date is in valid format, it must not be less than "2010-05-09".

Value

nepse_daily will return the object of class dataframe with 10 variables: daily_date, stock_symbol, transaction_no, max_price, min_price, closing_price, traded_shares, amount, previous_closing, and difference

Author(s)

Nayan Krishna Joshi

References

http://www.nepalstock.com.np/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
## Not run: 

# daily stock quote for an invalid stock symbol JOSHI and valid date; returns an
# error with message nepse_daily('JOSHI','2015-07-08')

# daily stock quote for a valid stock symbol HBL and an invalid date; returns an
# error with message nepse_daily('HBL','2015-07')

# daily stock quote for an invalid stock symbol JOSHI and an invalid date;
# returns an error with message nepse_daily('JOSHI','2015-07')

# daily stock quote for a valid stock symbol HBL and a valid date; returns a
# dataframe with non-NA values
nepse_daily("HBL", "2015-07-08")

# daily stock quote for a valid stock symbol HBL and valid dates; returns a
# dataframe with non-NA values
dates_list <- c("2015-07-08", "2015-07-09")
data_daily1 <- do.call(rbind, lapply(dates_list, function(dates) {
  nepse_daily("HBL", dates)
}))

# daily stock quote for valid stock symbols HBL and ADBL and a valid date;
# returns a dataframe with non-NA values
stocks_list <- c("HBL", "ADBL")
data_daily2 <- do.call(rbind, lapply(stocks_list, function(stocks) {
  nepse_daily(stocks, "2015-07-08")
}))

# daily stock quote for valid stock symbols HBL for '2015-07-08' and ADBL for
# '2015-07-09' ; returns a dataframe with non-NA values stocks_list and
# dates_list same as above
data_daily3 <- do.call(rbind, Map(function(stocks, dates) {
  nepse_daily(stocks, dates)
}, stocks_list, dates_list))

# draw an interactive time series chart of closing price for a stock symbol HBL
# for March, 2015
dates_march2015 <- as.character(
  seq.Date(from = as.Date("2015-03-01"), to = as.Date("2015-03-31"),
                                         by = 1))
data_daily4 <- do.call(rbind, lapply(dates_march2015, function(dates) {
  nepse_daily("HBL", dates)
}))
data_daily5 <- data_daily4[
  complete.cases(data_daily4), c("daily_date", "closing_price")]
# NA for non-traded days
require(xts)
require(dygraphs)
data_daily5 <- xts(data_daily5[, -1], order.by = data_daily5[, 1])
graph_daily <- dygraph(data_daily5[, 1],
                       main = "Time series graph of HBL for Month of March, 2015")
dyRangeSelector(graph_daily, height = 20, strokeColor = "darkred")


# compute daily, weekly, monthly, quartely, and yearly returns of closing price
# for a stock symbol HBL for March, 2015
require(xts)
require(quantmod)
# data_daily5 : xts object same as above arithmetic returns
return_daily_re_arithm <- allReturns(data_daily5)
# logarithmic returns
return_daily_re_log <- allReturns(data_daily5, type = "log")

## End(Not run)

nayanj/NPdata documentation built on May 23, 2019, 12:24 p.m.