-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
102 lines (76 loc) · 3.59 KB
/
README.Rmd
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
output: github_document
always_allow_html: true
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# PSEIpullr
<!-- badges: start -->
<!-- badges: end -->
PSEIpullr is used to pull stock prices of companies listed in the Philippine Stock Exchange via the pselookup API as well as to track portfolio performance. This project was inspired by the lack of available package(s) that can be used to efficiently pull local stock prices.
Massive thanks to Vrymel for maintaining the API. Interested parties can visit his/her website at https://pselookup.vrymel.com/about.
Disclaimer: As the package uses a third-party API, PSEIpullr cannot guarantee data accuracy pulled by the package. PSEIpullr also makes no warranties, representations, statements, or guarantees (whether express, implied in law or residual) regarding the package. The output of the package is simply for monitoring purposes and is not intended to provide investment advice.
## Installation
You can install the released version of PSEIpullr from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("PSEIpullr")
```
## Example
This is a basic example showing how to pull price of stocks listed in the Philippine Stock Exchange:
```{r example}
library(PSEIpullr)
system.time(
ac <- pull_historical_price(ticker = "AC",
type = "close",
start_date = "2020-01-01",
end_date = "2020-02-01")
)
head(ac)
```
The next function allows for a simplified way of pulling multiple stock prices:
```{r}
system.time(
multi_stock <- pull_multiple_prices(tickers = c("AC", "SM"),
type = "close",
start_date = "2020-01-01",
end_date = "2020-12-28")
)
head(multi_stock)
```
The package also allows for basic portfolio construction, analysis, and plotting. Start by setting up a position using the position_tracker() function before combining both positions with portfolio_tracker() to create a basic portfolio data set. portfolio_tracker() performs basic analysis on this data frame for easy plotting but can also return the raw combined data for additional analysis.
```{r}
tictoc::tic()
ac <- position_tracker(deposit = 1000000,
ticker = "AC",
start_date = "2020-01-02",
shares = 1200,
buying_price = 770,
industry = "Conglomerate",
listing = "Index",
selling_price = 823,
selling_date = "2020-11-30")
sm <- position_tracker(deposit = 1000000,
ticker = "SM",
start_date = "2020-04-30",
shares = 1300,
buying_price = 746,
industry = "Conglomerate",
listing = "Index",
selling_price = 1050,
selling_date = "2020-12-28")
tictoc::toc()
basic.port <- portfolio_tracker(ac, sm, summarized=TRUE)
head(basic.port)
```
The plot_performance() function allows quick plotting of the summarized portfolio data set.
```{r, warning=FALSE, echo=TRUE, eval=FALSE}
plot_performance(basic.port)
```
[![port-track.png](https://i.postimg.cc/YSdPDZMj/port-track.png)](https://postimg.cc/FfJG7PfQ)