Skip to main content

AI trading assistant

Project description

Netrade

Netrade is an AI trading assistant with human trader approach

How it works

This AI model will predict the price will go up or go down based on chart pattern and candlestick pattern

The data is available here

Chart Pattern

Chart pattern is enough for analyzing price will go up or go down as usualy traders do, here's some example:

chart-pattern

Candle Stick

Bechause of chart pattern has a limitation we need candle stick pattern to decide when we should buy or sell, here is some example

first row is bearish candle stick pattern and the second row bulish candle stick

chart-pattern

Performance

We've been tested this model in 1 week and here's the result:

  • model accuracy & loss

chart-pattern

  • profit

chart-pattern

  • Win & loss rate ( 61% win 39% loss )

chart-pattern

Installation

  • github
    git clone https://github.com/rizki4106/netrade.git
    
    cd netrade && pip3 install torch torchmetrics scikit-image Pillow torchvision
    
  • pypi
    pip3 install netrade
    

Usage

This step devided into 2 step

Training

download pre-trained model here https://github.com/rizki4106/netrade/releases/ but if you want to train with your own data, here's the step

  • Prepare The data
    You should put your image in this pattern:

    chart:
    ----up:
    ------image1.png
    ------image2.png
    ----down:
    ------image1.png
    ------image2.png
    candle:
    ------image1.png
    ------image2.png
    ----down:
    ------image1.png
    ------image2.png
    
  • Make csv file that contain this field

    chart_name candle_name path label
    filename.png filename.png down 0
    filename.png filename.png up 1
    filename.png filename.png down 0
    filename.png filename.png down 0
    filename.png filename.png up 1

    you can do it by using data preprocessing helper easly

    from netrade.data import DataPreprocessing
    
    # initialize class
    chart = "/path/to/somwhere/chart/"
    candle = "/path/to/somewhere/candle"
    
    prep = DataPreprocessing(chart_path=chart, candle_path=candle)
    
    # create dataframe
    frame = prep.create_frame()
    frame.head()
    
  • Create image transformer

    from torchvision import transforms
    
    # this is for chart pattern
    chart_transformer = transforms.Compose([
        transforms.Resize((224, 224)),
        transforms.ToTensor()
    ])
    
    # this is for candlestick pattern
    candle_transformer = transforms.Compose([
        transforms.Resize((64, 64)),
        transforms.ToTensor()
    ])
    
  • Load your data with data loader

    from netrade.data import NetradeDataLoader
    
    # supposed you have created csv file like i mention above
    frame = pd.read_csv("file_training.csv")
    
    # load data and turn it into tensor
    train_data = NetradeDataLoader(
        chart_dir="/path/to/root/chart-pattern/",
        candle_dir="/path/to/root/candle-stick/",
        frame=frame,
        chart_transform=chart_transformer,
        candle_transform=candle_transformer
    ) # this data loader will return [chart image, candle image and labels]
    
  • Create bathes

    from torch.utils.data import DataLoader
    
    dataloader = DataLoader(
        train_data,
        batch_size=16,
        shuffle=True
    )
    
  • Run training loop

    from netrade.core import Netrade
    import torch
    
    # initialize the model
    netrade = Netrade()
    
    # run training
    model, history = netrade.train(X_train=dataloader, epochs=10)
    
    # model is pure pytorch nn module that has been trained with your own data you can check it model.parameters()
    # history is the result from training loop
    
    print(history)
    
    # save the model's state
    torch.save(model.state_dict(), "name-it.pth")
    

Inference mode / Testing

If you want to run this model in production mode then here's the step

from netrade.core import Netrade
from torchvision import transforms
from PIL import Image

# initialize the model
netrade = Netrade(saved_state_path="path-to-saved-state.pth")

# create image transformer
# this is for chart pattern
chart_transformer = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor()
])

# this is for candlestick pattern
candle_transformer = transforms.Compose([
    transforms.Resize((64, 64)),
    transforms.ToTensor()
])

# read the chart pattern image and turn it into tensor
chart_image = chart_transformer(Image.open("chart.png")).unsqueeze(0)

# read candlestick image and turn it into tensor
candle_image = candle_transformer(Image.open("candle.png")).unsqueeze(0)

# run prediction
preds = netrade.predict(chart_image=chart_image, candle_image=candle_image)

# print the result
print(preds.argmax(1)) # 0 price will go down, 1 price will go up

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

netrade-1.1.2.tar.gz (9.0 kB view hashes)

Uploaded Source

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