XNO API Library for Financial Data
Project description
XNO API Library
XNO API is a Python package for retrieving financial data and performing quantitative analysis, specifically optimized for the Vietnamese financial market. It provides a clean, modular interface to access data on stocks, derivatives, and backtesting tools for PnL and performance metrics.
📌 Key Features
- 🔎 Simple interface to retrieve real-time and historical data for Vietnamese stocks and derivatives
- 📈 Built-in support for performance metrics: Sharpe, Sortino, Max Drawdown, and more
- 📊 Optimized PnL backtesting tools for derivatives with Vietnam-specific fee structures
- 🧪 Compatible with pandas, NumPy for custom strategies and analysis
- 🖼️ Easily extensible for visual output of strategies and metrics
📦 Installation
Install via pip:
pip install xnoapi
Or clone this repo:
git clone https://github.com/xnoproject/xnoapi.git
pip install ./xnoapi
After installation:
from xnoapi import client
from xnoapi.vn.data import stocks, derivatives
from xnoapi.vn.metrics import Metrics, Backtest_Derivates
client(apikey="your_api_key")
📚 Documentation
- Online Docs: https://xnoapi.readthedocs.io
- 📄 PDF version
🚀 Usage Example
Retrieve and analyze Vietnamese stock & derivative data:
from xnoapi import client
from xnoapi.vn.data import stocks, derivatives
client(apikey="your_api_key")
# List of liquid stocks
stocks.list_liquid_asset()
# Historical data for VIC (Vingroup)
vic = stocks.get_hist("VIC")
# Historical data for VN30F1M derivative
vn30f1m = derivatives.get_hist("VN30F1M", "1m")
🧠 Available Modules
📊 Financial Data
-
xnoapi.vn.data.stockslist_liquid_asset(): List of high-liquidity Vietnamese stocks.get_hist(asset): Historical OHLCV data.
-
xnoapi.vn.data.derivativesget_hist(asset, frequency): Derivative market data (e.g., VN30F1M).
📈 Metrics & Analytics
xnoapi.vn.metrics.Metrics:- Includes: Sharpe Ratio, Sortino Ratio, Max Drawdown, Avg Gain/Loss, Hit Ratio...
xnoapi.vn.metrics.Backtest_Derivates:- Backtesting logic for trading strategies with support for fee modeling.
xnoapi.metrics.single_asset.TradingBacktest:- Lightweight backtesting class for trading strategies on derivatives (supports raw and after-fee PnL calculation).
- Metrics included: Sharpe, Sortino, Calmar, Max Drawdown, Win Rate, Profit Factor, Risk of Ruin, etc.
🧪 Examples
Strategy Evaluation with Metrics
from xnoapi.vn.metrics import Metrics, Backtest_Derivates
from xnoapi.vn.data import derivatives
import numpy as np
# Generate signal: simple strategy based on 20-period median
def gen_position(df):
return df.assign(
position=np.sign(df["Close"] - df["Close"].rolling(20).median())
)
# Fetch 1-minute historical data
df = derivatives.get_hist("VN30F1M", "1m")
df_pos = gen_position(df)
# Backtest the strategy
backtest = Backtest_Derivates(df_pos, pnl_type="raw")
# Initialize metrics
metrics = Metrics(backtest)
# === Backtest_Derivates Methods ===
# Cumulative PNL
cumulative_pnl = backtest.PNL()
# Daily cumulative PNL
daily_cumulative_pnl = backtest.daily_PNL()
# Estimate Minimum Capital Required
min_capital = backtest.estimate_minimum_capital()
# PNL Percentage
pnl_percentage = backtest.PNL_percentage()
# === Metrics Methods ===
# Average Loss
metrics.avg_loss()
# Average Return
metrics.avg_return()
# Average Win
metrics.avg_win()
# Max Drawdown
metrics.max_drawdown()
# Win Rate
metrics.win_rate()
# Volatility
metrics.volatility()
# Sharpe Ratio
metrics.sharpe()
# Sortino Ratio
metrics.sortino()
# Calmar Ratio
metrics.calmar()
# Profit Factor
metrics.profit_factor()
# Risk of Ruin
metrics.risk_of_ruin()
# Value at Risk
metrics.value_at_risk()
🤝 Credits
Maintained by the XNO Team.
Special thanks to contributors and financial data providers supporting the Vietnamese retail quant community.
📄 License
This project is licensed under the MIT License.
See LICENSE for full details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xnoapi-0.1.17.tar.gz.
File metadata
- Download URL: xnoapi-0.1.17.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
023ad2e4f37dfb3a3f8340e41f13a0ef529b34fa7fb8df74cd4f04216db5daaf
|
|
| MD5 |
982517c2be3162bda4e4c8e5c8b95474
|
|
| BLAKE2b-256 |
dcfdc8ee9b88904d25695a3259dcd76424846910dc7cd2b1da1fdfed07e24a3f
|
File details
Details for the file xnoapi-0.1.17-py3-none-any.whl.
File metadata
- Download URL: xnoapi-0.1.17-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3add330c8c9cbd2439da3f001464cfc1494da9886d8b0baee5a9fb13e1d2eec
|
|
| MD5 |
f4b3f821d3aad8ce88c9b406ad54f8fa
|
|
| BLAKE2b-256 |
3da1d5145a894726c63b7453f3b3974c2bfac7c970cc50dbce702057a8d41697
|