from datetime import datetime

from bokeh.plotting import figure, output_file, show

from myToolbox import downloadStock, firstDayOfData, plotTimeSeriesDF, getYearlyReturn, solveMarkowitzWithShorting, getStats, calculateWeightedPortfolio, getWeeklyReturn, getWeeklyLogReturn

# Pick your stocks
stockNameVec = ['BND', 'O', 'SPLV']   # This one is good at 10%!

# Pick the year to start your analysis (probably corresponds to earliest data)
y1 = 2008 # Make this zero to turn off the lower bound

subDict = dict()
for curName in stockNameVec:
	# Download the data
	stock = downloadStock(curName, y1,1,1,2010,0,0)
	# Strip out everything except for the Adjusted Close Price and put it in a dictionary as a Series
	subDict[curName] = pd.Series(stock['Adj Close'].as_matrix(), index=stock.Date)
tickerDF = pd.DataFrame(subDict) # Then make a new data frame with just the adjusted closes.


firstDayOfData(tickerDF)

filename = "ticker.html"
plotTitle = "Stocks to Plot"
plotTimeSeriesDF(filename, plotTitle, tickerDF)

# Translate the daily prices into yearly rates of return
subDict = dict()
for curName in tickerDF:
	yearRecord, rate = getYearlyReturn(tickerDF[curName], 2000, 2016)