quantvn 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of quantvn might be problematic. Click here for more details.
- quantvn/__init__.py +2 -0
- quantvn/crypto/__init__.py +1 -0
- quantvn/crypto/data/__init__.py +31 -0
- quantvn/crypto/data/const.py +26 -0
- quantvn/crypto/data/core.py +82 -0
- quantvn/crypto/data/derivatives.py +22 -0
- quantvn/crypto/data/utils.py +93 -0
- quantvn/metrics/__init__.py +3 -0
- quantvn/metrics/portfolio.py +0 -0
- quantvn/metrics/single_asset.py +419 -0
- quantvn/metrics/st.py +569 -0
- quantvn/paper/__init__.py +0 -0
- quantvn/paper/portfolio.py +0 -0
- quantvn/paper/single_asset.py +0 -0
- quantvn/vn/__init__.py +1 -0
- quantvn/vn/data/__init__.py +146 -0
- quantvn/vn/data/const.py +26 -0
- quantvn/vn/data/core.py +904 -0
- quantvn/vn/data/derivatives.py +62 -0
- quantvn/vn/data/stocks.py +1281 -0
- quantvn/vn/data/utils.py +56 -0
- quantvn/vn/metrics/__init__.py +4 -0
- quantvn/vn/metrics/backtest.py +323 -0
- quantvn/vn/metrics/metrics.py +185 -0
- quantvn-0.1.0.dist-info/METADATA +25 -0
- quantvn-0.1.0.dist-info/RECORD +29 -0
- quantvn-0.1.0.dist-info/WHEEL +5 -0
- quantvn-0.1.0.dist-info/licenses/LICENSE +21 -0
- quantvn-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import gzip
|
|
3
|
+
import base64
|
|
4
|
+
import requests
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
from .utils import Config
|
|
8
|
+
|
|
9
|
+
# Định nghĩa các thành phần public của module
|
|
10
|
+
__all__ = ["get_hist"]
|
|
11
|
+
|
|
12
|
+
# Lấy URL của Lambda function từ Config
|
|
13
|
+
LAMBDA_URL = Config.get_link()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_hist(symbol: str, frequency: str):
|
|
17
|
+
"""
|
|
18
|
+
Get historical data of derivatives VN30F1M and VN30F2M.
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
symbol : str
|
|
23
|
+
Derivatives symbol (e.g. "VN30F1M", "VN30F2M").
|
|
24
|
+
frequency : str
|
|
25
|
+
Timeframe to get data (e.g. "1D", "1H", "5M").
|
|
26
|
+
Returns
|
|
27
|
+
-------
|
|
28
|
+
dict
|
|
29
|
+
Historical data with information such as time, closing price, trading volume.
|
|
30
|
+
|
|
31
|
+
Raises
|
|
32
|
+
------
|
|
33
|
+
Exception
|
|
34
|
+
If there is an error when calling the API.
|
|
35
|
+
"""
|
|
36
|
+
api_key = Config.get_api_key()
|
|
37
|
+
payload = {"symbol": symbol, "frequency": frequency}
|
|
38
|
+
|
|
39
|
+
response = requests.post(
|
|
40
|
+
f"{LAMBDA_URL}/data-derivatives",
|
|
41
|
+
json=payload,
|
|
42
|
+
headers={"x-api-key": api_key},
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
if response.status_code == 200:
|
|
46
|
+
data = response.json()
|
|
47
|
+
|
|
48
|
+
if isinstance(data, dict) and "base64" in data:
|
|
49
|
+
try:
|
|
50
|
+
decoded_data = base64.b64decode(data["base64"])
|
|
51
|
+
|
|
52
|
+
with gzip.GzipFile(fileobj=io.BytesIO(decoded_data), mode="rb") as gz:
|
|
53
|
+
extracted_content = gz.read().decode("utf-8")
|
|
54
|
+
df = pd.read_csv(io.StringIO(extracted_content), index_col=0)
|
|
55
|
+
return df
|
|
56
|
+
|
|
57
|
+
except Exception as e:
|
|
58
|
+
return {"error": f"Failed to process base64 data: {str(e)}"}
|
|
59
|
+
|
|
60
|
+
return pd.DataFrame(data)
|
|
61
|
+
else:
|
|
62
|
+
raise Exception(f"Error: {response.status_code}, {response.text}")
|