Investment_2022_fall_Assignment1

这是2022年秋季学期投资学课程的作业备忘录。由于版权原因,我将不分享原题目与数据集。但我会分享一个Summary以便解释代码的业务逻辑。

Summary

  1. Compute mean, standard deviation, skewness, kurtosis,minimum and maximum of the 3 stocks’ return data
  2. Define excess returns with respect of market returns.$$Z_{it} = R_{it} – R_{mt}$$ Calaculate for the stock “Interlake”. R_{it} for return of stock and R_{mt} for return of a market porfolio
  3. Compute univariate statistics for the excess returns as in 1).

Data Description

SAS dataset “a1_data_stocks” : return data for each of
the following 3 stocks, with an id as “PERMNO”. containing

SAS dataset “a1_data_indices” : value-weighted index as return of market

Code

cd D:\Janis\Downloads\资产定价(投资学)\data
import pandas as pd
d_stk = pd.read_sas('a1_data_stocks.sas7bdat')
gensig = d_stk[d_stk['PERMNO'] == 12095]
gensig.name = "gensig"
wgl = d_stk[d_stk['PERMNO'] == 15472]
wgl.name = "wgl"
itlake = d_stk[d_stk['PERMNO'] == 15747]
itlake.name = "itlake"
def print_univariate_statistics( df ):
    print(df.name + ".mean=",df['RET'].mean())
    print(df.name + ".std=",df['RET'].std())
    print(df.name + ".skew=",df['RET'].skew())
    print(df.name + ".kurt=",df['RET'].kurt())
    print(df.name + ".min=",df['RET'].min())
    print(df.name + ".max=",df['RET'].max())
print_univariate_statistics(gensig)
print_univariate_statistics(wgl)
print_univariate_statistics(itlake)
gensig.mean= 0.0005384913962517579
gensig.std= 0.01660579870155393
gensig.skew= 0.006147095147682125
gensig.kurt= 3.348573263907502
gensig.min= -0.1346153914928436
gensig.max= 0.09428571164608
wgl.mean= 0.000718630604623612
wgl.std= 0.014457717199920582
wgl.skew= -0.0032873108237338007
wgl.kurt= 11.027898966633048
wgl.min= -0.1867283880710602
wgl.max= 0.1188524588942528
itlake.mean= 0.0004311164104247514
itlake.std= 0.021558440123948357
itlake.skew= 0.7212010671576428
itlake.kurt= 12.352192867014283
itlake.min= -0.1724137961864471
itlake.max= 0.2307692319154739

Part 2

d_ind = pd.read_sas('a1_data_indices.sas7bdat')
d_merge = pd.merge(pd.DataFrame(itlake, columns=['RET','DATE']),pd.DataFrame(d_ind, columns=['vwretd','caldt']),left_on = "DATE",right_on = "caldt")
d_merge.drop(['caldt'], axis = 1, inplace=True)
d_merge.columns = ["itlake_ret", "date", "vw_ret"]
d_merge['itlake_excess_ret'] = d_merge['itlake_ret'] - d_merge['vw_ret']
print(d_merge.head(5))
   itlake_ret       date    vw_ret  itlake_excess_ret
0   -0.010256 1962-07-03  0.011296          -0.021552
1    0.000000 1962-07-05  0.006013          -0.006013
2    0.010363 1962-07-06 -0.010709           0.021072
3    0.000000 1962-07-09  0.006770          -0.006770
4    0.005128 1962-07-10  0.012571          -0.007443
print("itlake_excess_ret.mean=",d_merge['itlake_excess_ret'].mean())
print("itlake_excess_ret.std=",d_merge['itlake_excess_ret'].std())
print("itlake_excess_ret.skew=",d_merge['itlake_excess_ret'].skew())
print("itlake_excess_ret.kurt=",d_merge['itlake_excess_ret'].kurt())
print("itlake_excess_ret.min=",d_merge['itlake_excess_ret'].min())
print("itlake_excess_ret.max=",d_merge['itlake_excess_ret'].max())
itlake_excess_ret.mean= -6.609454975419493e-06
itlake_excess_ret.std= 0.0208214439514175
itlake_excess_ret.skew= 0.7352145454802111
itlake_excess_ret.kurt= 12.60220862045459
itlake_excess_ret.min= -0.1733796618864471
itlake_excess_ret.max= 0.2239592829154739

点击数:0

发布者:Janis

,,,

留下评论

您的电子邮箱地址不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据