1
我試圖在Python中創建一個程序,其中用戶輸入一些股票代碼和期望的日期範圍;假設股票具有相同的權重,則該輸出將是該日期範圍內投資組合的每日累計回報圖。在熊貓中關聯數組和嵌套循環(股票組合分析)
到目前爲止,這是我的輸入模塊:
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"""
處理塊是:
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)如果我輸入1股,截至去年底,我留下一個數組的回報,但沒有日期。我如何將返回數組與日期聯繫起來
2)如果我輸入了多個股票,我會得到一個超出範圍錯誤的指數。什麼可能導致這個問題?
概念化解決方案的任何幫助也將受到高度讚賞。
感謝