Skip to main content

jquants-algo

PyPI License: MIT codecov Python package PyPI - Python Version Downloads

jquants-algo is a python library for algorithmic trading with japanese stock trade using J-Quants on Python 3.8 and above.

Installation

$ pip install jquants-algo

Usage

backtest

from jquants_algo import Algo
import pprint

class MyAlgo(Algo):
    def strategy(self):
        fast_ma = self.sma(period=3)
        slow_ma = self.sma(period=5)
        # golden cross
        self.sell_exit = self.buy_entry = (fast_ma > slow_ma) & (
            fast_ma.shift() <= slow_ma.shift()
        )
        # dead cross
        self.buy_exit = self.sell_entry = (fast_ma < slow_ma) & (
            fast_ma.shift() >= slow_ma.shift()
        )

algo = MyAlgo(
    mail_address="<your J-Quants mail address>",
    password="<your J-Quants password>",
    ticker="7203",  # TOYOTA
    size=100,  # 100 shares
)
pprint.pprint(algo.backtest())

performance.png

{'long': {'average return': '0.156',
          'maximum drawdown': '49350.000',
          'profit': '11450.000',
          'profit factor': '1.080',
          'riskreward ratio': '1.455',
          'sharpe ratio': '0.038',
          'trades': '54.000',
          'win rate': '0.426'},
 'short': {'average return': '-0.238',
           'maximum drawdown': '42050.000',
           'profit': '-31020.000',
           'profit factor': '0.754',
           'riskreward ratio': '1.319',
           'sharpe ratio': '-0.091',
           'trades': '55.000',
           'win rate': '0.364'},
 'total': {'average return': '-0.043',
           'maximum drawdown': '79950.000',
           'profit': '-19570.000',
           'profit factor': '0.927',
           'riskreward ratio': '1.423',
           'sharpe ratio': '-0.013',
           'trades': '109.000',
           'win rate': '0.394'}}

predict

from jquants_algo import Algo
import pprint

class MyAlgo(Algo):
    def strategy(self):
        fast_ma = self.sma(period=3)
        slow_ma = self.sma(period=5)
        # golden cross
        self.sell_exit = self.buy_entry = (fast_ma > slow_ma) & (
            fast_ma.shift() <= slow_ma.shift()
        )
        # dead cross
        self.buy_exit = self.sell_entry = (fast_ma < slow_ma) & (
            fast_ma.shift() >= slow_ma.shift()
        )

algo = MyAlgo(
    mail_address="<your J-Quants mail address>",
    password="<your J-Quants password>",
    ticker="7203",  # TOYOTA
    size=100,  # 100 shares
)
pprint.pprint(algo.predict())
{'buy entry': True,
 'buy exit': False,
 'close': 2416.5,
 'date': '2023-08-22',
 'sell entry': False,
 'sell exit': True}

advanced

from jquants_algo import Algo
import pprint

class MyAlgo(Algo):
    def strategy(self):
        rsi = self.rsi(period=10)
        ema = self.ema(period=20)
        lower = ema - (ema * 0.001)
        upper = ema + (ema * 0.001)
        self.buy_entry = (rsi < 30) & (self.df.Close < lower)
        self.sell_entry = (rsi > 70) & (self.df.Close > upper)
        self.sell_exit = ema > self.df.Close
        self.buy_exit = ema < self.df.Close

algo = MyAlgo(
    mail_address="<your J-Quants mail address>",
    password="<your J-Quants password>",
    ticker="7203",  # TOYOTA
    size=100,  # 100 shares
    outputs_dir_path="outputs",
    data_dir_path="data",
)
pprint.pprint(algo.backtest())
pprint.pprint(algo.predict())

Supported indicators

  • Simple Moving Average 'sma'
  • Exponential Moving Average 'ema'
  • Moving Average Convergence Divergence 'macd'
  • Relative Strenght Index 'rsi'
  • Bollinger Bands 'bbands'
  • Market Momentum 'mom'
  • Stochastic Oscillator 'stoch'
  • Average True Range 'atr'

Getting started

For help getting started with J-Quants, view our online documentation.

Metadata

Release files for jquants-algo 0.1.1

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

Source distribution (sdist)

Source distribution for jquants-algo 0.1.1
File Size Uploaded
jquants-algo-0.1.1.tar.gz 7.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jquants-algo 0.1.1
File Interpreter ABI Platform
jquants_algo-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.1 kB

Release files / jquants-algo-0.1.1.tar.gz

Download URL jquants-algo-0.1.1.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d29a6ac0af0c9ec2b53a44c4059f60772575c488fbf7763f5a67bf66f47aa376
BLAKE2b-256 checksum
How to use checksums
8a60c09d5145ed65765b529ca3d6bcf60941cc73e0cad05ba09fd02aa4c347f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / jquants_algo-0.1.1-py3-none-any.whl

Download URL jquants_algo-0.1.1-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d0898dbc2f785454ef4c2c920a96ead2f0b9a6678bb7c1a0a001101395e7ef8
BLAKE2b-256 checksum
How to use checksums
8572fd25c87e1500b3abf14221c14f987289b28e9372b596e0b65d318a991a16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.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