Skip to content

Commit

Permalink
Commit Beta to Main (thinh-vu#38)
Browse files Browse the repository at this point in the history
* Update README

* functions & documentation updated

* Delete vnstock_demo_index_all_functions_testing_2023_06_07.ipynb

* demo file updated
  • Loading branch information
thinh-vu authored Jun 29, 2023
1 parent 67b5f79 commit 35919e3
Show file tree
Hide file tree
Showing 5 changed files with 1,787 additions and 1,605 deletions.
53 changes: 40 additions & 13 deletions README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,13 @@ df = stock_historical_data(symbol='GMD',
resolution='1D')
print(df.head())
```
- New: The resolution parameter can accept the following values: 1D (default, 1 day), '1' (1 minute), 15 (15 minutes), 30 (30 minutes), '1H' (1 hour).
- New:
- The resolution parameter can accept the following values: 1D (default, 1 day), '1' (1 minute), 15 (15 minutes), 30 (30 minutes), '1H' (1 hour).
- The `type = 'stock'` parameter allows retrieving price data for stock symbols. The `type = 'index'` parameter allows retrieving price data for index codes. Supported index codes include: VNINDEX, VN30, HNX, HNX30, UPCOM, VNXALLSHARE, VN30F1M, VN30F2M, VN30F1Q, VN30F2Q.

- You can also use a shorter function format as shown below, which applies to all functions as long as the parameters are entered in the correct order:

- Retrieve historical data of a stock code.
```python
df = stock_historical_data("GMD", "2021-01-01", "2022-02-25", "1D")
print(df.head())
Expand All @@ -147,9 +151,14 @@ The result should look like this:
1 2021-01-05 32279.0 33596.0 31938.0 32962.0 4851900
2 2021-01-06 33352.0 33352.0 32279.0 32572.0 3641300
```

</details>

- Retrieve historical data of an index code.
```python
df = stock_historical_data("VNINDEX", "2021-01-01", "2022-02-25", "1D", 'index')
print(df)
```

## 2.4. 📊 Price Table
You can download the price board of a target list of stocks to analyze with ease compared to viewing it directly on TCBS.

Expand Down Expand Up @@ -191,26 +200,44 @@ vnstock allows the user to **download intraday real-time/historical data**. In
the example presented below, you can see the intraday historical data from the last weekday of the current week.

```python
df = stock_intraday_data(symbol='GMD',
page_num=0,
page_size=100)
print(df.head())
df = stock_intraday_data(symbol='TCB',
page_size=500)
print(df)
```

<details>
<summary>Output</summary>
<summary>Terminal output</summary>

```{r, engine='python', count_lines}
p volume cp rcp a ba sa hl pcp time
0 50700.0 169700 0.0 0.0 0.0 0.0 True 0.0 14:45:08
1 50800.0 1000 0.0 0.0 BU 0.0 0.0 False 0.0 14:30:05
2 50800.0 500 0.0 0.0 BU 0.0 0.0 False 0.0 14:30:05
3 50800.0 20000 0.0 0.0 BU 0.0 0.0 True 0.0 14:29:54
4 50700.0 300 0.0 0.0 SD 0.0 0.0 False 0.0 14:29:53
>>> stock_intraday_data('TCB', 500)
ticker time orderType investorType volume averagePrice orderCount
0 TCB 14:29:55 Sell Down SHEEP 1000 32700.0 1
1 TCB 14:29:47 Buy Up SHEEP 200 32750.0 1
2 TCB 14:29:44 Sell Down WOLF 8000 32700.0 14
3 TCB 14:29:41 Sell Down SHEEP 1000 32700.0 5
4 TCB 14:29:36 Sell Down WOLF 23800 32700.0 10
```

</details>

<details>
<summary>Glossary</summary>

- When a large order (from Sharks, big players, organizations, etc.) is actively placed for buying or selling on the Exchange, it typically gets matched with multiple small orders awaiting execution (buy or sell). If we only observe real-time individual matched orders, it becomes difficult to detect the entry of large orders (from Sharks, big players, etc.) that have just been pushed into the Exchange. Therefore, we "accumulate" these matched orders (resulting from a large active order being placed on the Exchange within a very short period) to help investors identify large orders (from Sharks, big players, etc.) more accurately. Shark orders are highlighted in green (for active buying) and red (for active selling).

- Sharks (CM) refer to large investors, institutions, or market leaders who have a significant influence on the market. The value of an order is greater than 1 billion Vietnamese dong per order. The 1-minute chart reflects the last 60 minutes of data, the 1-week chart summarizes data every 15 minutes for one week, and the 1-month chart aggregates daily data for one month.

- Wolves (SG) refer to experienced investors with relatively high-value orders. The value of an order ranges from 200 million to 1 billion Vietnamese dong per order.

- Sheep (CN) refer to small retail investors with low-value transactions and low active buying or selling. The value of a Buy or Sell active order is less than 200 million Vietnamese dong per order.

- Active buying (or Buy Up) occurs when an investor proactively places a buy order at the best ask price to match immediately. As a result, the matched price for this order typically pushes the price higher than the previous market price.

- Active selling (or Sell Down) occurs when an investor proactively places a sell order below the current price (or market price) of the stock, matching it immediately with the best bid price. Consequently, the market price is pulled down lower than the previous market price. Analyzing the volume of Buy Up and Sell Down transactions helps evaluate the relationship between supply (Sell Down) and demand (Buy Up) in actual matched order transactions, providing a relative assessment of money flow trends. When the percentage of Buy Up transactions compared to the total of Buy Up and Sell Down transactions is greater than 50%, it indicates that the market is inclined towards more buying than selling, and vice versa. This helps determine the money flow in and out of each stock. When this percentage undergoes a sudden significant change (>70% or <30%) compared to the equilibrium point (50%), it signals market buying or selling regardless of other factors.

</details>

## 2.6. 💰Financial Ratio
### 2.6.1. Report from SSI

Expand Down
64 changes: 45 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,20 @@ vnstock cho phép người dùng **tải xuống dữ liệu lịch sử giao d
```python
df = stock_historical_data(symbol='GMD',
start_date="2021-01-01",
end_date='2022-02-25', resolution='1D')
print(df.head())
end_date='2022-02-25', resolution='1D', type='stock')
print(df)
```
- Mới: Giá trị mà tham số `resolution` có thể nhận là `1D` (mặc định, 1 ngày), '1' (1 phút), 15 (15 phút), 30 (30 phút), '1H' (hàng giờ).
- Mới:
- Giá trị mà tham số `resolution` có thể nhận là `1D` (mặc định, 1 ngày), '1' (1 phút), 15 (15 phút), 30 (30 phút), '1H' (hàng giờ).
- `type = 'stock'` cho phép lấy dữ liệu giá của mã cổ cổ phiếu, `type = 'index'` cho phép lấy dữ liệu giá của mã chỉ số. Các mã chỉ số hỗ trợ bao gồm: VNINDEX, VN30, HNX, HNX30, UPCOM, VNXALLSHARE, VN30F1M, VN30F2M, VN30F1Q, VN30F2Q

Bạn cũng có thể viết hàm theo dạng rút gọn như dưới đây, điều này đúng với tất cả các hàm, miễn là thông số được nhập vào đúng thứ tự:

```python
df = stock_historical_data("GMD", "2021-01-01", "2022-02-25", "1D")
print(df.head())
```
- Lấy dữ liệu lịch sử cổ phiếu
```python
df = stock_historical_data("GMD", "2021-01-01", "2022-02-25", "1D", 'stock')
print(df)
```
Và đây là kết quả

<details>
Expand All @@ -128,6 +131,12 @@ Và đây là kết quả
2 2021-01-06 33352.0 33352.0 32279.0 32572.0 3641300
```

- Lấy dữ liệu lịch sử của mã chỉ số
```python
df = stock_historical_data("VNINDEX", "2021-01-01", "2022-02-25", "1D", 'index')
print(df)
```

</details>

## 2.4. 📊 Bảng giá
Expand Down Expand Up @@ -167,29 +176,46 @@ price_board('TCB,SSI,VND')
![intraday](https://raw.githubusercontent.com/thinh-vu/vnstock/main/src/tcbs_intraday_screen2.png)

</details>
vnstock cho phép người dùng tải xuống dữ liệu giao dịch theo thời gian thực trong ngày ngày giao dịch. Nếu mốc thời gian bạn truy cứu rơi vào Thứ Bảy, Chủ Nhật thì dữ liệu nhận được thể hiện cho ngày giao dịch của Thứ 6 của tuần đó.
vnstock cho phép người dùng tải xuống dữ liệu giao dịch theo thời gian thực trong ngày giao dịch. Nếu mốc thời gian bạn truy cứu rơi vào Thứ Bảy, Chủ Nhật thì dữ liệu nhận được thể hiện cho ngày giao dịch của Thứ 6 của tuần đó.

```python
df = stock_intraday_data(symbol='GMD',
page_num=0,
page_size=100)
print(df.head())
df = stock_intraday_data(symbol='TCB',
page_size=500)
print(df)
```

<details>
<summary>Output</summary>
<summary>Terminal output</summary>

```{r, engine='python', count_lines}
p volume cp rcp a ba sa hl pcp time
0 50700.0 169700 0.0 0.0 0.0 0.0 True 0.0 14:45:08
1 50800.0 1000 0.0 0.0 BU 0.0 0.0 False 0.0 14:30:05
2 50800.0 500 0.0 0.0 BU 0.0 0.0 False 0.0 14:30:05
3 50800.0 20000 0.0 0.0 BU 0.0 0.0 True 0.0 14:29:54
4 50700.0 300 0.0 0.0 SD 0.0 0.0 False 0.0 14:29:53
>>> stock_intraday_data('TCB', 500)
ticker time orderType investorType volume averagePrice orderCount
0 TCB 14:29:55 Sell Down SHEEP 1000 32700.0 1
1 TCB 14:29:47 Buy Up SHEEP 200 32750.0 1
2 TCB 14:29:44 Sell Down WOLF 8000 32700.0 14
3 TCB 14:29:41 Sell Down SHEEP 1000 32700.0 5
4 TCB 14:29:36 Sell Down WOLF 23800 32700.0 10
```

</details>

<details>
<summary>Giải thích ý nghĩa chỉ số</summary>
• Khi 1 lệnh lớn (từ Cá mập, tay to, tổ chức....) mua chủ động (hoặc bán chủ động) được đưa vào Sàn, thường thì nó sẽ được khớp với nhiều lệnh nhỏ đang chờ bán (hoặc chờ mua). Nếu chỉ nhìn realtime theo từng lệnh khớp riêng lẻ, thì sẽ không thể phát hiện được các lệnh to (của Cá mập, tay to...) vừa được đẩy vào Sàn. Vì vậy, chúng tôi "cộng dồn" các lệnh khớp này lại (phát sinh bởi 1 lệnh lớn chủ động vào sàn trong 1 khoảng thời gian rất nhanh) để giúp NĐT phát hiện các lệnh lớn (của Cá mập, tay to....) chính xác hơn. Lệnh Cá mập sẽ được tô xanh (cho Mua chủ động) và đỏ (cho Bán chủ động).

• Cá mập: (CM - SHARK) nhà đầu tư tay to, tổ chức, đầu tư lớn, dẫn dắt thị trường. Giá trị 1 lệnh đặt > 1 tỷ đồng/lệnh đặt. Đồ thị 1N dùng số liệu 1 phút cho 60’ gần nhất; 1W là tổng mỗi 15’ cho 1 tuần; 1M là tổng hàng ngày cho 1 tháng

• Sói già: (SG - WOLF) nhà đầu tư kinh nghiệm, giá trị lệnh đặt cao. Giá trị 1 lệnh đặt từ 200 tr đến 1 tỷ đồng/lệnh đặt.

• Cừu non: (CN - SHEEP) nhà đầu tư nhỏ lẻ, giá trị giao dịch và mua bán chủ động thấp. Giá trị 1 lệnh đặt Mua hoặc Bán chủ động < 200 triệu đồng/lệnh đặt vào.

• Mua chủ động (hay Buy Up) là khi NĐT thực hiện chủ động mua lên qua việc đặt lệnh mua với giá bằng giá dư bán gần nhất để có thể khớp luôn. Như thế, giá khớp cho lệnh này thường sẽ đẩy giá khớp lên cao hơn thị giá trước đó.

• Bán chủ động (hay Sell Down) là khi NĐT thực hiện chủ động Bán dưới giá hiện tại (hay thị giá) của cổ phiếu bằng việc đặt lệnh bán với giá bán bằng giá dư mua gần nhất để khớp ngay. Và như thế, thị giá sẽ bị kéo xuống thấp hơn so với thị giá trước đó. Thống kê khối lượng giao dich theo Mua CĐ và Bán CĐ dùng để đánh giá tương quan giữa cung (Bán CĐ) và cầu (Mua CĐ) trên giao dịch khớp lệnh thực tế, nhằm nhận định tương đối về sự vận động của xu hướng dòng tiền. Khi tỷ lệ % Mua CĐ trên (Tổng Mua và Bán CĐ) lớn hơn 50%, đồng nghĩa với việc thị trường đang có xu hướng mua vào nhiều hơn bán ra và ngược lại, qua đó xác định được dòng tiền vào/ra với mỗi cổ phiếu. Khi tỷ lệ này cao đột biến (>70% hay <30%) so với điểm cân bằng (50%) , đó là tín hiệu của việc mua hoặc bán bất chấp của thị trường.

</details>

## 2.6. 💰 Các chỉ số tài chính
### 2.6.1. So sánh các chỉ số tài chính của nhiều mã cổ phiếu

Expand Down
4 changes: 4 additions & 0 deletions changes_log.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Updated 2023-06-29
- Updated the stock_intraday_data function to elaborate more insights the data returned by the function and make it usable.
- Updated the stock_historical_data to support getting indices historical data.

# Updated 2023-06-22
- Referred to as version 0.15 (coming soon on Pypi)
- Introduce a new feature to the stock_historical_data function, enabling retrieval of data with multiple time resolutions. The corresponding API endpoint supporting this function has been upgraded.
Expand Down
Loading

0 comments on commit 35919e3

Please sign in to comment.