Skip to main content

QuantSynthica Python SDK

PyPI version Python Version License

The official Python client for QuantSynthica Market API — the unified financial data & quantitative engine combining yfinance, TradingView-Screener, Screener.in, Modern Portfolio Theory, DCF valuation, algorithmic backtesting, and sentiment analysis.


Installation

pip install quantsynthica

Quickstart (Zero-Server, 100% Free - Like yfinance)

No server, API key, or setup required. Run directly in Google Colab, Jupyter, or any Python script:

import quantsynthica as qs

# 1. Direct Market Quote
quote = qs.get_quote("RELIANCE")
print(f"Price: {quote.price} | P/E: {quote.pe_ratio}")

# 2. Complete 4-in-1 Valuation Suite
val = qs.get_valuation("RELIANCE")
print(f"DCF Fair Value:     {val.dcf.fair_value_per_share}")
print(f"Piotroski Score:    {val.piotroski.f_score} / 9 ({val.piotroski.rating})")
print(f"Altman Z-Score:     {val.altman_z.z_score} ({val.altman_z.zone})")
print(f"Graham Number:      {val.graham.graham_number}")

# 3. Modern Portfolio Theory Optimization
opt = qs.optimize_portfolio(["RELIANCE", "TCS", "INFY"], objective="max_sharpe")
print("Expected Return:", opt.optimal_portfolio.expected_annual_return_pct, "%")
for a in opt.allocations:
    print(f"  {a.symbol}: {a.weight_pct}%")

# 4. Multi-Asset Screener (TradingView)
stocks = qs.screener.value_stocks(market="india", limit=10)
crypto = qs.screener.crypto(limit=10)

The Ticker Object (OOP Interface)

stock = qs.Ticker("TCS")

# Live quote
q = stock.quote()

# Historical OHLCV DataFrame
df = stock.history(period="1y")

# Technical indicators (SMA, RSI, MACD, Bollinger Bands)
tech = stock.technicals()
print("RSI 14:", tech.rsi_14)

# Custom Discounted Cash Flow (DCF)
dcf = stock.dcf(growth_rate=0.14, discount_rate=0.10)
print("Fair Value per share:", dcf.fair_value_per_share)

# Company news sentiment
news = stock.sentiment()
print("News Sentiment:", news.overall_sentiment)

Key Features & Examples

1. Valuation Models (DCF, Piotroski, Altman Z, Graham)

# Comprehensive valuation overview
val = client.valuation.get_overview("RELIANCE")
print("DCF Fair Value:", val.dcf_model.fair_value_per_share)
print("Piotroski Score:", val.piotroski_f_score.f_score, "/ 9")
print("Altman Zone:", val.altman_z_score.zone)
print("Graham Number:", val.graham_valuation.graham_number)

# Custom Discounted Cash Flow (DCF) calculation
custom_dcf = client.valuation.dcf(
    symbol="TCS",
    growth_rate=0.14,           # 14% annual growth
    discount_rate=0.105,        # 10.5% WACC hurdle
    terminal_growth_rate=0.035, # 3.5% perpetual growth
    years=5
)
print("Custom Fair Value:", custom_dcf.fair_value_per_share)

2. Portfolio Optimization (MPT / Markowitz Efficient Frontier)

opt = client.portfolio.optimize(
    symbols=["RELIANCE", "TCS", "INFY", "HDFCBANK"],
    objective="max_sharpe",     # 'max_sharpe' or 'min_volatility'
    period="1y",
    include_frontier=True
)

print("Expected Annual Return:", opt.optimal_portfolio.expected_annual_return_pct, "%")
print("Annual Volatility:", opt.optimal_portfolio.annual_volatility_pct, "%")
print("Sharpe Ratio:", opt.optimal_portfolio.sharpe_ratio)

for alloc in opt.allocations:
    print(f"  {alloc.symbol}: {alloc.weight_pct}%")

3. Algorithmic Strategy Backtesting

backtest = client.portfolio.backtest(
    symbol="RELIANCE",
    strategy="sma_crossover",
    period="2y",
    params={"fast_period": 20, "slow_period": 50},
    initial_capital=100000.0
)

print("Total Return:", backtest.summary.total_return_pct, "%")
print("Benchmark Return:", backtest.summary.benchmark_return_pct, "%")
print("Max Drawdown:", backtest.summary.max_drawdown_pct, "%")
print("Win Rate:", backtest.summary.win_rate_pct, "%")
print("Total Trades Executed:", len(backtest.trades))

4. Multi-Asset Screener (TradingView)

# Screen value stocks
value_stocks = client.screener.value_stocks(market="india", limit=25)

# Screen crypto pairs
crypto_movers = client.screener.crypto(limit=20, sort_by="volume")

# Custom screen with SQL-like filters
custom_screen = client.screener.query(
    market="america",
    columns=["name", "close", "volume", "market_cap_basic", "price_earnings_ttm"],
    sort_by="market_cap_basic",
    limit=50
)

5. Financial Sentiment & NLP

# Company news sentiment index
sentiment = client.sentiment.get_symbol_sentiment("RELIANCE")
print("Overall Sentiment:", sentiment.overall_sentiment)
print("Bullish Articles:", sentiment.breakdown.bullish_articles)

# Ad-hoc financial headline analysis
analysis = client.sentiment.analyze_text("Quarterly profit surges 35% beating analyst consensus estimates")
print(analysis.label, analysis.compound_score)

6. Institutional Factsheets & Excel Export

# Download multi-tab Excel financial model
client.reports.download_excel("RELIANCE", output_path="reliance_model.xlsx")

# Retrieve printable HTML tearsheet
tearsheet_html = client.reports.get_tearsheet_html("RELIANCE")

Error Handling

The SDK provides explicit exceptions:

from quantsynthica import QuantSynthica
from quantsynthica.exceptions import (
    AuthenticationError,
    NotFoundError,
    RateLimitError,
    QuantSynthicaError
)

client = QuantSynthica(api_key="your_api_key")

try:
    quote = client.market.get_quote("UNKNOWN_TICKER")
except NotFoundError:
    print("Symbol does not exist")
except RateLimitError:
    print("Rate limit reached; retry shortly")
except AuthenticationError:
    print("Invalid API Key")
except QuantSynthicaError as e:
    print(f"API Error: {e.message} (HTTP {e.status_code})")

License

Apache License 2.0. See LICENSE for details.

Metadata

Release files for quantsynthica 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quantsynthica 1.1.0
File Size Uploaded
quantsynthica-1.1.0.tar.gz 22.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for quantsynthica 1.1.0
File Interpreter ABI Platform
quantsynthica-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 49.2 kB

Release files / quantsynthica-1.1.0.tar.gz

Download URL quantsynthica-1.1.0.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7f06df569640db9dbfb0c3f84eb17056853f9f059e81c76e70d4e4f78fdf39c8
BLAKE2b-256 checksum
How to use checksums
ab051532bdd1c53667e4e435eba288002e0043a693cd79de762b73f734587ee2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / quantsynthica-1.1.0-py3-none-any.whl

Download URL quantsynthica-1.1.0-py3-none-any.whl
Size 26.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc18dcf902e9182e50a25271093fa5d08dcc90e529b85d4c04d5fb1f829eaa74
BLAKE2b-256 checksum
How to use checksums
63c3f452d018f417bd202daa7f79ded2a84482dd51f2ac1ce344b0fae6772ebc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

1.1.1

2 release files

This release

1.1.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page