# -*- coding: utf-8 -*-
"""
Created on Wed Aug 30 19:07:37 2017

@author: AmatVictoriaCuramIII
"""
import numpy as np
import random as rand
import pandas as pd
import time as t
#from DatabaseGrabber import DatabaseGrabber
from YahooGrabber import YahooGrabber
from ListPairs import ListPairs
Empty = []
Start = t.time()
Counter = 0
Counter2 = 0
iterations = range(0, 10000)
Dataset2 = pd.DataFrame()
#Input
tickers = ('TLT', 'SPY', 'TMF', 'AAPL', 'PBF', 'UVXY', '^VIX', 'GLD', 'SLV',
           'JO','CORN', 'DBC', 'SOYB')

#Make all pairs in final list
MajorList = ListPairs(tickers)

#Here we go

#Brute Force Optimization
for m in MajorList:
    Dataset = pd.DataFrame()
    Ticker1 = m[0]
    Ticker2 = m[1]
    TAG = m[0] + '/' + m[1]
    Dataset = pd.DataFrame()
    Portfolio = pd.DataFrame()
#pull online data, change to local for testing
    Asset1 = YahooGrabber(Ticker1)
    Asset2 = YahooGrabber(Ticker2)    
#get log returns
    Asset1['LogRet'] = np.log(Asset1['Adj Close']/Asset1['Adj Close'].shift(1))
    Asset1['LogRet'] = Asset1['LogRet'].fillna(0)
    Asset2['LogRet'] = np.log(Asset2['Adj Close']/Asset2['Adj Close'].shift(1))
    Asset2['LogRet'] = Asset2['LogRet'].fillna(0)
#Match lengths
    trim = abs(len(Asset1) - len(Asset2))
    if len(Asset1) == len(Asset2):
        pass
    else:
        if len(Asset1) > len(Asset2):
            Asset1 = Asset1[trim:]
        else:
            Asset2 = Asset2[trim:]
#
    for i in iterations:
        Counter = Counter + 1
        aa = rand.random() * 2 #uniformly distributed random number 0 to 2
        a = aa - 1          #a > 1 indicating long position in a
        bb = rand.random()
        if bb >= .5:
            bb = 1
        else:
            bb = -1