예제 #1
0
파일: test_sqla.py 프로젝트: azflin/trump
class TestToolsSQLA(object):
    
    def setup_method(self, test_method):
        self.eng = SetupTrump()
        self.sm = SymbolManager(self.eng)

    def test_repr_mixin(self):
        sym = self.sm.create("testsym", overwrite=True)
        assert repr(sym) == """Symbol(name=u'testsym', description=None, units=None, agg_method=u'priority_fill', freshthresh=0)"""
        
예제 #2
0
class TestToolsSQLA(object):
    def setup_method(self, test_method):
        self.eng = SetupTrump()
        self.sm = SymbolManager(self.eng)

    def test_repr_mixin(self):
        sym = self.sm.create("testsym", overwrite=True)
        assert repr(
            sym
        ) == """Symbol(name=u'testsym', description=None, units=None, agg_method=u'priority_fill', freshthresh=0)"""
예제 #3
0
class TestToolsSQLA(object):
    
    def setup_method(self, test_method):
        self.eng = SetupTrump()
        self.sm = SymbolManager(self.eng)

    def test_metamatrix(self):
        tikrs = [x * 3 for x in list('jkl')]
        syms = []
        for s in tikrs:
            sym = self.sm.create(s, overwrite=True)
            sym.add_meta(alpha='a', beta='b', charlie='c')
            syms.append(sym)
        
        mm = MetaMatrix(syms)
        
        mmr = mm(['alpha','beta'])
        
        exp = pd.DataFrame({'alpha' : ['a'] * 3,
                            'beta' : ['b'] * 3}, index = tikrs)
        
        exp.index.name = 'trumpsym'        
        assert_frame_equal(mmr, exp)
예제 #4
0
# -*- coding: utf-8 -*-

from trump.orm import SymbolManager
from trump.templating import QuandlFT, QuandlSecureFT, SQLFT
from trump.tools.bitflags import BitFlag
from datetime import datetime as dt

sm = SymbolManager()

oil = sm.create(name="oil_front_month", overwrite=True)

oil.index.case = "asfreq"
oil.index.setkwargs(freq='W', method='ffill')
sm.ses.commit()

f1 = QuandlFT(r"CHRIS/CME_CL3", fieldname='Settle')

oil.add_feed(f1)

oil.cache()

print oil.df.tail()

print oil.df.index
예제 #5
0
# -*- coding: utf-8 -*-

from trump.orm import SymbolManager
from trump.templating import QuandlFT, QuandlSecureFT, SQLFT
from datetime import datetime as dt

sm = SymbolManager()

oil = sm.create(
    name="oil_front_month",
    description="Crude Oil Futures, Continuous Contract #2 (CL2) (Front Month)",
    units='$ / barrel')

oil.add_alias("OILA")
oil.add_tags(['commodity', 'oil'])

f1 = QuandlFT(r"CHRIS/CME_CL2", fieldname='Settle')
f2 = QuandlSecureFT(r"CHRIS/CME_CL3", fieldname='Settle')
f3 = SQLFT("SELECT date,data FROM test_oil_data;")

oil.add_feed(f1)
oil.add_feed(f2)
oil.add_feed(f3)

oil.add_override(dt(2015, 1, 6), 50.0, user='******')
oil.add_fail_safe(dt(2015, 1, 6), 45.0, user='******')

df = oil.cache()

print oil.df.tail()
예제 #6
0
# -*- coding: utf-8 -*-

from trump.orm import SymbolManager
from trump.templating import QuandlFT, QuandlSecureFT, SQLFT
from trump.tools.bitflags import  BitFlag
from datetime import datetime as dt

sm = SymbolManager()

oil = sm.create(name = "oil_front_month", overwrite=True)

f1 = QuandlFT(r"CHRIS/CME_CL3",fieldname='Settle')

oil.add_feed(f1)

oil.cache()

print oil.df.tail()

oil._reset_datatable()

oil.cache()

print oil.df.tail()
예제 #7
0
파일: multi_add.py 프로젝트: Asiant/trump
# -*- coding: utf-8 -*-

from trump.orm import SymbolManager
from trump.templating import QuandlFT, GoogleFinanceFT, YahooFinanceFT

sm = SymbolManager()

TSLA = sm.create(name = "TSLA", description = "Tesla Closing Price USD",
                units = '$ / share')

TSLA.add_tags(["stocks","US"])

#Try Google First
#If Google's feed has a problem, try Quandl's backup
#If all else fails, use Yahoo's data...

TSLA.add_feed(GoogleFinanceFT("TSLA"))
TSLA.add_feed(QuandlFT("GOOG/NASDAQ_TSLA",fieldname='Close'))
TSLA.add_feed(YahooFinanceFT("TSLA"))

#All three are downloaded, with every cache instruction
TSLA.cache()

# Trump's plans for various aggregation, munging, and validity checking can
# use the intelligence of multiple feeds to compare and clean up the data
# if a variety common problems exist. These features are few months off,
# but a priority in Trump's plans.

# In the end, you're left with one clean pandas Series representing TSLA's closing
# price, with source, munging, validity checks, all stored persistently for future
# re-caching.
예제 #8
0
파일: simple_add.py 프로젝트: Asiant/trump
# -*- coding: utf-8 -*-

from trump.orm import SymbolManager
from trump.templating import QuandlFT, QuandlSecureFT, SQLFT
from datetime import datetime as dt

sm = SymbolManager()

oil = sm.create(name = "oil_front_month",
                description = "Crude Oil Futures, Continuous Contract #2 (CL2) (Front Month)",
                units = '$ / barrel')

oil.add_alias("OILA")
oil.add_tags(['commodity','oil'])

f1 = QuandlFT(r"CHRIS/CME_CL2",fieldname='Settle')
f2 = QuandlSecureFT(r"CHRIS/CME_CL3",fieldname='Settle')
f3 = SQLFT("SELECT date,data FROM test_oil_data;")

oil.add_feed(f1)
oil.add_feed(f2)
oil.add_feed(f3)

oil.add_override(dt(2015,1,6),50.0,user='******')
oil.add_fail_safe(dt(2015,1,6),45.0,user='******')

df = oil.cache()

print oil.df.tail()
            
예제 #9
0
# -*- coding: utf-8 -*-
"""
Created on Sat Jun  6 16:02:28 2015

@author: jnm
"""

from trump.orm import SymbolManager
from trump.templating.templates import FFillIT, WorldBankFT, StLouisFEDFT, QuandlFT, GoogleFinanceFT, YahooFinanceFT

sm = SymbolManager()

xiu = sm.create('XIU', overwrite=True)
xiu.add_tags(['ETF', 'iShares'])
xiu.add_meta(Geography='Canada', AssetClass='Equity', MER="0.07")
xiu.set_description("S&P/TSX 60 Index Fund")
xiu.set_units("CAD/unit")
#xiu.add_feed(GoogleFinanceFT('TSE:XIU'))
xiu.add_feed(YahooFinanceFT('XIU.TO'))
xiu.cache()

spy = sm.create('SPY', overwrite=True)
spy.add_tags(['ETF', 'equity'])
spy.set_description("SPDR S&P 500 ETF Trust")
spy.add_meta(Geography='USA', AssetClass='Equity', Index='S&P 500', MER="0.11", CUSIP="78462F103", Exchange="NYSE")
spy.set_units("USD/unit")
spy.add_feed(YahooFinanceFT('SPY'))
spy.cache()

tsla = sm.create('TSLA', overwrite=True)
tsla.add_tags(['ETF', 'equity', 'Company'])
예제 #10
0
파일: add.py 프로젝트: jnmclarty/trump
info = namedtuple('info',['description','ticker'])

oil = {"EU" : [info("Europe Brent Crude Oil Spot Price FOB", r"DOE/RBRTE")],
       "US" : [info("WTI Crude Oil Spot Price Cushing, OK FOB", r"DOE/RWTC")],
       "CONT" : [info("Crude Oil Futures, Continuous Contracts",r"CHRIS/CME_CL1"),
                info("Crude Oil Futures, Continuous Contract #2 (CL2) (Front Month)",r"CHRIS/CME_CL2")]}

sm = SymbolManager()

rawmunging = False
templatedmunging = True

if rawmunging:
    for oil_sym,oil_info_l in oil.iteritems():
        new_sym = sm.create("oil_" + oil_sym,"Quandl - " + oil_info_l[0].description,'D','$ / barrel')
        for oil_info in oil_info_l:
            f = QuandlFT(oil_info.ticker,fieldname='Settle')
    
            f.addMunging('crop_dates',{'start' : '2000-01-01', 'end' : '2015-01-01'})
            f.addMunging('multiply_const',3)
    
            new_sym.add_feed(f,fillna={'method' : 'ffill'},exp_const=(3,['a','b','c'],{'n' : 123}),add_const={'n' : 55})
        new_sym.add_alias(oil_sym + "_oil")
        new_sym.add_tags(['commodity','oil','quandl'])
        
        if oil_sym == 'CONT':
            new_sym.add_override(dt(2015,1,6),50.0,user='******')
            new_sym.add_fail_safe(dt(2015,1,6),45.0,user='******')
            
elif templatedmunging:
예제 #11
0
            desc['Premium'] = doc['premium'] 
            desc['url'] = doc['display_url']
        
            if freq == 'daily':
                freq = 'D'
            elif freq == 'quarterly':
                freq = 'Q'
            elif freq == 'annual':
                freq = 'A'
            
            meta, desc = desc, name
            
            for col in cols:
                symname = code.split("_")[0] + "_" + col.replace(" ", "_").replace("/","_")
                
                sym = sm.create(symname, overwrite=True)
                
                qdl = QuandlSecureFT("NVCA/" + code, fieldname=col)
                sym.add_feed(qdl)
                
                sym.add_tags(("US", "Venture Capital"))
                sym.set_description(desc)
                sym.set_units(units)
                sym.add_meta(**meta)
                
                ind = FFillIT(freq)
                sym.set_indexing(ind)
                #sym.cache()

if doraymond:
    r = requests.get('https://www.quandl.com/api/v2/datasets.json?query=*&source_code=RAYMOND&per_page=300&page=1&auth_token=y9RJp7f7DRW3Aj7FEqq1')
예제 #12
0
# -*- coding: utf-8 -*-

from trump.orm import SymbolManager
from trump.templating import QuandlFT, GoogleFinanceFT, YahooFinanceFT

sm = SymbolManager()

TSLA = sm.create(name="TSLA",
                 description="Tesla Closing Price USD",
                 units='$ / share')

TSLA.add_tags(["stocks", "US"])

#Try Google First
#If Google's feed has a problem, try Quandl's backup
#If all else fails, use Yahoo's data...

TSLA.add_feed(GoogleFinanceFT("TSLA"))
TSLA.add_feed(QuandlFT("GOOG/NASDAQ_TSLA", fieldname='Close'))
TSLA.add_feed(YahooFinanceFT("TSLA"))

#All three are downloaded, with every cache instruction
TSLA.cache()

# Trump's plans for various aggregation, munging, and validity checking can
# use the intelligence of multiple feeds to compare and clean up the data
# if a variety common problems exist. These features are few months off,
# but a priority in Trump's plans.

# In the end, you're left with one clean pandas Series representing TSLA's closing
# price, with source, munging, validity checks, all stored persistently for future