I'm trying to create a program in Python, in which the user inputs a number of stock tickers and a desired date range; the output would be a graph of daily cumulative returns of the portfolio in that date range assuming the stocks have equal weights.
So far, this is my input block:
import datetime
import pandas
import numpy
import matplotlib.pyplot as plt
from matplotlib import pyplot
import csv
from pandas.io.data import DataReader
isValid = False
userInStart = raw_input("Enter Start Date mm/dd/yyyy: ") """start of date range"""
userInEnd = raw_input ("Enter End Date mm/dd/yyyy: ") """end of date range"""
StockCount = input ('Input the number of stocks in the porfolio: ')
StockArray = list() """an array of input stocks"""
Return = [[]] """an array of daily returns for each stock"""
CumulativeReturn = list() """an array of cumulative returns for each stock"""
The processing block is:
for i in range(0,StockCount):
for j in range(1,len(StockArray[i]["Adj Close"])):
Return[i].append (StockArray[i]["Adj Close"][j] - StockArray[i]["Adj Close"][j-1])
1) If I input 1 stock, by the end, I am left with an array of returns but no dates. How can I relate the Return array with the Dates
2) If I input more than one stock, I am given an index out of range error. What may be causing the problem?
Any help on conceptualizing a solution would also be highly appreciated.
Thanks