 #### 联系方式

• QQ：99515681
• 邮箱：99515681@qq.com
• 工作时间：8:00-23:00
• 微信：codehelp #### 您当前位置：首页 >> Algorithm 算法作业Algorithm 算法作业

###### 日期：2019-11-07 09:39

Nov. 11th, 2019

Question 1 (50 Points)

In this exam, we want to replicate the S&P 500 Index based on two different data sets using linear regression

model. The final goal is comparing the performance between two models and figure out which model gives

you the best simulation.

For your convenience, I already pick some of the equities and put them into two different groups, they

are:

? Group 1: XLE, XLF, XLK, XLV, XLB

? Group 2: GOOG, MSFT, BAC, JPM, XOM, CVX, JNJ, PFE, AAPL, NKE

1. Download 2 year length of data as training data sets. Another half year as testing data sets. In the

end, you need to calculate daily return (either type) for all data you downloaded.

2. For Model 1, you are required to use all equities in Group 1. Group 2 has 10 tickers in total. Therefore,

you may want to simplify your model. The method to simply your model is based on your preference.

In the end, name this model as Model 2.

3. Which model has better performance based on the training data set? Explain your result.

4. Now let’s compare the model performance based on testing data set. Generate a single line chart which

shows three lines in total (result from Model 1, result from model 2, S&P 500 performance). Your

X-axis should be a time line. You need to include X-label, Y-label, title, legend and etc.

5. Based on the result from Step 4, which model has better performance? Which model is more risky

when using?

Question 2 (30 Points)

In this question, you are required to create a self-defined function. The final output should be a report which

details all qualified prime numbers you have found. Please keep in mind:

? You can ONLY use system library (default library when installing the R) to solve this

question

? You can not use any existed functions/library during calculation, including system library.

For your convenience, I will highlight calculation part with blue letters.

Here is the detailed requirement for this function:

1. The input of this function has to be a numeric vector. Other than this format, you need to stop this

function and return me an error message.

2. For each number inside this vector (let’s call it target number), find out all prime numbers which can

divide the target number without reminders.

1

3. Based on the prime numbers you find, further decompose the target number into the product of a

sequence of prime numbers. Summarize your result into two parts: prime number and the corresponding

power.

4. You need to return a table which record all result.

Example:

> f i n d . prime ( c ( 8 , 9 , 3 6 , 3 7 ) )

Target number Prime number C o r re sp ondin g power

[ 1 , ] 8 2 3

[ 2 , ] 9 3 2

[ 3 , ] 36 2 2

[ 4 , ] 36 3 2

[ 5 , ] 37 37 1>

Question 3: (20 Points)

In this question, you are required to create a self-defined function. The final goal is identifying whether two

input triangles are identical (Under two dimensions). Detailed information are the following:

? For this function, your input should be the coordinate for two triangles

? For this function, your output should be a True or False judgment (minimum requirement)

? We define the identical triangles as the following: If the two input triangle match each

other perfectly after translation and rotation, they are identical triangles

? You can ONLY use system library (default library when installing the R) to solve this

question

? You need to finish Question 1 at least before solving this Bonus.

1. Return the correct judgement.

2. Besides the final statement (True or False), you also need to plot these two triangles.

3. Fill two triangles with different colors.

2