# Portfolio Algorithm

### Here is the code I used in class: Portfolio1.java

This is a brain dead algorithm that is quite unstable (might gives extremely low return once in a while) but should give the highest overall return in the long run theoretically.

My idea was really simple. The only unknown in the problem is the favorable and unfavorable attributes, so I just try to repeat the processes done by the simulator to get the expected return for each gamble. Then, put a higher share on the gamble with a higher expected return.

The program is divided into 6 parts originally: getMostLikelyAttr(); changeProbFromAttr(); changeProbFromLinks(); getExpectedReturns(); getBiasFromOutcome(); (not implemented), getGambleAmount();

getMostLikelyAttr:
the expected high, medium and low return probabilities are calculated using the probabilities modified from the original with the links information. Then the actual probabilites are calculated from the outcome of each round. For each attribute, we get the totAttrDiff=(expected high-actual high)-(expected low-actual low). Those totAttrDiff for each round are added up, so the smallest two should be the favorable attributes and the largest two should be the unfavorables ones.

changeProbFromAttr:
Just change the probabilities according to the attributes. This would sometimes give horrible result after the first few rounds.

After the attributes have been accounted for, the probabilities are changed according to the links. Since there are at most 4 gambles a link, you can either hard code all permutations or generate them using recursive methods at the beginning of the program. This part goes through all permutations and changes the probabilities accordingly. Then, average all the results and put them back into the probabilities array.

getExpectedReturns:
get the expected return from each gamble.

getGambleAmount:
gamble more on those that have a higher expected return

### WARNING: This is a high risk, high return program. If you are really unlucky, you can actually decrease in wealth once in a while. This program captures the gambles with a large low return probability, a small high return probability, thus a really high return percentage. If those gambles happen to have favorable attributes, it will put almost everything in those gambles. If there is just one such gamble in the data, this algorithm is extremely unstable, but theoretically, it should still give you the highest overall return. In the competition, I suspected that there are four such gambles that each have a high return of about 10. If I get a high return on all four, I get a wealth of 10. High return on 3 of them, I get a return of around 8. Two high returns, around 6. One high return, around 3.

Usage: java Portfolio hostname portNumber playerName filename maximumRound

Karven Lam