-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/file-io-development' into dev
- Loading branch information
Showing
4 changed files
with
92 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/millions/model/calculators/PriceChangeCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package millions.model.calculators; | ||
|
|
||
| import millions.model.Stock; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.List; | ||
|
|
||
| public class PriceChangeCalculator { | ||
|
|
||
| public PriceChangeCalculator() {} | ||
|
|
||
| public BigDecimal calculateChange(Stock stock) { | ||
| BigDecimal change = BigDecimal.ZERO; | ||
| List<BigDecimal> volatilityParameters = stock.getVolatilityParameters(); | ||
| change = change.add(upChange(volatilityParameters.get(0))); | ||
| change = change.add(downChange(volatilityParameters.get(1))); | ||
| change = change.add(randomChange(volatilityParameters.get(2))); | ||
| change = change.add(sinChange(volatilityParameters.get(3))); | ||
| change = change.add(cosChange(volatilityParameters.get(4))); | ||
| return change; | ||
| } | ||
|
|
||
| private BigDecimal upChange(BigDecimal input) { | ||
| if (input.equals(BigDecimal.ZERO)) { | ||
| return BigDecimal.ZERO; | ||
| } | ||
| return input; | ||
|
|
||
| } | ||
| private BigDecimal downChange(BigDecimal input) { | ||
| if (input.equals(BigDecimal.ZERO)) { | ||
| return BigDecimal.ZERO; | ||
| } | ||
| return input.negate(); | ||
| } | ||
|
|
||
| private BigDecimal randomChange(BigDecimal input) { | ||
| if (input.equals(BigDecimal.ZERO)) { | ||
| return BigDecimal.ZERO; | ||
| } | ||
| return new BigDecimal(Math.random()*10).multiply(input); | ||
| } | ||
|
|
||
| private BigDecimal sinChange(BigDecimal input) { | ||
| if (input.equals(BigDecimal.ZERO)) { | ||
| return BigDecimal.ZERO; | ||
| } | ||
| return new BigDecimal(Math.sin(input.doubleValue())); | ||
| } | ||
| private BigDecimal cosChange(BigDecimal input) { | ||
| if (input.equals(BigDecimal.ZERO)) { | ||
| return BigDecimal.ZERO; | ||
| } | ||
| return new BigDecimal(Math.cos(input.doubleValue())); | ||
| } | ||
| } |