Skip to content

Commit

Permalink
Restructure vnquant project according modules
Browse files Browse the repository at this point in the history
  • Loading branch information
phamdinhkhanh committed Jun 3, 2022
1 parent f5f88c5 commit 7316e5b
Show file tree
Hide file tree
Showing 13 changed files with 419 additions and 229 deletions.
90 changes: 28 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# vnquant package

<img src="./vnquant/img/stock_1.png" style="display: block;margin-left: auto;margin-right: auto;width:50%;" />
<img src="./vnquant/imgs/stock_1.png" style="display: block;margin-left: auto;margin-right: auto;width:50%;" />

## 0. NOTE
Note: Currently, prices on VnDirect source are supported again. There are two options data source for you:
Expand Down Expand Up @@ -31,8 +31,8 @@ from version 0.0.2 vnquant enable to you visualize stock price from any symbols
Below is general syntax of visualization function supported on vnquant package.

```{python}
from vnquant import Plot
Plot._vnquant_candle_stick(data,
import vnquant.plot as pl
pl._vnquant_candle_stick(data,
title=None,
xlab='Date', ylab='Price',
start_date=None, end_date=None,
Expand Down Expand Up @@ -61,33 +61,33 @@ in case symbol, data is automatically cloned from open source.

In this way, you can visualize stock price clone from VND or CAFE source by pass symbol, start_date, end_date into module as below:
```{python}
from vnquant import Plot
Plot._vnquant_candle_stick(data='VND',
from vnquant import pl
pl._vnquant_candle_stick(data='VND',
title='VND stock price data and volume from 2019-09-01 to 2019-11-01',
xlab='Date', ylab='Price',
start_date='2019-09-01',
end_date='2019-11-01',
show_vol=True)
```

<img src="./vnquant/img/stock_2.png" style="display: block;margin-left: auto;margin-right: auto;width:50%;" />
<img src="./vnquant/imgs/stock_2.png" style="display: block;margin-left: auto;margin-right: auto;width:50%;" />

You can suppress volume by set up show_vol=False. Result as below:

<img src="./vnquant/img/stock_3.png" style="display: block;margin-left: auto;margin-right: auto;width:50%;" />
<img src="./vnquant/imgs/stock_3.png" style="display: block;margin-left: auto;margin-right: auto;width:50%;" />

### 3.2. Visualization from data frame
Data frame must be OHLC or OHLCV type. OHLC type when it includes ['open','high','low','close'] and OHLCV is ['open','high','low','close','volume']. In case your data frame have columns with the same function, you should accordingly rename its.

```{python}
from vnquant import Plot
Plot._vnquant_candle_stick(data = data_vnd,
from vnquant import pl
pl._vnquant_candle_stick(data = data_vnd,
title='Your data',
ylab='Date', xlab='Price',
show_vol=True)
```

<img src="./vnquant/img/stock_4.png" style="display: block;margin-left: auto;margin-right: auto;width:50%;" />
<img src="./vnquant/imgs/stock_4.png" style="display: block;margin-left: auto;margin-right: auto;width:50%;" />

To check whether data_vnd frame is OHLC or OHLCV type you can try:

Expand All @@ -102,9 +102,9 @@ Return `True` mean data frame is adapted types.
## 4. Clone Stock Prices: (0.0.1)
You can load the prices of one or more stocks in specific time interval according to syntax as below.
```{python}
from vnquant.DataLoader import DataLoader
import vnquant.data as dt
DataLoader(symbols="VND",
dt.DataLoader(symbols="VND",
start="2018-01-10",
end="2018-02-15",
minimal=True,
Expand All @@ -121,8 +121,8 @@ for example `volumn_reconcile, volumn_match,...`

### 4.1. Clone one stock:
```{python}
import vnquant.DataLoader as web
loader = web.DataLoader('VND', '2018-02-02','2018-04-02')
import vnquant.data as dt
loader = dt.DataLoader('VND', '2018-02-02','2018-04-02')
data = loader.download()
data.head()
```
Expand Down Expand Up @@ -208,7 +208,7 @@ data.head()
### 4.2. Clone more stocks:
We need to set up symbols as a list.
```{python}
loader = web.DataLoader(symbols=["VND", "VCB"], start="2018-01-10", end="2018-02-15", minimal=True, data_source="cafe")
loader = dt.DataLoader(symbols=["VND", "VCB"], start="2018-01-10", end="2018-02-15", minimal=True, data_source="cafe")
data = loader.download()
data.head()
```
Expand Down Expand Up @@ -336,7 +336,7 @@ data.head()
### 4.3. Clone full information:
To get more the others information about `volume` and `value` beside basical fields, we need to declare `minimal=False` (default `True`).
```{python}
loader = web.DataLoader(symbols=["VND"], start="2018-01-10", end="2018-02-15", minimal=False)
loader = dt.DataLoader(symbols=["VND"], start="2018-01-10", end="2018-02-15", minimal=False)
data = loader.download()
data.head()
```
Expand Down Expand Up @@ -456,11 +456,11 @@ kindly comment and send me feed back to implement my project.

# 5. Get finance, cashflow, business and basic index reports (0.0.3)

In version 0.0.3 you can download finance, cashflow, business and basic index reports with class `vnquant.DataLoader.FinanceLoader`. Currently, we only support you clone one symbol per each time. To use this class you import as bellow:
In version 0.0.3 you can download finance, cashflow, business and basic index reports with class `vnquant.data.FinanceLoader`. Currently, we only support you clone one symbol per each time. To use this class you import as bellow:

```
import vnquant.DataLoader as dl
loader = dl.FinanceLoader(symbol = 'VND',
import vnquant.data as dt
loader = dt.FinanceLoader(symbol = 'VND',
start = '2019-06-02',
end = '2021-12-31')
```
Expand All @@ -475,8 +475,8 @@ loader = dl.FinanceLoader(symbol = 'VND',
Function `get_finan_report()` will help you get these finance indexes. For example:

```
import vnquant.DataLoader as dl
loader = dl.FinanceLoader('VND', '2019-06-02','2021-12-31')
import vnquant.data as dt
loader = dt.FinanceLoader('VND', '2019-06-02','2021-12-31')
data_finan = loader.get_finan_report()
data_finan.head()
```
Expand Down Expand Up @@ -576,8 +576,8 @@ data_finan.head()
To get business report of each symbol, you use `get_business_report()` function as below:

```
import vnquant.DataLoader as dl
loader = dl.FinanceLoader('VND', '2019-06-02','2021-12-31', data_source='VND', minimal=True)
import vnquant.data as dt
loader = dt.FinanceLoader('VND', '2019-06-02','2021-12-31', data_source='VND', minimal=True)
data_bus = loader.get_business_report()
data_bus.head()
```
Expand Down Expand Up @@ -679,8 +679,8 @@ data_bus.head()
Function `get_cashflow_report()` shall support to clone cashflow report:

```
import vnquant.DataLoader as dl
loader = dl.FinanceLoader('VND', '2019-06-02','2021-12-31', data_source='VND', minimal=True)
import vnquant.data as dt
loader = dt.FinanceLoader('VND', '2019-06-02','2021-12-31', data_source='VND', minimal=True)
data_cash = loader.get_cashflow_report()
data_cash.head()
```
Expand Down Expand Up @@ -774,8 +774,8 @@ data_cash.head()
This function provide to you basic and important index of each symbol such as: `ROA, ROE, Net Profit Marget, Net Revenue Growth, Profit After tax Growth`

```
import vnquant.DataLoader as dl
loader = dl.FinanceLoader('VND', '2019-06-02','2021-12-31', data_source='VND', minimal=True)
import vnquant.data as dt
loader = dt.FinanceLoader('VND', '2019-06-02','2021-12-31', data_source='VND', minimal=True)
data_basic = loader.get_basic_index()
data_basic.head()
```
Expand Down Expand Up @@ -819,38 +819,4 @@ data_basic.head()
<td>0.033224</td>
</tr>
</tbody>
</table>


































</table>
36 changes: 21 additions & 15 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
# 1. Test data loader
import vnquant.DataLoader as dl
loader = dl.DataLoader('E1VFVN30', '2018-02-02','2018-04-02', data_source='VND', minimal=True)
data = loader.download()
print(data.head())
# # 1. Test data loader
# import vnquant.data as dt
# loader = dt.DataLoader('E1VFVN30', '2021-02-01','2021-04-02', data_source='VND', minimal=True)
# data = loader.download()
# print(data)

# 2. Test clone finance
# import vnquant.DataLoader as dl
# loader = dl.FinanceLoader('VND', '2019-06-02','2021-12-31', data_source='VND', minimal=True)
# # 2. Test clone finance
# import vnquant.data as dt
# loader = dt.FinanceLoader('VND', '2019-06-02','2021-12-31', data_source='VND', minimal=True)
# data_business = loader.get_business_report()
# print(data_business.head())
# data_business.head().to_html('data_business.html')

# import vnquant.DataLoader as dl
# loader = dl.FinanceLoader('VND', '2019-06-02','2021-12-31', data_source='VND', minimal=True)
# import vnquant.data as dt
# loader = dt.FinanceLoader('VND', '2019-06-02','2021-12-31', data_source='VND', minimal=True)
# data_finan = loader.get_finan_report()
# print(data_finan.head())
# data_finan.head().to_html('data_finan.html')


# import vnquant.DataLoader as dl
# loader = dl.FinanceLoader('VND', '2019-06-02','2021-12-31', data_source='VND', minimal=True)
# import vnquant.data as dt
# loader = dt.FinanceLoader('VND', '2019-06-02','2021-12-31', data_source='VND', minimal=True)
# data_cash = loader.get_cashflow_report()
# print(data_cash.head())
# data_cash.head().to_html('data_cashflow.html')

# import vnquant.DataLoader as dl
# loader = dl.FinanceLoader('VND', '2019-06-02','2020-12-31', data_source='VND', minimal=True)
# import vnquant.data as dt
# loader = dt.FinanceLoader('VND', '2019-06-02','2020-12-31', data_source='VND', minimal=True)
# data_basic = loader.get_basic_index()
# print(data_basic.head())
# data_basic.head().to_html('data_basic.html')
# data_basic.head().to_html('data_basic.html')

# import vnquant.plot as pl
# pl._vnquant_candle_stick_source('VND', '2019-09-01', '2019-11-01', show_vol=False)

# from vnquant import utils
# print(utils._isOHLC)
5 changes: 4 additions & 1 deletion vnquant/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
__version__ = '0.0.3'
# Copyright (c) general_backbone. All rights reserved.
from .utils import *
from .data import *
from .plot import *
2 changes: 2 additions & 0 deletions vnquant/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (c) general_backbone. All rights reserved.
__version__ = '0.0.3'
24 changes: 24 additions & 0 deletions vnquant/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) general_backbone. All rights reserved.
# from .configs import USER_AGENTS, URL_VND, URL_CAFE, HEADERS

# Copyright (c) general_backbone. All rights reserved.
# Can be used to randomize and rotate
# Source(s):
# - https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome

USER_AGENTS = [
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 12_3_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36"
]

# Config for DataLoader
URL_VND = 'https://www.vndirect.com.vn/portal/thong-ke-thi-truong-chung-khoan/lich-su-gia.shtml'
URL_CAFE = "http://s.cafef.vn/Lich-su-giao-dich-"
HEADERS = {'content-type': 'application/x-www-form-urlencoded', 'User-Agent': 'Mozilla'}

__all__ = [
'USER_AGENTS', 'URL_VND', 'URL_CAFE', 'HEADERS'
]
12 changes: 12 additions & 0 deletions vnquant/configs/configs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) general_backbone. All rights reserved.
# Can be used to randomize and rotate
# Source(s):
# - https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome

USER_AGENTS = [
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 12_3_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36"
]
6 changes: 6 additions & 0 deletions vnquant/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) general_backbone. All rights reserved.
from .dataloader import *
from .finance import *
__all__ = [
'DataLoader', 'FinanceLoader'
]
Loading

0 comments on commit 7316e5b

Please sign in to comment.