def main(): # db = psql.get_db() # product_codes = db.prepare('''SELECT p.code AS code, p.id as id # FROM products p LEFT JOIN companies c ON p.company_id = c.id # WHERE c.sector IS NOT NULL # and p.id < 9354 # ORDER BY p.id''')() product_codes = ds.idx_components('^DJI').index total = len(product_codes) cur = 0 products=[] logger.info('Start downloading of %d products.', len(product_codes)) for code in product_codes: cur += 1 try: product = ds.ohlc(code, 'yahoo', start=date_from, end=date_to) except: logger.warn('(%d/%d) Fail downloading %s.', cur, total, code) continue product.code = code products.append(product) logger.info('(%d/%d) Downloaded %s.', cur, total, code) logger.info('Download complete.') return opt(products)
def demo(code='AAPL', start='2003-01-01', end='2013-01-01'): product = ds.ohlc(code, start=start, end=end) product.code = code opt([product])
def apply(self): self.analyze() self.summary() # self.plot() def __call__(self, *args, **kwargs): self.__dict__.update(kwargs) self.analyze() return self.revenue if __name__ == '__main__': from pandas.io.data import DataReader import corpfin.datasource.online as ds date_from = '2003-01-01' date_to = '2013-01-01' code = 'GOOG' product = ds.ohlc(code, start=date_from, end=date_to) product.code = code model = MACD(12, 26, 9, verbose=True) model.product = product model.analyze() model.summary() # From 2003-01-01 to 2013-01-01, MACD(12, 26, 9) # Trade stat: 154 trades, total revenue 6904.1657838