久久综合精品国产丝袜长腿|男男大尺度GVGAY|少妇AV一区二区三区无码|好男人在线社区www资源|国产GaysexChina体育生男男|欧美gaygv束缚|海角国产乱辈乱精品视频|YYYY111111少妇影院

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

錢(qián)如故

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

本周三上課講到了投資組合收益率的計(jì)算,課本上的例題把收益率計(jì)算涉及到的數(shù)據(jù)都給全了,同學(xué)們做了一個(gè)帶概率的加權(quán)平均收益率計(jì)算。從課堂反應(yīng)來(lái)看,似乎同學(xué)們都能明白例題的計(jì)算過(guò)程;從課堂提問(wèn)情況來(lái)看,似乎同學(xué)們又沒(méi)明白計(jì)算過(guò)程背后的數(shù)據(jù)信息。我在課后便針對(duì)收益率問(wèn)題,做了一個(gè)梳理,查閱了好幾個(gè)教材,發(fā)現(xiàn)該主題的例題幾乎如出一轍,不同的僅為參數(shù)的調(diào)整。

為了換個(gè)思路來(lái)學(xué)習(xí)這個(gè)知識(shí)點(diǎn),算是自我再學(xué)習(xí),也是算我給學(xué)生們的答疑解惑。因剛好處在一周的因疫情居家隔離期間,消磨時(shí)間,我設(shè)計(jì)了一個(gè)案例:從中國(guó)股市中任意選取4支股票(實(shí)際上,我編寫(xiě)的python程序可以處理N多支股票的組合),用1年的日交易收盤(pán)價(jià)(可以是N年的數(shù)據(jù))來(lái)計(jì)算確定股票投資組合的收益率及風(fēng)險(xiǎn)。

介紹該案例的目的是讓我的學(xué)生們懂得實(shí)務(wù)中的收益率是怎么計(jì)算出來(lái)的,風(fēng)險(xiǎn)是怎么度量的,數(shù)據(jù)是如何取得的,數(shù)據(jù)是如何處理的……,最終,這么大、這么復(fù)雜的數(shù)據(jù)是怎么通過(guò)python程序計(jì)算的……

本文先介紹收益率,下一篇文章將介紹風(fēng)險(xiǎn)。

時(shí)間無(wú)限,生命有限,強(qiáng)烈建議您趕緊使用計(jì)算機(jī)程序來(lái)幫您進(jìn)行財(cái)務(wù)計(jì)算和推演,手算真的不足以支撐您的欲壑!

正文起:

對(duì)普通投資者來(lái)說(shuō),資產(chǎn)收益率體現(xiàn)了該資產(chǎn)的投資機(jī)會(huì),并且與其投資規(guī)模無(wú)關(guān);資產(chǎn)收益率序列比價(jià)格序列有更好的統(tǒng)計(jì)性質(zhì)。為認(rèn)知清楚收益率的本質(zhì),有必要先搞清下面幾個(gè)概念。

一、單項(xiàng)資產(chǎn)收益率

1、單期簡(jiǎn)單收益率

如果從第t-1 天到第t天(一個(gè)周期)持有某項(xiàng)資產(chǎn),則該項(xiàng)資產(chǎn)的簡(jiǎn)單收益率為:

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

則:

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

2、多期簡(jiǎn)單收益率

如果從第t-k天到第t天,在這k天持有某項(xiàng)資產(chǎn)(k個(gè)周期),則該項(xiàng)資產(chǎn)的k期簡(jiǎn)單收益率為:

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

則:

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

又:

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

即:

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

故:

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

即:?jiǎn)雾?xiàng)資產(chǎn)持有k期的簡(jiǎn)單收益率等于它所包含的k個(gè)簡(jiǎn)單收益率的乘積減去1。

3、持有K期的年化收益率為:

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

二、投資組合收益率

投資組合收益率是投資組合中各單項(xiàng)資產(chǎn)收益率的加權(quán)平均數(shù)。權(quán)重為投資金額的占比。

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

所以:

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

即:

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

三、計(jì)算程序

# -*- coding: utf-8 -*-"""Created on Thu Sep 29 17:08:53 2022@author: zgrweixin ID: """import warningsimport pandas as pdimport numpy as npimport tushare as tsimport matplotlib.pyplot as pltpro=ts.pro_api()# 股票投資組合:盛和資源,北方稀土,廣晟有色,五礦稀土 tickers='600392.SH, 600111.SH, 600259.SH, 000831.SZ' # 投資權(quán)重 weight=pd.DataFrame([{'000831.SZ':0.3,'600111.SH':0.3,'600259.SH':0.15,'600392.SH':0.25}]) # 1年的交易數(shù)據(jù) data=pro.daily(ts_code=tickers , start_date='20200101', end_date='20201231')# 查看是否有空值:沒(méi)有空值data.info()# 對(duì)收盤(pán)價(jià)進(jìn)行透視close_pivot=data.pivot_table(values="close",index='trade_date',columns='ts_code')close_pivot.info()# 對(duì)返回值進(jìn)行檢查def _check_returns(returns):# Check NaNs excluding leading NaNsif np.any(np.isnan(returns.mask(returns.ffill().isnull(), 0))): warnings.warn("Some returns are NaN. Please check your price data.", UserWarning )if np.any(np.isinf(returns)): warnings.warn("Some returns are infinite. Please check your price data.", UserWarning )# 根據(jù)價(jià)格計(jì)算日收率def returns_from_prices(prices, log_returns=False):""" Calculate the returns given prices. :param prices: adjusted (daily) closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.DataFrame :param log_returns: whether to compute using log returns :type log_returns: bool, defaults to False :return: (daily) returns :rtype: pd.DataFrame """if log_returns: returns=np.log(1 + prices.pct_change()).dropna(how="all")else: returns=prices.pct_change().dropna(how="all")return returns# 根據(jù)價(jià)格計(jì)算各單項(xiàng)資產(chǎn)年收益率def mean_historical_return( prices, returns_data=False, compounding=True, frequency=252, log_returns=False):""" Calculate annualised mean (daily) historical return from input (daily) asset prices. Use ``compounding`` to toggle between the default geometric mean (CAGR) and the arithmetic mean. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.DataFrame :param returns_data: if true, the first argument is returns instead of prices. These **should not** be log returns. :type returns_data: bool, defaults to False. :param compounding: computes geometric mean returns if True, arithmetic otherwise, optional. :type compounding: bool, defaults to True :param frequency: number of time periods in a year, defaults to 252 (the number of trading days in a year) :type frequency: int, optional :param log_returns: whether to compute using log returns :type log_returns: bool, defaults to False :return: annualised mean (daily) return for each asset :rtype: pd.Series """if not isinstance(prices, pd.DataFrame): warnings.warn("prices are not in a dataframe", RuntimeWarning) prices=pd.DataFrame(prices)if returns_data: returns=priceselse: returns=returns_from_prices(prices, log_returns) _check_returns(returns)if compounding:return (1 + returns).prod() ** (frequency / returns.count()) - 1else:return returns.mean() * frequency# 返回單項(xiàng)資產(chǎn)日收益率(根據(jù)收盤(pán)價(jià)計(jì)算)returns_assets_daily=returns_from_prices(close_pivot, log_returns=False)# 日收益率曲線(日收益可視化)returns_assets_daily.plot(subplots=True,figsize=(8,6))# 日收益率直方圖returns_assets_daily.hist(bins=20)# 日收益率極差、四分位差、方差、標(biāo)準(zhǔn)差和離散系數(shù)ret_des=returns_assets_daily.describe().Tret_des['var_coef']=ret_des['std']/ret_des['mean']ret_des=ret_des.T# 計(jì)算投資組合的收益率def _objective_value(w, obj):""" Helper method to return either the value of the objective function or the objective function as a cvxpy object depending on whether w is a cvxpy variable or np array. :param w: weights :type w: np.ndarray OR cp.Variable :param obj: objective function expression :type obj: cp.Expression :return: value of the objective function OR objective function expression :rtype: float OR cp.Expression """if isinstance(w, np.ndarray):if np.isscalar(obj):return objelif np.isscalar(obj.value):return obj.valueelse:return obj.value.item()else:return objdef portfolio_return(w, expected_returns, negative=True):""" Calculate the (negative) mean return of a portfolio :param w: asset weights in the portfolio :type w: np.ndarray OR cp.Variable :param expected_returns: expected return of each asset :type expected_returns: np.ndarray :param negative: whether quantity should be made negative (so we can minimise) :type negative: boolean :return: negative mean return :rtype: float """ sign=1 if negative else -1 mu=w @ expected_returnsreturn _objective_value(w, sign * mu)# 返回單項(xiàng)資產(chǎn)年收益率(根據(jù)收盤(pán)價(jià)計(jì)算)returns_assets=mean_historical_return(close_pivot)# 投資組合的年收益率returns_portfolio=portfolio_return(weight,returns_assets)returns_assets['portfolio']=float(np.around(returns_portfolio.values, 6))# 收益率可視化returns_assets.plot(kind='bar',rot=45)plt.title('returns of assets and portfolio')plt.xlabel('tscode')plt.ylabel('annual returns')

結(jié)果:

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

收益率的計(jì)算例題,收益率的計(jì)算例題及答案?

【僅供參考】

授人玫瑰,手留余香。請(qǐng)關(guān)注本公眾號(hào)!歡迎轉(zhuǎn)發(fā)!鼓勵(lì)分享!

好了,這篇文章就和大家分享到這里,希望可以幫助到大家。另外,想要實(shí)現(xiàn)投資穩(wěn)定盈利,建議大家可以多學(xué)習(xí)一些相關(guān)的課程內(nèi)容,這里給大家推薦一個(gè)知識(shí)平臺(tái)——愛(ài)雅微課:https://ke.iya88.com/,里面提供了全網(wǎng)最全最實(shí)戰(zhàn)的課程,很多大佬都是該網(wǎng)站的會(huì)員,抓緊收藏起來(lái)吧!

本文內(nèi)容由互聯(lián)網(wǎng)用戶(hù)自發(fā)貢獻(xiàn),該文觀點(diǎn)僅代表作者本人。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如發(fā)現(xiàn)本站有涉嫌抄襲侵權(quán)/違法違規(guī)的內(nèi)容,請(qǐng)發(fā)送郵件至 [email protected] 進(jìn)行舉報(bào),一經(jīng)查實(shí),本站將立刻刪除。如若轉(zhuǎn)載,請(qǐng)注明出處:http://www.weightcontrolpatches.com/70702.html