Example #1
0
    quotes = fin.quotes_historical_yahoo(symbol, start, end)
    dates, open, close, high, low, volume = zip(*quotes)

    data = {"open": open, "close": close, "high": high, "low": low, "volume": volume}

    dates = Index([datetime.fromordinal(int(d)) for d in dates])
    return DataMatrix(data, index=dates)


msft = getQuotes("MSFT", startDate, endDate)
aapl = getQuotes("AAPL", startDate, endDate)
goog = getQuotes("GOOG", startDate, endDate)
ibm = getQuotes("IBM", startDate, endDate)

px = DataMatrix({"MSFT": msft["close"], "IBM": ibm["close"], "GOOG": goog["close"], "AAPL": aapl["close"]})
returns = px / px.shift(1) - 1

# Select dates

subIndex = ibm.index[(ibm["close"] > 95) & (ibm["close"] < 100)]
msftOnSameDates = msft.reindex(subIndex)

# Insert columns

msft["hi-lo spread"] = msft["high"] - msft["low"]
ibm["hi-lo spread"] = ibm["high"] - ibm["low"]

# Aggregate monthly


def toMonthly(frame, how):
Example #2
0
        'volume' : volume
    }

    dates = Index([datetime.fromordinal(int(d)) for d in dates])
    return DataMatrix(data, index=dates)

msft = getQuotes('MSFT', startDate, endDate)
aapl = getQuotes('AAPL', startDate, endDate)
goog = getQuotes('GOOG', startDate, endDate)
ibm = getQuotes('IBM', startDate, endDate)

px = DataMatrix({'MSFT' : msft['close'],
                 'IBM' : ibm['close'],
                 'GOOG' : goog['close'],
                 'AAPL' : aapl['close']})
returns = px / px.shift(1) - 1

# Select dates

subIndex = ibm.index[(ibm['close'] > 95) & (ibm['close'] < 100)]
msftOnSameDates = msft.reindex(subIndex)

# Insert columns

msft['hi-lo spread'] = msft['high'] - msft['low']
ibm['hi-lo spread'] = ibm['high'] - ibm['low']

# Aggregate monthly

def toMonthly(frame, how):
    offset = BMonthEnd()