Giter Club home page Giter Club logo

deep-fingaf's Introduction

Deep-FinGAF

Python application License: MIT

OnBoarding

Transform tabular data to Gramian Angular Fields (GAF)

After making sure you installed all the required libraries, you can run the following commands to transform tabular data to gaf :

First, import your raw data

As the i-20 previous are used to create day's i GAF, you need to have more an interval more than 20 days long. In fact, you'll get interval_lenght-20 images saved.

import yfinance as yf
your_stock = yf.Ticker("your_stock_ticker")
df = your_stock.history(start= start_date, end = end_date,interval= "1h")

To define the decision, a simple comparison is made in trading_action:

def trading_action(future_close: float, current_close: float) -> str:
    if future_close < current_close:
        decision = 'LONG'
    else:
        decision = 'SHORT'
    return decision

Then you only need to run the following commands :

from DataGeneration.raw_to_gafs_funcs import clean_non_trading_times, set_gaf_data, convert_to_gaf_and_save

your_stock = clean_non_trading_times(your_stock)
decision_map = set_gaf_data(your_stock)
convert_to_gaf_and_save(decision_map)

In your deep_FinGAF/data folder you shall get two directories, SHORT and LONG containing images containing each day information.

Train and test a model

Pretty easily done :

from model.models import CNN
from model.train import train, test_model

cnn = CNN()
train(cnn, 50)
test_model("../saved_model/cnn")

More on GAF

Images are normalized to [-1,1] then converted to polar coordinates. (r.cos(phi) where phi = arcos(x)) and r is normalized time_stamp)

With the polar vector, we build a Gramian Matrix. This matrix is then processed into a heatmap and that's your encoded image.

Some examples :

Real plot Encoded image
plot plot
plot plot
plot plot

Ressources :

Zhiguang Wang and Tim Oates: Time-Series Image Encoding

deep-fingaf's People

Contributors

g0bel1n avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.