Download and Process High Frequency Data from NetFods
来源:互联网 发布:证件照片制作软件app 编辑:程序博客网 时间:2024/06/06 08:53
API for trade data
http://hopey.netfonds.no/tradedump.php?date=20150423&paper=AAPL.O&csv_format=csvAPI for quota data should be
http://hopey.netfonds.no/posdump.php?date=20150423&paper=AAPL.O&csv_format=txt
but does not work.
Download trading price and volume
import numpy as npimport pandas as pdimport datetime as dtfrom urllib import urlretrieveurl1 = 'http://hopey.netfonds.no/tradedump.php?'url2 = 'date=%s%s%s&paper=AAPL.O&csv_format=csv'url = url1 + url2year = '2015'month = '04'days = ['20', '21', '22', '23', '24']AAPL = pd.DataFrame()for day in days: tickdata = pd.read_csv(url % (year, month, day), index_col=0, header=0, parse_dates=True) AAPL = AAPL.append(tickdata)AAPL = AAPL[['price', 'quantity']]AAPL_resample = AAPL.resample(rule='5min', how='last')Another piece of code for quota from web
from pylab import *from urllib import urlretrieveimport talibimport matplotlib.pyplot as pltfrom matplotlib.dates import date2numfrom matplotlib.finance import candlestickimport pandas as pdfrom matplotlib.dates import DateFormatter, WeekdayLocator, HourLocator, \ DayLocator, MONDAYurl='http://hopey.netfonds.no/posdump.php?date=20121130&paper=%s.O&csv_format=csv'urlretrieve(url % 'AAPL', 'AAPL.csv')urlretrieve(url % 'GOOG', 'GOOG.csv')AAPL = pd.read_csv('AAPL.csv')GOOG = pd.read_csv('GOOG.csv')AAPL = AAPL.drop_duplicates(cols='time')GOOG = GOOG.drop_duplicates(cols='time')for i in AAPL.index: AAPL['time'][i]=pd.datetime.strptime(AAPL['time'][i],'%Y%m%dT%H%M%S')#AAPL.index=AAPL['time']; del AAPL['time']AAPL.index=AAPL['time']for i in GOOG.index: GOOG['time'][i]=pd.datetime.strptime(GOOG['time'][i],'%Y%m%dT%H%M%S')#GOOG.index=GOOG['time']; del GOOG['time']GOOG.index=GOOG['time']AAPL.time = date2num(AAPL.time)GOOG.time = date2num(GOOG.time) DATA = pd.DataFrame({'AAPL':AAPL['bid'],'GOOG':GOOG['bid']}) DATA = DATA[DATA.index > pd.datetime(2012, 11, 30, 9, 59, 0)]DATA['AAPL'] = (DATA['AAPL'].fillna(method='ffill')).fillna(method='backfill')DATA['GOOG'] = (DATA['GOOG'].fillna(method='ffill')).fillna(method='backfill')DATA['GOOG_SMA'] = talib.SMA(DATA['GOOG'],1000)DATA['GOOG_FMA'] = talib.SMA(DATA['GOOG'],500)DATA['AAPL_SMA'] = talib.SMA(DATA['AAPL'],1000)DATA['AAPL_FMA'] = talib.SMA(DATA['AAPL'],500) print DATA.ix[:20].to_string()DATA = pd.DataFrame({'AAPL':AAPL['bid'], 'GOOG':GOOG['bid']})# Compute OHLC data with pandas from raw tick dataDATA_15MIN = pd.Panel({'AAPL':DATA.AAPL.resample('15min', how='ohlc', fill_method='backfill'), 'GOOG':DATA.GOOG.resample('15min', how='ohlc', fill_method='backfill')})DATA_15MIN.GOOG['time']=DATA_15MIN.GOOG.indexDATA_15MIN.AAPL['time']=DATA_15MIN.AAPL.index DATA_15MIN.GOOG = DATA_15MIN.GOOG.reindex(columns= ('time','open', 'close', 'high', 'low'))DATA_15MIN.AAPL = DATA_15MIN.AAPL.reindex(columns= ('time','open', 'close', 'high', 'low'))DATA_15MIN.GOOG['time'] = date2num(DATA_15MIN.GOOG['time'])DATA_15MIN.AAPL['time'] = date2num(DATA_15MIN.AAPL['time']) # Technical AnalysisDATA_15MIN.GOOG['SMA'] = talib.MA(DATA_15MIN.GOOG.close, 15)DATA_15MIN.GOOG['FMA'] = talib.MA(DATA_15MIN.GOOG.close, 9)DATA_15MIN.AAPL['SMA'] = talib.MA(DATA_15MIN.AAPL.close, 15)DATA_15MIN.AAPL['FMA'] = talib.MA(DATA_15MIN.AAPL.close, 9)#mondays = WeekdayLocator(MONDAY) # major ticks on the mondays#alldays = DayLocator() # minor ticks on the days#weekFormatter = DateFormatter('%b %d') # Eg, Jan 12#dayFormatter = DateFormatter('%d')fig = figure()fig.subplots_adjust(bottom=0.2)ax1 = fig.add_subplot(211)ax2 = fig.add_subplot(212)#ax.xaxis.set_major_locator(mondays)#ax.xaxis.set_minor_locator(alldays)#ax.xaxis.set_major_formatter(weekFormatter)#ax1.xaxis.set_minor_formatter(dayFormatter)#ax2.xaxis.set_minor_formatter(dayFormatter)# Plotcandlestick(ax1, np.array(DATA_15MIN.AAPL), width=(1/48), colorup='g', colordown='r')candlestick(ax2, np.array(DATA_15MIN.GOOG), width=(1/48), colorup='g', colordown='r')#fig, (ax1, ax2) = plt.subplots(2, 1, sharex = True)ax1.set_ylabel('AAPL', size=20)ax2.set_ylabel('GOOG', size=20)#DATA_15MIN.AAPL.close.plot(ax=ax1, lw=2)DATA_15MIN.AAPL.SMA.plot(ax=ax1, c = 'g', label='SMA')DATA_15MIN.AAPL.FMA.plot(ax=ax1, c = 'r', label='FMA')ax1.legend(loc='upper left')#DATA_15MIN.GOOG.close.plot(ax=ax2, lw=2)DATA_15MIN.GOOG.SMA.plot(ax=ax2, c = 'g')DATA_15MIN.GOOG.FMA.plot(ax=ax2, c = 'r')ax2.legend(loc='upper left')plt.show()print "Done."
0 0
- Download and Process High Frequency Data from NetFods
- Download and execute file under any process
- Download Chinese Stock Data from Sina Finance
- Download Option Data from Yahoo Finance
- javascript download excel file from JSON data
- Download data from new EOSDIS system
- Data Transfer Process and Error handling process
- high-frequency emphasis filter matlab
- The design and analysis of high frequency phased array coils for MRI
- Electromagnetic analysis and design of high frequency coils for magnetic resonance / Bin Xu.
- OPENXML to Publish and Process XML Data
- High quality PDF output from LaTeX and TeX
- High Performance Data Mining - Scaling Algorithms, Applications and Systems
- download video from "ku6" web site and change to mp3
- How to upload and download image from habase?
- Data Blocks and Freelists (from ixora)
- Configuration data download to FPGA was not successful. DONE did not go high, please check your con
- Debug Support from Process, Thread, and Exception Functions
- C++ Primer第四版习题--3.8
- Android 网络框架学习之Retrofit
- spring与jpa整合 除去persistence.xml设备文件 应用属性文件 数据源dbcp接见数据库
- iframe重新加载主页的脚本
- 直接插入排序和希尔排序
- Download and Process High Frequency Data from NetFods
- Active MQ使用场景
- Selective Search for Object Recognition
- 数据库 - 数据库完整性
- Map<String,String> m=new HashMap<String,String>()和HashMap<String,String> hashMapOut=new HashMap<Stri
- Spss中非参数检验的两个独立样本检验
- Java基础知识复习(一)
- 事件驱动模型
- 在 MFC 中检测内存泄漏