SHARE
TWEET

Untitled

a guest Mar 26th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. import numpy as np
  3. from datetime import datetime
  4.  
  5.  
  6. def dt2epoch(value):
  7.     epoch = (value - datetime(1970, 1, 1)).total_seconds()
  8.     return epoch
  9.  
  10.  
  11. df = pd.read_csv("data/ES ##-##-1-Minute.csv", sep=";")
  12. df['Datetime'] = pd.to_datetime(df['Datetime'])
  13. df['Datetime'] = df['Datetime'].apply(dt2epoch)
  14. df['Datetime'] = df['Datetime'].astype('uint64')
  15.  
  16. lines = ["ohlc"
  17.          + ",symbol=ES"
  18.          + ",type=min"
  19.          + " "
  20.          + "frame=1i,"
  21.          + "cons=" + str(d) + "i,"
  22.          + "close=" + str(df['Close'][d]) + ","
  23.          + "high=" + str(df['High'][d]) + ","
  24.          + "low=" + str(df['Low'][d]) + ","
  25.          + "open=" + str(df['Open'][d]) #+ ","
  26.         #+ "volume=" + str(df['Volume'][d])
  27.          + " " + str(df['Datetime'][d]) for d in range(len(df))]
  28.  
  29.  
  30. out = np.array_split(lines, 4)
  31.  
  32. for i, list in enumerate(out):
  33.     file = open('data/ES 1 min part {}.txt'.format(i), 'w')
  34.  
  35.     file.write("# DDL\n")
  36.     file.write("CREATE DATABASE financial_data\n")
  37.  
  38.     file.write("# DML\n")
  39.     file.write("# CONTEXT-DATABASE: financial_data\n")
  40.  
  41.     for item in list:
  42.         file.write("{}\n".format(item))
  43.  
  44.     file.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top