import statsmodels.api as sm
from mpl_toolkits.axisartist.axislines import SubplotZero
#from pandas.stats.api import ols
from jqfactor import get_factor_values
from jqdata import *
import pandas as pd
import talib as ta
import copy
from datetime import datetime,timedelta
from dateutil.relativedelta import relativedelta
import time
# fields=['time', 'current', 'high', 'low', 'volume', 'money']
today = (datetime.now() - timedelta(days=0)).strftime('%Y-%m-%d')
#today = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d')
today_end = datetime.strptime(today,'%Y-%m-%d')+timedelta(hours=15)
#固定日期
fix_date = '2019-05-07'
fix_date_end = datetime.strptime(fix_date,'%Y-%m-%d')+timedelta(hours=15)
#是否使用今天
use_today = 0
#测试股票代码
stock = '000815.XSHE'
if use_today ==1:
date = today
date_end = today_end
elif use_today == 0:
date = fix_date
date_end = fix_date_end
#df = get_ticks(stock,start_dt=date, end_dt=date_end,fields=['time', 'current', 'volume', 'money'])
nearCode = 'M1409.XDCE'
farCode = 'M1501.XDCE'
edate='2015-2-1'
df = get_price(nearCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2 = get_price(farCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2['diff']=df2['close']-df['close'];
#print(df)
#df = get_ticks("000001.XSHG",start_dt="2019-03-26", end_dt="2019-03-26 15:00:00")
#print(df);
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15,3))
ax=SubplotZero(fig,1,1,1)
ax.grid(True, linestyle='-.')
fig.add_subplot(ax)
plt.plot(df['close'])
plt.plot(df2['close'])
plt.show()
#plt.figure(figsize=(10,3))
#plt.plot(df2['diff'])
#plt.show()
write_file('技术面/near91_df.csv', pd.DataFrame(df).to_csv(), append=False);
write_file('技术面/far91_df.csv', pd.DataFrame(df2).to_csv(), append=False);
nearCode = 'M1505.XDCE'
farCode = 'M1509.XDCE'
edate='2015-10-1'
df = get_price(nearCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2 = get_price(farCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2['diff']=df2['close']-df['close'];
#print(df)
#df = get_ticks("000001.XSHG",start_dt="2019-03-26", end_dt="2019-03-26 15:00:00")
#print(df);
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15,3))
ax=SubplotZero(fig,1,1,1)
ax.grid(True, linestyle='-.')
fig.add_subplot(ax)
plt.plot(df['close'])
plt.plot(df2['close'])
#plt.show()
#plt.figure()
#plt.plot(df2['diff'])
plt.show()
write_file('技术面/near59_df.csv', pd.DataFrame(df).to_csv(), append=False)
write_file('技术面/far59_df.csv', pd.DataFrame(df2).to_csv(), append=False)
6910
#df = get_ticks(stock,start_dt=date, end_dt=date_end,fields=['time', 'current', 'volume', 'money'])
nearCode = 'M1509.XDCE'
farCode = 'M1601.XDCE'
edate='2016-2-1'
df = get_price(nearCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2 = get_price(farCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2['diff']=df2['close']-df['close'];
#print(df)
#df = get_ticks("000001.XSHG",start_dt="2019-03-26", end_dt="2019-03-26 15:00:00")
#print(df);
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15,3))
ax=SubplotZero(fig,1,1,1)
ax.grid(True, linestyle='-.')
fig.add_subplot(ax)
plt.plot(df['close'])
plt.plot(df2['close'])
plt.show()
#plt.figure(figsize=(10,3))
#plt.plot(df2['diff'])
#plt.show()
write_file('技术面/near91_df.csv', pd.DataFrame(df).to_csv(), append=False);
write_file('技术面/far91_df.csv', pd.DataFrame(df2).to_csv(), append=False);
nearCode = 'M1605.XDCE'
farCode = 'M1609.XDCE'
edate='2016-10-1'
df = get_price(nearCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2 = get_price(farCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2['diff']=df2['close']-df['close'];
#print(df)
#df = get_ticks("000001.XSHG",start_dt="2019-03-26", end_dt="2019-03-26 15:00:00")
#print(df);
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15,3))
ax=SubplotZero(fig,1,1,1)
ax.grid(True, linestyle='-.')
fig.add_subplot(ax)
plt.plot(df['close'])
plt.plot(df2['close'])
#plt.show()
#plt.figure()
#plt.plot(df2['diff'])
plt.show()
write_file('技术面/near59_df.csv', pd.DataFrame(df).to_csv(), append=False)
write_file('技术面/far59_df.csv', pd.DataFrame(df2).to_csv(), append=False)
6895
#df = get_ticks(stock,start_dt=date, end_dt=date_end,fields=['time', 'current', 'volume', 'money'])
nearCode = 'M1609.XDCE'
farCode = 'M1701.XDCE'
edate='2017-2-1'
df = get_price(nearCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2 = get_price(farCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2['diff']=df2['close']-df['close'];
#print(df)
#df = get_ticks("000001.XSHG",start_dt="2019-03-26", end_dt="2019-03-26 15:00:00")
#print(df);
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15,3))
ax=SubplotZero(fig,1,1,1)
ax.grid(True, linestyle='-.')
fig.add_subplot(ax)
plt.plot(df['close'])
plt.plot(df2['close'])
plt.show()
#plt.figure(figsize=(10,3))
#plt.plot(df2['diff'])
#plt.show()
write_file('技术面/near91_df.csv', pd.DataFrame(df).to_csv(), append=False);
write_file('技术面/far91_df.csv', pd.DataFrame(df2).to_csv(), append=False);
nearCode = 'M1705.XDCE'
farCode = 'M1709.XDCE'
edate='2017-10-1'
df = get_price(nearCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2 = get_price(farCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2['diff']=df2['close']-df['close'];
#print(df)
#df = get_ticks("000001.XSHG",start_dt="2019-03-26", end_dt="2019-03-26 15:00:00")
#print(df);
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15,3))
ax=SubplotZero(fig,1,1,1)
ax.grid(True, linestyle='-.')
fig.add_subplot(ax)
plt.plot(df['close'])
plt.plot(df2['close'])
#plt.show()
#plt.figure()
#plt.plot(df2['diff'])
plt.show()
write_file('技术面/near59_df.csv', pd.DataFrame(df).to_csv(), append=False)
write_file('技术面/far59_df.csv', pd.DataFrame(df2).to_csv(), append=False)
6842
#df = get_ticks(stock,start_dt=date, end_dt=date_end,fields=['time', 'current', 'volume', 'money'])
nearCode = 'M1709.XDCE'
farCode = 'M1801.XDCE'
edate='2018-2-1'
df = get_price(nearCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2 = get_price(farCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2['diff']=df2['close']-df['close'];
#print(df)
#df = get_ticks("000001.XSHG",start_dt="2019-03-26", end_dt="2019-03-26 15:00:00")
#print(df);
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15,3))
ax=SubplotZero(fig,1,1,1)
ax.grid(True, linestyle='-.')
fig.add_subplot(ax)
plt.plot(df['close'])
plt.plot(df2['close'])
plt.show()
#plt.figure(figsize=(10,3))
#plt.plot(df2['diff'])
#plt.show()
write_file('技术面/near91_df.csv', pd.DataFrame(df).to_csv(), append=False);
write_file('技术面/far91_df.csv', pd.DataFrame(df2).to_csv(), append=False);
nearCode = 'M1805.XDCE'
farCode = 'M1809.XDCE'
edate='2018-10-1'
df = get_price(nearCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2 = get_price(farCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2['diff']=df2['close']-df['close'];
#print(df)
#df = get_ticks("000001.XSHG",start_dt="2019-03-26", end_dt="2019-03-26 15:00:00")
#print(df);
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15,3))
ax=SubplotZero(fig,1,1,1)
ax.grid(True, linestyle='-.')
fig.add_subplot(ax)
plt.plot(df['close'])
plt.plot(df2['close'])
#plt.show()
#plt.figure()
#plt.plot(df2['diff'])
plt.show()
write_file('技术面/near59_df.csv', pd.DataFrame(df).to_csv(), append=False)
write_file('技术面/far59_df.csv', pd.DataFrame(df2).to_csv(), append=False)
6942
#df = get_ticks(stock,start_dt=date, end_dt=date_end,fields=['time', 'current', 'volume', 'money'])
nearCode = 'M1809.XDCE'
farCode = 'M1901.XDCE'
edate='2019-2-1'
df = get_price(nearCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2 = get_price(farCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2['diff']=df2['close']-df['close'];
#print(df)
#df = get_ticks("000001.XSHG",start_dt="2019-03-26", end_dt="2019-03-26 15:00:00")
#print(df);
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15,3))
ax=SubplotZero(fig,1,1,1)
ax.grid(True, linestyle='-.')
fig.add_subplot(ax)
plt.plot(df['close'])
plt.plot(df2['close'])
plt.show()
#plt.figure(figsize=(10,3))
#plt.plot(df2['diff'])
#plt.show()
write_file('技术面/near91_df.csv', pd.DataFrame(df).to_csv(), append=False);
write_file('技术面/far91_df.csv', pd.DataFrame(df2).to_csv(), append=False);
nearCode = 'M1905.XDCE'
farCode = 'M1909.XDCE'
edate='2019-10-1'
df = get_price(nearCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2 = get_price(farCode,count=200,end_date=edate,frequency='1d',fields=['close','high','low']);
df2['diff']=df2['close']-df['close'];
#print(df)
#df = get_ticks("000001.XSHG",start_dt="2019-03-26", end_dt="2019-03-26 15:00:00")
#print(df);
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15,3))
ax=SubplotZero(fig,1,1,1)
ax.grid(True, linestyle='-.')
fig.add_subplot(ax)
plt.plot(df['close'])
plt.plot(df2['close'])
#plt.show()
#plt.figure()
#plt.plot(df2['diff'])
plt.show()
write_file('技术面/near59_df.csv', pd.DataFrame(df).to_csv(), append=False)
write_file('技术面/far59_df.csv', pd.DataFrame(df2).to_csv(), append=False)
6866
本社区仅针对特定人员开放
查看需注册登录并通过风险意识测评
5秒后跳转登录页面...
移动端课程