"""
Created on Wed May 2 13:41:08 2018
@author: luogan
"""
"""
Created on Tue May 1 19:32:14 2018
@author: luogan
"""
"""
Created on Thu Dec 14 15:26:31 2017
@author: 量化之王
"""
import pymongo
import pandas
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import pylab as pl
import datetime
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter, WeekdayLocator, DayLocator, MONDAY,YEARLY
from matplotlib.finance import quotes_historical_yahoo_ohlc, candlestick_ohlc
from matplotlib.pylab import date2num
import talib
from dateutil.parser import parse
import tushare as ts
client1 = pymongo.MongoClient('192.168.10.182',27017)
db1 = client1.stock.ma250
'''
def before_month_lastday(ti):
from dateutil.parser import parse
today=parse(str(ti))
#first = datetime.date(day=1, month=today.month, year=today.year)
client1 = pymongo.MongoClient('192.168.10.182',27017)
db1 = client1.stock.potential
lastMonth = today - datetime.timedelta(days=0)
def plus(k):
if k<10:
return '0'+str(k)
else:
return str(k)
y=lastMonth.year
m=lastMonth.month
d=lastMonth.day
#day=calendar.monthrange(y,m)[1]
cc=str(y)+plus(m)+plus(d)
#bb=parse(cc)
#pacific = pytz.timezone('Asia/Shanghai')
#return pacific.localize(bb)
return int(cc)
'''
def polyfit(c,k):
xlist=list(range(len(c)))
bbz1 = np.polyfit(xlist, c,k)
return bbz1[0]
def potential_index(tl):
df=ts.get_hist_data(tl[0],start=tl[1],end=tl[2])
if str(type(df))!="<class 'NoneType'>":
if df.shape[0]>250:
date=df.index
date1=list(map(parse,date))
df['date']=date1
df=df.sort_values(by='date')
closed=df['close'].values
ma250=talib.SMA(closed,timeperiod=250)
p=ma250[-1]
n=closed[-1]
print('p=',p)
print('n=',n)
ra=(p-n)/min(p,n)
s1=pd.Series(ma250)
s2=s1.dropna()
s3=list(s2)
kk=polyfit(s3,1)
if abs(ra)<0.03 and kk>0:
print('kk=',kk)
print('ra=',ra)
print('name',tl[0])
db1.save({'name':tl[0]})
print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
ak=ts.get_stock_basics()
code=list(ak.index)
def front_step_time(day):
now = datetime.datetime.now()
front = now - datetime.timedelta(days=day)
d1 = front.strftime('%Y-%m-%d')
return d1
now=front_step_time(0)
bf=front_step_time(720)
sheet=pd.DataFrame()
sheet['code']=code
sheet['bf']=bf
sheet['sta']=now
import time
from multiprocessing import Pool
import numpy as np
te =sheet.values
'''
for name in te:
mm=potential_index(name)
#print(name,mm)
'''
if __name__ == "__main__" :
startTime = time.time()
testFL =sheet.values
pool = Pool(20)
pool.map(potential_index,testFL)
pool.close()
pool.join()
endTime = time.time()
print ("time :", endTime - startTime)