def load_data(): symbols = ['XOM', 'AAPL', 'MSFT', 'JNJ', 'GE', 'GOOG', 'CVX', 'PG', 'WFC'] cap = {'^GSPC':14.90e12, 'XOM':403.02e9, 'AAPL':392.90e9, 'MSFT':283.60e9, 'JNJ':243.17e9, 'GE':236.79e9, 'GOOG':292.72e9, 'CVX':231.03e9, 'PG':214.99e9, 'WFC':218.79e9} n = len(symbols) prices_out, caps_out = [], [] for s in symbols: print("Reading symbol %s" % s) q = QuoteSeries.loadfromfile(s, 'data/black_litterman/%s.csv' % s) prices = q.getprices()[-500:] prices_out.append(prices) caps_out.append(cap[s]) return symbols, prices_out, caps_out
def getquotesfromstring(symbol, string): linecount = 0 data = [] for line in string.split("\\n"): linecount += 1 entries = line.split(",") if len(entries) != 7 or linecount == 1: continue quote = Quote(datetime.strptime(entries[0], '%Y-%m-%d'), float(entries[1]), float(entries[2]), float(entries[3]), float(entries[4]), int(entries[5])) data.append(quote) reversedIterator = reversed(data) return QuoteSeries(symbol, list(reversedIterator))
def load_data(): symbols = ['XOM', 'AAPL', 'MSFT', 'JNJ', 'GE', 'GOOG', 'CVX', 'PG', 'WFC'] cap = { '^GSPC': 14.90e12, 'XOM': 403.02e9, 'AAPL': 392.90e9, 'MSFT': 283.60e9, 'JNJ': 243.17e9, 'GE': 236.79e9, 'GOOG': 292.72e9, 'CVX': 231.03e9, 'PG': 214.99e9, 'WFC': 218.79e9 } n = len(symbols) prices_out, caps_out = [], [] for s in symbols: print("Reading symbol %s" % s) q = QuoteSeries.loadfromfile(s, 'data/black_litterman/%s.csv' % s) prices = q.getprices()[-500:] prices_out.append(prices) caps_out.append(cap[s]) return symbols, prices_out, caps_out
# Copyright (c) 2012 Quantitative & Financial, All rights reserved # www.quantandfinancial.com import datasources.google as google from structures.quote import QuoteSeries import numpy from math import log, exp from datetime import datetime # Definition of enumerators call, put, european, american = 100, 101, 102, 103 #google.getquotesfromweb('IVV').savetofile('data/ivv.csv') prices = QuoteSeries.loadfromfile('IVV', 'data/ivv_2012_11_05.csv').getprices() prices = prices[-250:] # We will use last 250 trading days # Calculation of daily continuous (logaritmic) returns returns = [] for i in range(0, len(prices)-1): r = log(prices[i] / prices[i-1]) returns.append(r) # Calculation of daily and annualized volatility from daily returns volat_d = numpy.std(returns) # Daily volatility volat = volat_d * 250**.5 # Annualized volatility # Calculation inputs side = call # Option side style = american # Option style price = prices[-1] # Current instrument price (147.31, as of 2012/11/05)