def assess_portfolio(sd = dt.datetime(2008,1,1), ed = dt.datetime(2009,1,1), \
syms = ['GOOG','AAPL','GLD','XOM'], \
allocs=[0.1,0.2,0.3,0.4], \
sv=1000000, rfr=0.0, sf=252.0, \
gen_plot=False):
# Read in adjusted closing prices for given symbols, date range
dates = pd.date_range(sd, ed)
prices_all = get_data(syms, dates) # automatically adds SPY
prices = prices_all[syms] # only portfolio symbols
prices_SPY = prices_all['SPY'] # only SPY, for comparison later
portVal = get_portfolio_value(prices, allocs, sv)
cr, adr, sddr, sr = get_portfolio_stats(portVal, rfr, sf)
# Compare daily portfolio value with SPY using a normalized plot
if gen_plot:
# add code to plot here
df_temp = pd.concat([portVal, prices_SPY], keys=['Portfolio', 'SPY'], axis=1)
plot_normalized_data(df_temp,'Daily portfolio value and SPY',\
'date', 'normalized price')
# ( df_temp / df_temp.values[0,:] ).plot()
# Add code here to properly compute end value
ev = portVal[-1]
return cr, adr, sddr, sr, ev
analysis.py 文件源码
python
阅读 26
收藏 0
点赞 0
评论 0
评论列表
文章目录