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')






[((55, 120), 'pandas.read_csv', 'pd.read_csv', (['"""sp500_ohlc.csv"""'], {'index_col': '"""Date"""', 'parse_dates': '(True)'}), "('sp500_ohlc.csv', index_col='Date', parse_dates=True)\n", (66, 120), True, 'import pandas as pd\n'), ((1602, 1632), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (1619, 1632), False, 'import datetime\n'), ((1672, 1701), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (1689, 1701), False, 'import datetime\n'), ((1784, 1814), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (1801, 1814), False, 'import datetime\n'), ((1854, 1883), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (1871, 1883), False, 'import datetime\n'), ((1966, 1996), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (1983, 1996), False, 'import datetime\n'), ((2036, 2065), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (2053, 2065), False, 'import datetime\n'), ((2148, 2178), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (2165, 2178), False, 'import datetime\n'), ((2218, 2247), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (2235, 2247), False, 'import datetime\n'), ((2768, 2798), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (2785, 2798), False, 'import datetime\n'), ((2838, 2867), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (2855, 2867), False, 'import datetime\n'), ((2950, 2980), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (2967, 2980), False, 'import datetime\n'), ((3020, 3049), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (3037, 3049), False, 'import datetime\n'), ((3132, 3162), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (3149, 3162), False, 'import datetime\n'), ((3202, 3231), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (3219, 3231), False, 'import datetime\n'), ((3314, 3344), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (3331, 3344), False, 'import datetime\n'), ((3384, 3413), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (3401, 3413), False, 'import datetime\n'), ((3494, 3524), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (3511, 3524), False, 'import datetime\n'), ((3564, 3593), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (3581, 3593), False, 'import datetime\n'), ((3676, 3706), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (3693, 3706), False, 'import datetime\n'), ((3746, 3775), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (3763, 3775), False, 'import datetime\n'), ((3856, 3886), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (3873, 3886), False, 'import datetime\n'), ((3926, 3955), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (3943, 3955), False, 'import datetime\n'), ((4038, 4068), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (4055, 4068), False, 'import datetime\n'), ((4108, 4137), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (4125, 4137), False, 'import datetime\n'), ((4218, 4248), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (4235, 4248), False, 'import datetime\n'), ((4288, 4317), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (4305, 4317), False, 'import datetime\n'), ((4400, 4430), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (4417, 4430), False, 'import datetime\n'), ((4470, 4499), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (4487, 4499), False, 'import datetime\n'), ((4580, 4610), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (4597, 4610), False, 'import datetime\n'), ((4650, 4679), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (4667, 4679), False, 'import datetime\n'), ((4760, 4790), 'datetime.datetime', 'datetime.datetime', (['(2011)', '(10)', '(1)'], {}), '(2011, 10, 1)\n', (4777, 4790), False, 'import datetime\n'), ((4830, 4859), 'datetime.datetime', 'datetime.datetime', (['(2014)', '(1)', '(1)'], {}), '(2014, 1, 1)\n', (4847, 4859), False, 'import datetime\n')]