import pandas as pd
from pandas import DataFrame

df = pd.read_csv('sp500_ohlc.csv', index_col = 'Date', parse_dates=True)
df['H-L'] = df.High - df.Low

# Giving us count (rows), mean (avg), std (standard deviation for the entire
# set), minimum for the set, maximum for the set, and some %s in that range.
print( df.describe())

x = input('enter to cont')

# gives us correlation data. Remember the 3d chart we plotted?
# now you can see if correlation of H-L and Volume also is correlated
# with price swings. Correlations for your correlations
print( df.corr())
x = input('enter to cont')

# covariance... now plenty of people know what correlation is, but what in the
# heck is covariance.

# Let's defined the two.
# covariance is the measure of how two variables change together.
# correlation is the measure of how two variables move in relation to eachother.

# so covariance is  a more direct assessment of the relationship between two variables.
# Maybe a better way to put it is that covariance is the measure of the strength of correlation.

print( df.cov())
x = input('enter to cont')

print( df[['Volume','H-L']].corr())
x = input('enter to cont')

# see how it makes a table?
# so now, we can actually perform a service that some people actually pay for
# I once had a short freelance gig doing this

# so a popular form of analysis within especially forex is to compare correlations between
# the currencies. The idea here is that you pace one currency with another.
# 


import datetime
import pandas.io.data

C = pd.io.data.get_data_yahoo('C', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
AAPL = pd.io.data.get_data_yahoo('AAPL', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
MSFT = pd.io.data.get_data_yahoo('MSFT', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
TSLA = pd.io.data.get_data_yahoo('TSLA', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))


print( C.head())
x = input('enter to cont')

del C['Open']
# , 'high', 'low', 'close', 'volume'
del C['High']
del C['Low']
del C['Close']
del C['Volume']



corComp = C



corComp.rename(columns={'Adj Close': 'C'}, inplace=True)

corComp['AAPL'] = AAPL['Adj Close']
corComp['MSFT'] = MSFT['Adj Close']
corComp['TSLA'] = TSLA['Adj Close']

print( corComp.head())
x = input('enter to cont')

print( corComp.corr())
x = input('enter to cont')


C = pd.io.data.get_data_yahoo('C', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
AAPL = pd.io.data.get_data_yahoo('AAPL', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
MSFT = pd.io.data.get_data_yahoo('MSFT', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
TSLA = pd.io.data.get_data_yahoo('TSLA', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
BAC = pd.io.data.get_data_yahoo('BAC', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
BBRY = pd.io.data.get_data_yahoo('BBRY', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
CMG = pd.io.data.get_data_yahoo('CMG', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
EBAY = pd.io.data.get_data_yahoo('EBAY', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
JPM = pd.io.data.get_data_yahoo('JPM', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
SBUX = pd.io.data.get_data_yahoo('SBUX', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
TGT = pd.io.data.get_data_yahoo('TGT', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))
WFC = pd.io.data.get_data_yahoo('WFC', 
                                 start=datetime.datetime(2011, 10, 1), 
                                 end=datetime.datetime(2014, 1, 1))

x = input('enter to cont')
print( C.head())

del C['Open']
# , 'high', 'low', 'close', 'volume'
del C['High']
del C['Low']
del C['Close']
del C['Volume']



corComp = C



corComp.rename(columns={'Adj Close': 'C'}, inplace=True)

corComp['BAC'] = BAC['Adj Close']
corComp['MSFT'] = MSFT['Adj Close']
corComp['TSLA'] = TSLA['Adj Close']

corComp['AAPL'] = AAPL['Adj Close']
corComp['BBRY'] = BBRY['Adj Close']
corComp['CMG'] = CMG['Adj Close']
corComp['EBAY'] = EBAY['Adj Close']
corComp['JPM'] = JPM['Adj Close']
corComp['SBUX'] = SBUX['Adj Close']
corComp['TGT'] = TGT['Adj Close']
corComp['WFC'] = WFC['Adj Close']


print( corComp.head())
x = input('enter to cont')

print( corComp.corr())

x = input('enter to cont')

fancy = corComp.corr()
fancy.to_csv('bigmoney.csv')






[((4, 5, 4, 72), 'pandas.read_csv', 'pd.read_csv', (), '', True, 'import pandas as pd\n'), ((48, 39, 48, 69), 'datetime.datetime', 'datetime.datetime', ({(48, 57, 48, 61): '2011', (48, 63, 48, 65): '10', (48, 67, 48, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((49, 37, 49, 66), 'datetime.datetime', 'datetime.datetime', ({(49, 55, 49, 59): '2014', (49, 61, 49, 62): '1', (49, 64, 49, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((51, 39, 51, 69), 'datetime.datetime', 'datetime.datetime', ({(51, 57, 51, 61): '2011', (51, 63, 51, 65): '10', (51, 67, 51, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((52, 37, 52, 66), 'datetime.datetime', 'datetime.datetime', ({(52, 55, 52, 59): '2014', (52, 61, 52, 62): '1', (52, 64, 52, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((54, 39, 54, 69), 'datetime.datetime', 'datetime.datetime', ({(54, 57, 54, 61): '2011', (54, 63, 54, 65): '10', (54, 67, 54, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((55, 37, 55, 66), 'datetime.datetime', 'datetime.datetime', ({(55, 55, 55, 59): '2014', (55, 61, 55, 62): '1', (55, 64, 55, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((57, 39, 57, 69), 'datetime.datetime', 'datetime.datetime', ({(57, 57, 57, 61): '2011', (57, 63, 57, 65): '10', (57, 67, 57, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((58, 37, 58, 66), 'datetime.datetime', 'datetime.datetime', ({(58, 55, 58, 59): '2014', (58, 61, 58, 62): '1', (58, 64, 58, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((91, 39, 91, 69), 'datetime.datetime', 'datetime.datetime', ({(91, 57, 91, 61): '2011', (91, 63, 91, 65): '10', (91, 67, 91, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((92, 37, 92, 66), 'datetime.datetime', 'datetime.datetime', ({(92, 55, 92, 59): '2014', (92, 61, 92, 62): '1', (92, 64, 92, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((94, 39, 94, 69), 'datetime.datetime', 'datetime.datetime', ({(94, 57, 94, 61): '2011', (94, 63, 94, 65): '10', (94, 67, 94, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((95, 37, 95, 66), 'datetime.datetime', 'datetime.datetime', ({(95, 55, 95, 59): '2014', (95, 61, 95, 62): '1', (95, 64, 95, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((97, 39, 97, 69), 'datetime.datetime', 'datetime.datetime', ({(97, 57, 97, 61): '2011', (97, 63, 97, 65): '10', (97, 67, 97, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((98, 37, 98, 66), 'datetime.datetime', 'datetime.datetime', ({(98, 55, 98, 59): '2014', (98, 61, 98, 62): '1', (98, 64, 98, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((100, 39, 100, 69), 'datetime.datetime', 'datetime.datetime', ({(100, 57, 100, 61): '2011', (100, 63, 100, 65): '10', (100, 67, 100, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((101, 37, 101, 66), 'datetime.datetime', 'datetime.datetime', ({(101, 55, 101, 59): '2014', (101, 61, 101, 62): '1', (101, 64, 101, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((103, 39, 103, 69), 'datetime.datetime', 'datetime.datetime', ({(103, 57, 103, 61): '2011', (103, 63, 103, 65): '10', (103, 67, 103, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((104, 37, 104, 66), 'datetime.datetime', 'datetime.datetime', ({(104, 55, 104, 59): '2014', (104, 61, 104, 62): '1', (104, 64, 104, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((106, 39, 106, 69), 'datetime.datetime', 'datetime.datetime', ({(106, 57, 106, 61): '2011', (106, 63, 106, 65): '10', (106, 67, 106, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((107, 37, 107, 66), 'datetime.datetime', 'datetime.datetime', ({(107, 55, 107, 59): '2014', (107, 61, 107, 62): '1', (107, 64, 107, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((109, 39, 109, 69), 'datetime.datetime', 'datetime.datetime', ({(109, 57, 109, 61): '2011', (109, 63, 109, 65): '10', (109, 67, 109, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((110, 37, 110, 66), 'datetime.datetime', 'datetime.datetime', ({(110, 55, 110, 59): '2014', (110, 61, 110, 62): '1', (110, 64, 110, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((112, 39, 112, 69), 'datetime.datetime', 'datetime.datetime', ({(112, 57, 112, 61): '2011', (112, 63, 112, 65): '10', (112, 67, 112, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((113, 37, 113, 66), 'datetime.datetime', 'datetime.datetime', ({(113, 55, 113, 59): '2014', (113, 61, 113, 62): '1', (113, 64, 113, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((115, 39, 115, 69), 'datetime.datetime', 'datetime.datetime', ({(115, 57, 115, 61): '2011', (115, 63, 115, 65): '10', (115, 67, 115, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((116, 37, 116, 66), 'datetime.datetime', 'datetime.datetime', ({(116, 55, 116, 59): '2014', (116, 61, 116, 62): '1', (116, 64, 116, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((118, 39, 118, 69), 'datetime.datetime', 'datetime.datetime', ({(118, 57, 118, 61): '2011', (118, 63, 118, 65): '10', (118, 67, 118, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((119, 37, 119, 66), 'datetime.datetime', 'datetime.datetime', ({(119, 55, 119, 59): '2014', (119, 61, 119, 62): '1', (119, 64, 119, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((121, 39, 121, 69), 'datetime.datetime', 'datetime.datetime', ({(121, 57, 121, 61): '2011', (121, 63, 121, 65): '10', (121, 67, 121, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((122, 37, 122, 66), 'datetime.datetime', 'datetime.datetime', ({(122, 55, 122, 59): '2014', (122, 61, 122, 62): '1', (122, 64, 122, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n'), ((124, 39, 124, 69), 'datetime.datetime', 'datetime.datetime', ({(124, 57, 124, 61): '2011', (124, 63, 124, 65): '10', (124, 67, 124, 68): '1'}, {}), '(2011, 10, 1)', False, 'import datetime\n'), ((125, 37, 125, 66), 'datetime.datetime', 'datetime.datetime', ({(125, 55, 125, 59): '2014', (125, 61, 125, 62): '1', (125, 64, 125, 65): '1'}, {}), '(2014, 1, 1)', False, 'import datetime\n')]