After making sure you installed all the required libraries, you can run the following commands to transform tabular data to gaf :
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.
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")
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 |
---|---|
Zhiguang Wang and Tim Oates: Time-Series Image Encoding