Skip to main content

Out-of-box python tool and framework for quantitative trading and study

Project description

Hiquant

阅读此文档的中文版本

Hiquant is a quatitative trading framework and out-of-box toolset for assisting stock/fund investment.

Features

  • Data acquisition: fetch data from financial websites, including indices, stocks, funds, financial reports, history data, realtime data, etc.
  • Valuation analysis: extract key abstract info from financial reports like ROE, calculate PE/PB percentiles, find “cheap valuation” stocks, export to stock pool
  • Plot stock with indicators: plot k-line diagram of stocks with indicators, comparing earning curve of multiple indices or even multiple stocks
  • Strategy framework: implemented a strategy framework for backtesting, with sample code for demo purposes, and provides a command to create a new strategy from the template, which is convenient for users to write their own strategies
  • Simulated backtesting: Use historical market data, to simulate backtesting of one or more portfolio strategies, output data analysis of investment returns, and draw yield curves for comparison
  • Simulated realtime trading: Synchronize real-time market data, calculate trading decisions based on strategies, and send email notifications to remind users to trade
  • Multi markets: currently supports China, Hong Kong and United States market, will add support for markets in other countries if requested and data available
  • TODO: Automated trading: call the quantitative trading interface to realize automated trading (not yet implemented, planned)

Other features:

  • Evaluate funds: search and filter funds, calculate sharpe ratio and max drawdown, evaluate funds, comparing earning curve of multiple funds, comparing investment performance of fund managers

Hiquant system architecture

Installation

Please make sure your Python is v3.7 or above, as it's required by Matplotlib 3.4 for plottting.

python3 --version
python3 -m pip install hiquant

Or, clone from GitHub:

git clone https://github.com/floatinghotpot/hiquant.git
cd hiquant
python3 -m pip install -e .

Examples

  • Draw stock indicators and yield curve
hiquant stock AAPL -ma -macd

Draw stock

  • Draw trade signal of mixed indicators, holding time, and yield curve
hiquant stock AAPL -ma -macd -mix

Draw stock

  • Compare ROI of multiple stocks
hiquant stock plot AAPL GOOG AMZN -years=5 "-base=^IXIC,^GSPC"

Compore stocks

  • Backtrade with one portoflio Draw stock

  • Backtrade with multiple portoflios Draw stock

Command quick start

hiquant create myProj
cd myProj

hiquant index list us
hiquant stock list us

hiquant stock plot AAPL -ma -macd -kdj
hiquant stock plot AAPL -all
hiquant stock plot AAPL -wr -bias -mix

hiquant stock pool AAPL GOOG AMZN TSLA MSFT -out=stockpool/mystocks.csv

hiquant strategy create strategy/mystrategy.py
hiquant backtest strategy/mystrategy.py

hiquant trade create etc/myfund.conf
hiquant backtrade etc/myfund.conf
hiquant run etc/myfund.conf

Code quick start

import pandas as pd
import hiquant as hq

class MyStrategy( hq.BasicStrategy ):
    def __init__(self, fund):
        super().__init__(fund, __file__)
        self.max_stocks = 10
        self.max_weight = 1.2
        self.stop_loss = 1 + (-0.10)
        self.stop_earn = 1 + (+0.20)

    def select_targets(self):
        return ['AAPL', 'MSFT', 'AMZN', 'TSLA', '0700.HK']

    def gen_trade_signal(self, symbol, init_data = False):
        market = self.fund.market
        if init_data:
            df = market.get_daily(symbol)
        else:
            df = market.get_daily(symbol, end = market.current_date, count = 26+9)

        dif, dea, macd_hist = hq.MACD(df.close, fast=12, slow=26, signal=9)
        return pd.Series( hq.CROSS(dif, dea), index=df.index )

    def get_signal_comment(self, symbol, signal):
        return 'MACD golden cross' if (signal > 0) else 'MACD dead cross'

def init(fund):
    strategy = MyStrategy(fund)

if __name__ == '__main__':
    backtest_args = dict(
        #start_cash= 1000000.00,
        #date_start= hq.date_from_str('3 years ago'),
        #date_end= hq.date_from_str('yesterday'),
        #out_file= 'output/demo.png',
        #parallel= True,
        compare_index= '^GSPC',
    )
    hq.backtest_strategy( MyStrategy, **backtest_args )

Usage

Read following docs for more details:

Develop with Hiquant

Read this document on how to develop with Hiquant:

Credits

Great appreciate developers of following projects. This project is based on their great works: Pandas, Matplotlib, Mplfinance, Akshare, etc.

Thanks folloowing websites for providing data service: Sina, Legu, Yahoo, Nasdaq, etc.

Thanks the warm-hearted knowledge sharing on Zhihu and Baidu websites.

Disclaimer

This software and related codes are for research purposes only and do not constitute any investment advice.

If anyone invests money in actual investment based on this, please bear all risks by yourself.

This software is developed on Mac, and the examples in this document are written with Mac environment. They are similiar for Linux, but might be a little difference on Windows.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hiquant-0.4.16.tar.gz (72.6 kB view details)

Uploaded Source

Built Distribution

hiquant-0.4.16-py3-none-any.whl (91.9 kB view details)

Uploaded Python 3

File details

Details for the file hiquant-0.4.16.tar.gz.

File metadata

  • Download URL: hiquant-0.4.16.tar.gz
  • Upload date:
  • Size: 72.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.9

File hashes

Hashes for hiquant-0.4.16.tar.gz
Algorithm Hash digest
SHA256 e855bead2c6f840db9ad66afe1513a24eefd8cf09d976a486ad6b38b23d2b900
MD5 66ac3edc4b7d849f3097d1c1c59a2dd3
BLAKE2b-256 558ee3766889dedcdd43901ec437e64f4d0ccd6cd93ef9c73098383e7167a04c

See more details on using hashes here.

Provenance

File details

Details for the file hiquant-0.4.16-py3-none-any.whl.

File metadata

  • Download URL: hiquant-0.4.16-py3-none-any.whl
  • Upload date:
  • Size: 91.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.9

File hashes

Hashes for hiquant-0.4.16-py3-none-any.whl
Algorithm Hash digest
SHA256 c5b08e6e1068c0c15785feefc720204db62a75469f1d9403c26b36c2b7a25bdd
MD5 c1ac299fd202a1459c2401e1624df628
BLAKE2b-256 54293a05645e32facf20b0a50462e45120aad8f089ca2180c355c6120323c42a

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page