happynoom / DeepTrade_keras

http://www.deeplearning.xin
229 stars 125 forks source link

Adapting this for FOREX on 1 Hour Timeframe #11

Closed developeralgo8888 closed 6 years ago

developeralgo8888 commented 6 years ago

is there a way to adapt your code to work on Forex with 1 hour timeframe . The CSV datafiles is have columns:

DateTime, Open, High , Low , Close , Volume

or

EpochTime, Open, High , Low , Close , Volume

so that it would output buy or sell signal for next hour.

ChenLi0830 commented 6 years ago

@developeralgo8888 You'd need to modify the source code a bit to achieve that. Fortunately, the source code is pretty clear to maintain and modify, just make the necessary changes in csv_resample.py file

ChenLi0830 commented 6 years ago

@developeralgo8888 BTW, where did you get the FOREX CSV data? Do you happen to know any reliable source to get the data?

developeralgo8888 commented 6 years ago

I have Tick data from IQFEED using my own downloader and but also from DUKASCOPY using StrategyQuant's Tick Downloader tool. IQFEED is expensive for nothing. Get Tick Downloader and download same quality TICK data from Dukascopy for Free

ChenLi0830 commented 6 years ago

@developeralgo8888 Awesome thanks! Let me give that a try

developeralgo8888 commented 6 years ago

Chen, please email me on FX for 5 Minutes, 15 minutes, 30 minutes or 1 hour time frame, and how do we connect it to Interactive brokers for live trading instead of manual trading

  1. Connect to Interactive brokers for Live trading .
  2. Live continuous running prediction to Predict the next 5 , 15 , 30 or 1 hour close price .
  3. Buy or Sell according to the prediction automatically

How do i adapt your code to do this in Forex .

ChenLi0830 commented 6 years ago

Hi @developeralgo8888, I took a quick look at the datasets downloaders you mentioned. It seems the downloader a client for downloading historical data which require manual interactions. What you actually need is a data API that allows you to fetch ticker/OHLCV data in real time in order to make predictions and an exchange API that allows you to trade live.

Unfortunately, I am not very familiar with forex trading enough to give you any suggestions on it. Maybe it's better to ask someone who is familiar with forex bot/quant trading. Good luck 😃

developeralgo8888 commented 6 years ago

Where is csv_resample.py file that you mentioned. i don't see it

ChenLi0830 commented 6 years ago

Oh, I thought it was in the original repo, it turns out I coded it myself. I used that to parse raw ohlcv data and resample it from 5m data into 15m, 30m, 1h, etc. Here it is:

import pandas as pd
import datetime
import numpy as np
import warnings

def is_not_number(s):
    try:
        float(s)
        return False
    except ValueError:
        return True

def resample(csv_path, output_path, input_shape=[30, 61]):
    df = pd.read_csv(csv_path,
                     header=0,
                     usecols=["time", "open", "high", "low", "close", "volume"]
                     # usecols=["date", "open", "high", "low", "close", "volume"], sep='\t',
                     # usecols=["timeStamp", "open", "high", "low", "close", "volume"]
                     # usecols=["Timestamp", "Open", "High", "Low", "Close", "Volume (BTC)"], sep='\t',  )

    df.columns = ['date', 'open', 'high', 'low', 'close', 'volume']
    print(df.head())

    # df['date'] = pd.to_datetime(df['date'], unit='ms')
    # df['date'] = pd.to_datetime(df['date'], unit='s')
    df['date'] = pd.to_datetime(df['date'])
    print(df.head())

    ohlc_dict = {
        'open': 'first',
        'high': 'max',
        'low': 'min',
        'close': 'last',
        'volume': 'sum'
    }

    # df = df.resample('30T', on='date').agg(ohlc_dict)
    df = df.resample('1H', on='date').agg(ohlc_dict)
    # df = df.resample('2H', on='date').agg(ohlc_dict)

    null_indices = df.index[df['high'].apply(is_not_number)]

    if len(null_indices) > 0:
        warnings.warn("Data with nulls has NAN values")
        print('null_indices', null_indices)
        print("Removing NAN values, but it might cause inconsistency in data!")
        # df = df.dropna()
        df = df.drop(null_indices)

    nan_indices = df.index[df['high'].apply(pd.isnull)]

    if len(nan_indices) > 0:
        warnings.warn("Data with nulls has NAN values")
        print('nan_indices', nan_indices)
        print("Removing NAN values, but it might cause inconsistency in data!")
        # df = df.dropna()
        df = df.drop(nan_indices)

    print(df.head())

    print('Writing to file {}...'.format(output_path))
    df.to_csv(output_path, sep='\t', encoding='utf-8', columns=['open', 'high', 'low', 'close', 'volume'])
    print('Finished')

if __name__ == '__main__':
    csv_path = './fetch_new_data/savedData/data-raw.csv'
    output_path = './dataset_back/output.csv'
    resample(csv_path, output_path)