Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import pandas as pd
- import matplotlib.pyplot as plt
- import numpy as np
- from matplotlib.finance import candlestick
- from datetime import *
- def conv_str_to_datetime(x):
- return(datetime.strptime(x, '%Y%m%d %H:%M:%S.%f'))
- df = pd.read_csv('test_EURUSD/EURUSD-2012-07.csv', names=['Symbol', 'Date_Time', 'Bid', 'Ask'], index_col=1, parse_dates=True)
- PipPosition = 4
- df['Spread'] = (df['Ask'] - df['Bid']) * 10**PipPosition
- print(df)
- print("="*10)
- print(df.ix[0])
- print("Bid={0}".format(df['Bid'].mean()))
- print("Ask={0}".format(df['Ask'].mean()))
- print("Spread={0}".format(df['Spread'].mean()))
- grouped = df.groupby('Symbol')
- ask = grouped['Ask'].resample('5Min', how='ohlc')
- bid = grouped['Bid'].resample('5Min', how='ohlc')
- df2 = pd.concat([ask, bid], axis=1, keys=['Ask', 'Bid'])
- print(df2)
- #Date = df2.index.get_level_values(1).astype(object)
- #Date = pd.to_datetime(df2.index.get_level_values(1))
- Date = range(len(df2))
- #ToFix : Date !
- Open = df2['Bid']['open'].values
- Close = df2['Bid']['close'].values
- High = df2['Bid']['high'].values
- Low = df2['Bid']['low'].values
- Volume = np.zeros(len(df2))
- DOCHLV = zip(Date, Open, Close, High, Low, Volume)
- fig = plt.figure()
- fig.subplots_adjust(bottom=0.1)
- ax = fig.add_subplot(211)
- df['Bid'].plot()
- plt.title("Price graph")
- ax = fig.add_subplot(212)
- plt.title("Candlestick chart")
- candlestick(ax, DOCHLV, width=0.6, colorup='g', colordown='r', alpha=1.0)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement