Skip to main content

jquants-ml

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

jquants-ml is a python library for machine learning with japanese stock trade using J-Quants on Python 3.8 and above.

Installation

$ pip install jquants-ml

Usage

backtest

from jquants_ml import Ml
import pprint

class MyMl(Ml):
    def features(self):
        self.X["close"] = self.df.Close
        self.X["ror"] = self.df.Close.pct_change(1)
        self.X["sma"] = self.sma(period=5)

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

7203.png

{'long': {'maximum drawdown': '15250.000',
          'profit': '12700.000',
          'profit factor': '1.183',
          'riskreward ratio': '1.213',
          'sharpe ratio': '0.063',
          'trades': '81.000',
          'win rate': '0.494'},
 'short': {'maximum drawdown': '50100.000',
           'profit': '-43800.000',
           'profit factor': '0.413',
           'riskreward ratio': '0.478',
           'sharpe ratio': '0.298',
           'trades': '41.000',
           'win rate': '0.463'},
 'total': {'maximum drawdown': '47200.000',
           'profit': '-31100.000',
           'profit factor': '0.784',
           'riskreward ratio': '0.837',
           'sharpe ratio': '0.149',
           'trades': '122.000',
           'win rate': '0.484'}}

predict

from jquants_ml import Ml
import pprint

class MyMl(Ml):
    def features(self):
        self.X["close"] = self.df.Close
        self.X["ror"] = self.df.Close.pct_change(1)
        self.X["sma"] = self.sma(period=5)

ml = MyMl(
    mail_address="<your J-Quants mail address>",
    password="<your J-Quants password>",
    ticker="7203",  # TOYOTA
    size=100,  # 100 shares
)
pprint.pprint(ml.predict())
{'Date': '2023-08-01', 'Price': 2445.5, 'Sign': 'short'}

advanced

from jquants_ml import Ml

class MyMl(Ml):
    # Awesome Oscillator
    def ao(self, *, fast_period: int = 5, slow_period: int = 34):
        return ((self.df.H + self.df.L) / 2).rolling(fast_period).mean() - (
            (self.df.H + self.df.L) / 2
        ).rolling(slow_period).mean()

    def features(self):
        self.X["ao"] = self.ao(fast_period=5, slow_period=34)
        self.X["close"] = self.df.Close
        self.X["ror"] = self.df.Close.pct_change(1)
        self.X["sma"] = self.sma(period=5)
        self.X["ema"] = self.ema(period=5)
        self.X["upper"], self.X["mid"], self.X["lower"] = self.bbands(
            period=20, band=2
        )
        self.X["macd"], self.X["signal"] = self.macd(
            fast_period=12, slow_period=26, signal_period=9
        )
        self.X["k"], self.X["d"] = self.stoch(k_period=5, d_period=3)
        self.X["rsi"] = self.rsi(period=14)
        self.X["atr"] = self.atr(period=14)
        self.X["mom"] = self.mom(period=10)

ml = MyMl(
    mail_address="<your J-Quants mail address>",
    password="<your J-Quants password>",
    ticker="7203",  # TOYOTA
    size=100,  # 100 shares
    outputs_dir_path="outputs",
    model_dir_path="model",
    data_dir_path="data",
)
pprint.pprint(ml.backtest())
pprint.pprint(ml.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-ml 0.1.4

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-ml 0.1.4
File Size Uploaded
jquants-ml-0.1.4.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jquants-ml 0.1.4
File Interpreter ABI Platform
jquants_ml-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 14.2 kB

Release files / jquants-ml-0.1.4.tar.gz

Download URL jquants-ml-0.1.4.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
83241eb992dcf1c80cd1f684b8592ce6409eea0cf6588eecb002d62534081df5
BLAKE2b-256 checksum
How to use checksums
297f4d765a6bb8fc8c3269832ae87d7c4ef95146958afcba5277f2b89dcbdea9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / jquants_ml-0.1.4-py3-none-any.whl

Download URL jquants_ml-0.1.4-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55eb24e0891ac5d26cda397bf30a34281ab47c400e249741de10a868ffc7e1b3
BLAKE2b-256 checksum
How to use checksums
ef603f6afcdbca90b8bf491d700523929fb89684e8dd430eb3372cd9df253278
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.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

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