- Authors
- Fede Rozenberg

This extension needs a unit test. For now, run it as indicated at the end of this assignment.

So it turns out that numbers can feel things. We define a happy or sad number through this process:

- Split up the number into its digits.
- Square the digits and sum them.
- Repeat with the new sum until you reach a set of numbers that repeat or the number 1.
- If your process results in a repeating 1, your initial number was happy! Otherwise, it has fallen into a cycle of depression, characterized by the repeating numbers
`[4, 16, 37, 58, 89, 145, 42, 20, 4...]`How sad.

For example, starting with the number 15, our process yields:

- 1
^{2}+ 5^{2}= 26- 2
^{2}+ 6^{2}= 40- 4
^{2}+ 0^{2}= 16- 1
^{2}+ 6^{2}= 37- 3
^{2}+ 7^{2}= 58

Here you can see our number has fallen into the beginning stages of depression...

In this extension you will be designing a program that uses `sets` to find the sad cycle of a number for an arbitrary power.

In the `sadcycle` package of your
`extensions` folder, create a `SadCycler` class.

- Create a method
`Set<Long> findCycle(int base, long n)`that takes in a number`n`and either returns a`Set<Long>`with the`base`-sad cycle for`n`or with 1 as its only element.A

`long`is simply twice as long as an`int`. I recommend using it here because some of the numbers found in higher`base`-sad cycles can be quite large. - Feel free to create any other methods you might need.
I highly recommend partitioning the splitting of digits, raising to the power of

`base`, and summing into one method. The trick here is figuring out how to treat every digit in a number as its own entity. - Test your program on inputs you find documented here. Show these results to a TA and convince him or her they are right for credit on this assignment.

When you done with this extension, you must be cleared by the TA to receive credit.

- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click
OKwhile the TA watches- If you request propagation, it does not happen immediately, but should be posted in the next day or so

This demo box is for extension 8.1

- Authors
- Devin Goodkin
- Ron K. Cytron

Issues:Working on it, stay tuned

The Sharpe ratio is a measure for calculating risk-adjusted return. It was developed by Nobel laureate William F. Sharpe.

Suppose you are considering investing a given amount of money in one of two possible ways:

- a
- This investment has risk. You may experience a positive return on
your investment, or you could lose your money. Let
*R*denote the return you will receive if your money is invested this way._{a} - b
- This investment has no risk. So let us say that you will certainly receive
*R*funds if your money is invested this way._{b}

The Sharpe ratio is calculated with this formula:

To calculate **average rate of return** of x, just add up all the provided **returns**
for each individual stock and divide by the **number of stocks**.

Assume that for this portfolio, the **risk free rate** or **Rf** is 2%.

The **portfolio standard deviation** can be calculated using this formula:

RKC Do exponentiation using^{this }Stddev= [ (wgt1 ^2 * s1 ^2) + (wgt2 ^2 * s2 ^ 2) + (2 * w1 * w2 * cov12) ] ^ .5

where

- wgt1 is the weight of asset 1
- wgt2 is the weight of asset 2
- s1 is the standard deviation of asset 1
- s2 is the standard deviation of asset 2
- cov12 is the covariant of assets 1 and 2

For the purposes of this extension, assume that all the stocks have **no correlation**
with each other and are **weighted equally**. This means that the covariance between
any two stocks is 0 and that the weight of each stock is simply 1/n where n is
the number of stocks.

Now that you understand what the Sharpe ratio is, it is time to apply what you have learned.

**Directions**

Click on the extensions folder and create a new class called **CalculateSharpeRatio**
in the **sharperatio** package.

Set up the **ArgsProcessor** to take input from **datafiles/stockaccount**. This is where
the data you will use to calculate the Sharpe ratio comes from.

- On the left, there will be a column of doubles.
This is the value of the
**expected return**for each stock. - On the right, there will be another column of doubles.
These are the
**variances**for each individual stock.

You will have to create a **List** of doubles for both the expected returns and the
variances in the main method.

After, write up a **loop** to read in the doubles for the expected returns and another
**loop** for the standard deviations. Once your program has read in these values,
you can start making your calculations for the Sharpe ratio.

Calculate the Sharpe ratio and **round** it to two decimal points then print it out.

- You should also print out whether the portfolio is
**profitable**or not. In general, a portfolio with a Sharpe ratio greater than**one**is considered profitable.

When you done with this extension, you must be cleared by the TA to receive credit.

- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click
OKwhile the TA watches- If you request propagation, it does not happen immediately, but should be posted in the next day or so

This demo box is for extension 8.2