예제 #1
0
"""
.. moduleauthor:: Li, Wang <*****@*****.**>
"""

import os
from string import Template

import pandas as pd
import logbook
logbook.set_datetime_format('local')
logger = logbook.Logger('universe')

from orca.mongo.barra import BarraFetcher
barra_fetcher = BarraFetcher('short')
bid_sid = barra_fetcher.fetch_idmaps()


def generate_path(path_pattern, date):
    return Template(path_pattern).substitute(YYYYMMDD=date,
                                             YYYYMM=date[:6],
                                             YYYY=date[:4],
                                             MM=date[4:6],
                                             DD=date[6:8])


def prep_universe_lance(account, date, output):
    path = os.path.join('/home/liulc/trade_' + account, 'barra', date[:4],
                        date[4:6], date[6:8], 'universe.' + date)
    bid = pd.read_csv(path, header=0, dtype={0: str}).iloc[:, 0]
    bid = bid.ix[bid.apply(lambda x: x in bid_sid)]
    sid = bid.map(bid_sid)
예제 #2
0
"""
.. moduleauthor:: Li, Wang <*****@*****.**>
"""

import os
from string import Template

import pandas as pd
import logbook
logbook.set_datetime_format('local')
logger = logbook.Logger('universe')

from orca.mongo.barra import BarraFetcher
barra_fetcher = BarraFetcher('short')
bid_sid = barra_fetcher.fetch_idmaps()

def generate_path(path_pattern, date):
    return Template(path_pattern).substitute(YYYYMMDD=date, YYYYMM=date[:6], YYYY=date[:4], MM=date[4:6], DD=date[6:8])

def prep_universe_lance(account, date, output):
    path = os.path.join('/home/liulc/trade_'+account, 'barra', date[:4], date[4:6], date[6:8], 'universe.'+date)
    bid = pd.read_csv(path, header=0, dtype={0: str}).iloc[:,0]
    bid = bid.ix[bid.apply(lambda x: x in bid_sid)]
    sid = bid.map(bid_sid)
    sid_bid = barra_fetcher.fetch_idmaps(date=DATES[DATES.index(date)-1], barra_key=False)
    bid = sid.map(sid_bid)
    is_regular = sid.apply(lambda x: len(x) == 6 and x[:2] in ('00', '30', '60'))
    df = pd.concat([sid.ix[is_regular], bid.ix[is_regular]], axis=1)
    df.columns = ['sid', 'bid']

    output = generate_path(output, date)
예제 #3
0
 def test_idmaps2(self):
     barra = BarraFetcher.fetch_idmaps()
     sids = BarraFetcher.fetch_idmaps(barra_key=False)
     self.assertDictEqual(barra, {v: k for k, v in sids.iteritems()})
예제 #4
0
"""
.. moduleauthor:: Li, Wang <*****@*****.**>
"""

import os
from string import Template

import pandas as pd
import logbook

logbook.set_datetime_format('local')
logger = logbook.Logger('assets')
from orca.mongo.barra import BarraFetcher

barra_fetcher = BarraFetcher('short')


def generate_path(path_pattern, date):
    return Template(path_pattern).substitute(YYYYMMDD=date,
                                             YYYYMM=date[:6],
                                             YYYY=date[:4],
                                             MM=date[4:6],
                                             DD=date[6:8])


def prep_assets_lance(account, date, output):
    path = os.path.join('/home/liulc/trade_' + account, 'barra', date[:4],
                        date[4:6], date[6:8], 'assets.' + date)
    df = pd.read_csv(path, header=0, dtype={0: str}).iloc[:, :3]
    df.columns = ['sid', 'bid', 'alpha']
예제 #5
0
 def test_idmaps1(self):
     barra = BarraFetcher.fetch_idmaps()
     self.assertIsInstance(barra, dict)