Esempio n. 1
0
import talib
import importlib
import rschLib

np.set_printoptions(formatter={'float_kind': "{:.6f}".format})
client = pymongo.MongoClient('localhost', 27017)
#db = rschLib.db_quanLiang()
#dbt = rschLib.db_tinySoftData()
dtes, tkrs, name, open_mtx, high_mtx, low_mtx, close_mtx, belong, shenwan1, shenwan2, shenwan3, vol_mtx, amount_mtx = rschLib.loadDailyBarMtx(
    "D:\\pklWeeklyUpdate\\")
# get time labels
# get trades

# In[13]:

strategy_names = [x['file'] for x in rschLib.tagDict().values()]
offStarts = [x['off_start'] for x in rschLib.tagDict().values()]
importlib.reload(rschLib)

# In[73]:


def analyzeStrategy(strategy_name, offStart, dtes, name, tkrs):
    timeAsFloat, timeLabels, maxM, dayOff, dayTimeAsFloat = rschLib.getTimeLabels(
        maxD)
    R = open_mtx[:, 1:] / close_mtx[:, :-1] - 1  #使用收盘到开盘的回报率来修正分红和拆股
    R = np.hstack((np.zeros((R.shape[0], 1)), R))
    tradesUsed, r_withnan = rschLib.getTradesFast(strategy_name, name, tkrs,
                                                  dtes, maxD, dayTimeAsFloat,
                                                  R)
    # get trade samples by good/bad trades
Esempio n. 2
0
maxD = 5
timeAsFloat, timeLabels, maxM, dayOff = rschLib.getTimeLabels(maxD)
importlib.reload(rschLib)
tt, tradesUsed, Po, r = rschLib.getTradesWithPklCache(
    q['strategy_name_original'], name, tkrs, dtes, maxD, maxM)

# In[26]:

m = db.strategyBackTest.find_one(
    {'strategy_name': q['strategy_name_original']})
if ('off_start' in m.keys()):
    strategy_off_start = (m['off_start'][0], m['off_start'][1])

# In[27]:

d = rschLib.tagDict()
k = list(d.keys())
t = list([x['file'] for x in d.values()])
t.index(q['tagToAdd'])
tagName = k[t.index(q['tagToAdd'])]
tag_off_start = d[tagName]['off_start']
with open("d:\\pkl\\" + q['tagToAdd'] + ".pkl", 'rb+') as f:
    tagFile = pickle.load(f)
    tagMtx = tagFile['tag_mtx']

# In[28]:

[p, idxTradesOverLapped] = rschLib.totInTag(range(len(tradesUsed)), tagMtx,
                                            dtes, tkrs, tradesUsed,
                                            strategy_off_start, tag_off_start)
print(p)
Esempio n. 3
0
            query.append({
                'strategy_name':strategy_name,
                'name':y,
                'ticker':tk[i],
                'dateIn':int(x)
            })
        if len(query)>0:
            db.strategyBackTestTrades.insert_many(query)
    rschLib.updateStrategyGeneratingStatus(strategy_name, '生成进度:10%。初始化标签。'+str(datetime.datetime.now()),10)


# In[3]:


importlib.reload(rschLib)
tagNames = list(rschLib.tagDict().keys())
for q in range(len(tagNames)):
    generateTagAnalysis(tagNames[q])


# In[4]:


# importlib.reload(rschLib)
# %load_ext line_profiler
# %lprun -f generateTagAnalysis generateTagAnalysis(tagName)


# In[ ]: