首页 > > 详细

辅导 Investment Modeling Summer 2019, Practice Set # 5讲解 Python编程

Investment Modeling Summer 2019, Practice Set # 5

1. What is x?

 

oi = c (100 ,200 ,300 ,400 ,500)

ppe = c (1000 ,2000 ,3000 ,4000 ,5000) ad = c ( -100 , -150 , -200 , -250 , -300)   tca = c (200 ,300 ,400 ,500 ,600)

tcl = c (100 ,120 ,140 ,160 ,180)

dt = data . table ( oi , ppe , ad , tca , tcl ) x = dt [ tca >200   &  tca <600 , tca ]

2. What is y?

 

oi = c (100 ,200 ,300 ,400 ,500)

ppe = c (1000 ,2000 ,3000 ,4000 ,5000) ad = c ( -100 , -150 , -200 , -250 , -300)   tca = c (200 ,300 ,400 ,500 ,600)

tcl = c (100 ,120 ,140 ,160 ,180)

dt = data . table ( oi , ppe , ad , tca , tcl )   x = dt [ tca >200   &  tca <600 , . ( oi , ppe ) ] x [ , a := ppe / oi ]

y = x [ , sum ( a ) ]

3. Given the table below, add a column ROC, that will be the return on capital ratio?

 

oi = c (100 ,200 ,300 ,400 ,500)

ppe = c (1000 ,2000 ,3000 ,4000 ,5000) ad = c ( -100 , -150 , -200 , -250 , -300)   tca = c (200 ,300 ,400 ,500 ,600)

tcl = c (100 ,120 ,140 ,160 ,180)

dt = data . table ( oi , ppe , ad , tca , tcl ) 

4. Using sampdt, find the most recent prices per quarter, and put the values in the vector x.

 

dt = c ( as . Date ( ' 2018 -01 -01 ' ) , as . Date ( ' 2018 -03 -03 ' ) , as . Date ( ' 2018 -05 -01 ' ) , as .

Date ( ' 2018 -05 -31 ' ) )

price = c (4 ,8 ,10 ,12)

sampdt   =   data . table ( dt , price )

5. Using the table below, calculate the ROC for 201712.

6. Using the table below, calculate the current ratio for all the dates, and put them in the newly created column CR. The current ratio formula is :

currentratio = TCL/TCA

7. An asset appreciated %100 in 4 years, what is the annual compound return?

8. An asset was $100 in the beginning of year 1, it was $110 and the end of the year 1, it was $120 at the end of year 2, and $200 at the end of year 3.  What was for the annual compound return for those 3 years.

9. Change the code below, so that you backtest the investment strategy where:

1) You are choosing 10 stocks per year

2) You are choosing the stocks with the 5 highest positive EYs THAT are less than .3, and you are choosing the 5 smallest negative EYs greater than -.3.

3) Assume table df2 has the columns, (Date, ticker, ey, Price) Only write down the changes, dont re-write all of the code.

1 library ( data . table )

2

3 df3 = df2 [ order ( Date , - ey ) ]

4 df4 = df3 [is. finite ( ey ) & ey >0 , tail ( ticker ,15) ,by= Date ]

5

6 for ( i in df4 $V1 )

7 {

8 tryCatch (

9 {

10 v = getQuote ( i )$ Last

11 df4 [ V1 == i , pricesell := v ]

12 } ,

13 error = function ( e )

14 {

15 })

16 }

17

18 df3 [ df4 , sellprice := pricesell , n = c( ticker ="V1") ]

19 df3 [ , return :=( sellprice / Price - 1) ]

20

21 strat = df3 [is. finite ( return ) & is. finite ( ey ) & ey >0 , head (return ,1) ,by= Date ]

22 f_ amount =sum (11000 *(1+ strat $V1 ) )

23

24 fcr = function ( x )

25 {

26 v =11000 *(1+ x ) ^3+11000 *(1+ x ) ^2+11000 *(1+ x ) ^1 - f_ amount

27 return ( v )

28 }

29

30 res = uniroot ( fcr , lower = -.8 , upper =.8)

31 res $ root

10. There are 5 number, with the arithmetic mean of 5 and a geometric mean of 3, what does this imply about the 5 numbers?

11. There are 5 number, with the arithmetic mean of 10 and a geometric mean of 10, what does this imply about the 5 numbers?

12. Given the numbers 1,2,3,4,5 what is the geometric mean?

13. Given the numbers .2,.4,.6,.8,.9 what is the geometric mean?

14. You have a table dt, that has 5 columns:

ticker, price, date, ey, roc

Create a bar graph of the count of each unique ticker.

15. You have a table dt, that has 5 columns:

ticker, price, date, ey, roc

Create a histogram of the roc numbers, only 10 bars.

16. What is a?

x =1:10

dt = data . table ( x )

dt [ , y := cut (x , c (0 ,3 ,6 ,10) , labels  =  F ) ] a = dt [ , sum ( unique ( y ) ) ]

 


联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!