Metadata-Version: 2.1
Name: jquants-algo
Version: 0.1.0
Summary: jquants-algo is a python library for algorithmic trading with japanese stock trade using J-Quants on Python 3.8 and above.
Author-email: 10mohi6 <10.mohi.6.y@gmail.com>
Project-URL: Homepage, https://github.com/10mohi6/jquants-algo-python
Project-URL: Documentation, https://github.com/10mohi6/jquants-algo-python
Project-URL: Repository, https://github.com/10mohi6/jquants-algo-python.git
Keywords: algorithmic trading,python,japanese stock,trade,J-Quants,jquants
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Operating System :: OS Independent
Classifier: Topic :: Office/Business :: Financial :: Investment
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENCE.txt
Requires-Dist: jquants-api-client
Requires-Dist: matplotlib
Provides-Extra: dev
Requires-Dist: pytest ; extra == 'dev'
Requires-Dist: pytest-cov ; extra == 'dev'
Requires-Dist: pytest-mock ; extra == 'dev'

# jquants-algo

[![PyPI](https://img.shields.io/pypi/v/jquants-algo)](https://pypi.org/project/jquants-algo/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![codecov](https://codecov.io/gh/10mohi6/jquants-algo-python/graph/badge.svg?token=X8QKKFK6AL)](https://codecov.io/gh/10mohi6/jquants-algo-python)
[![Python package](https://github.com/10mohi6/jquants-algo-python/actions/workflows/python-package.yml/badge.svg)](https://github.com/10mohi6/jquants-algo-python/actions/workflows/python-package.yml)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/jquants-algo)](https://pypi.org/project/jquants-algo/)
[![Downloads](https://pepy.tech/badge/jquants-algo)](https://pepy.tech/project/jquants-algo)

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

```python
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](https://raw.githubusercontent.com/10mohi6/jquants-algo-python/main/tests/7203-performance.png)

```python
{'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.207',
           'maximum drawdown': '39950.000',
           'profit': '-26420.000',
           'profit factor': '0.782',
           'riskreward ratio': '1.330',
           'sharpe ratio': '-0.079',
           'trades': '54.000',
           'win rate': '0.370'},
 'total': {'average return': '-0.026',
           'maximum drawdown': '79950.000',
           'profit': '-14970.000',
           'profit factor': '0.943',
           'riskreward ratio': '1.426',
           'sharpe ratio': '-0.008',
           'trades': '108.000',
           'win rate': '0.398'}}
```

### predict

```python
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())
```

```python
{'buy entry': False,
 'buy exit': False,
 'close': 2356.5,
 'date': '2023-08-21',
 'sell entry': False,
 'sell exit': False}
```

### advanced

```python
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](https://jpx-jquants.com/).
