コード例 #1
0
 def read_data(self, needStore = False):
     if os.path.exists('i_data.json'):
         with open('k_data.json', 'r') as f:
             k_data = pd.read_json(f.read(), orient = 'records', lines = True)
             k_data.date = k_data.date.dt.strftime('%Y-%m-%d')
         with open('d_data.json', 'r') as f:
             d_data = pd.read_json(f.read(), orient = 'records', lines = True)
         with open('i_data.json', 'r') as f:
             i_data = pd.read_json(f.read(), orient = 'records', lines = True)
             i_data.date = i_data.date.dt.strftime('%Y-%m-%d')
     else:
         obj = CStock(self.code, dbinfo = ct.OUT_DB_INFO, redis_host = '127.0.0.1')
         k_data = obj.get_k_data()
         k_data.date = pd.to_datetime(k_data.date).dt.strftime('%Y-%m-%d')
         d_data = obj.get_chip_distribution()
         iobj = CIndex(self.index_code, dbinfo = ct.OUT_DB_INFO, redis_host = '127.0.0.1')
         i_data = iobj.get_k_data()
         cdates = k_data.date.tolist()
         i_data = i_data.loc[i_data.date.isin(cdates)]
         i_data = i_data.reset_index(drop = True)
         k_data = k_data[['date', 'open', 'high', 'low', 'close', 'volume', 'amount', 'outstanding', 'totals', 'adj', 'aprice', 'uprice', 'sprice', 'mprice', 'lprice', 'profit']]
         k_data = k_data.rename(columns = {"date": "time"})
         i_data = i_data[['date', 'open', 'high', 'low', 'close', 'volume', 'amount']]
         i_data = i_data.rename(columns = {"date": "time"})
         if needStore:
             with open('k_data.json', 'w') as f:
                 f.write(k_data.to_json(orient='records', lines=True))
             with open('d_data.json', 'w') as f:
                 f.write(d_data.to_json(orient='records', lines=True))
             with open('i_data.json', 'w') as f:
                 f.write(i_data.to_json(orient='records', lines=True))
     return k_data, d_data, i_data
コード例 #2
0
    def test_get_k_data(self, mock_create_info, mock_create, mock_sql_get):
        mock_create.return_value = True
        mock_create_info.return_value = True
        cs = CStock(ct.DB_INFO, '111111', 'testa')
        cs.get_k_data('2017-3-18')
        mock_sql_get.assert_called_with(
            "select * from `111111` where date=\"2017-3-18\"")

        cs = CStock(ct.DB_INFO, '111111', 'testa')
        cs.get_k_data()
        mock_sql_get.assert_called_with("select * from `111111`")

        cs = CStock(ct.DB_INFO, '111111a', 'testa')
        cs.get_k_data()
        mock_sql_get.assert_called_with("select * from 111111a")

        cs = CStock(ct.DB_INFO, '111111a', 'testa')
        cs.get_k_data('2017-3-19')
        mock_sql_get.assert_called_with(
            "select * from 111111a where date=\"2017-3-19\"")
コード例 #3
0
ファイル: main.py プロジェクト: github4n/smart_deal_tool
def update_stock(attr, old, new):
    code = code_text.value
    if code is None: return
    sobj = CStock(code)
    sdf = sobj.get_k_data()
    if sdf is None: return
    vdf = get_val_data(code)
    global stock_fig, profit_fig, dist_fig, roe_fig, stock_source, dist_source, val_source
    mdate = mmap_pckr.value
    mdate = mdate.strftime('%Y-%m-%d')
    ddf = sobj.get_chip_distribution(mdate)
    stock_source = ColumnDataSource(sdf)
    dist_source = ColumnDataSource(ddf)
    val_source = ColumnDataSource(vdf)
    stock_fig = create_stock_figure(stock_source)
    profit_fig = create_profit_figure(stock_source)
    dist_fig = create_dist_figure(dist_source)
    roe_fig = create_roe_figure(val_source)
    stock_fig.on_event(DoubleTap, scallback)
    layout.children[4] = gridplot([[stock_fig, dist_fig],
                                   [profit_fig, roe_fig]])
コード例 #4
0
 def get_stock_data(self, cdate, code):
     obj = CStock(code)
     return (code, obj.get_k_data(cdate, obj.get_profit_table()))
コード例 #5
0
def MA(data, peried):
    return data.rolling(peried).mean()


def VMA(price, volume, peried):
    svolume = sum(volume)
    vprice = np.array(price) * np.array(volume)
    vprice = vprice / svolume
    return MA(pd.Series(vprice), peried)


if __name__ == "__main__":
    code = '601318'
    prestr = "1" if get_market_name(code) == "sh" else "0"
    cstock = CStock(ct.DB_INFO, code)
    data = cstock.get_k_data()

    filename = "%s%s.csv" % (prestr, code)
    data = pd.read_csv("/data/tdx/history/days/%s" % filename, sep=',')
    data = data[['date', 'open', 'low', 'high', 'close', 'volume', 'amount']]
    data = data.sort_index(ascending=False)
    data = data.reset_index(drop=True)

    info = pd.read_csv("/data/tdx/base/bonus.csv",
                       sep=',',
                       dtype={
                           'code': str,
                           'market': int,
                           'type': int,
                           'money': float,
                           'price': float,