-
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 pull request #3 from agilitytestbed/features/balancehistory
Features/balancehistory
- Loading branch information
Showing
8 changed files
with
403 additions
and
21 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
82 changes: 82 additions & 0 deletions
82
src/main/java/nl/utwente/ing/misc/date/IntervalHelper.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,82 @@ | ||
package nl.utwente.ing.misc.date; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
/** | ||
* The IntervalHelper class. | ||
* Used to generate intervals and compare dates. | ||
* | ||
* @author Daan Kooij | ||
*/ | ||
public class IntervalHelper { | ||
|
||
/** | ||
* Method used to generate a certain number of intervals with certain size. | ||
* The generation of intervals is done by taking the current datetime and and putting the resulting edges of the | ||
* intervals in an array in the form of LocalDateTime objects. | ||
* <p> | ||
* Example: suppose the current date is 13 May 2018 and you want to generate five intervals with sizes of one day | ||
* each. Then you specify intervalPeriod to be IntervalPeriod.DAY and amount to be 5. The returned array will then | ||
* be: [8 May 2018, 9 May 2018, 10 May 2018, 11 May 2018, 12 May 2018, 13 May 2018]. | ||
* <p> | ||
* Note that the size of the array is equal to the amount of intervals plus one. | ||
* | ||
* @param intervalPeriod The size of the intervals to be generated. | ||
* @param amount The amount of intervals to be generated. | ||
* @return An array containing (amount | ||
*/ | ||
public static LocalDateTime[] getIntervals(IntervalPeriod intervalPeriod, int amount) { | ||
LocalDateTime[] intervals = new LocalDateTime[amount + 1]; | ||
intervals[amount] = LocalDateTime.now(); | ||
|
||
if (intervalPeriod == IntervalPeriod.YEAR) { | ||
for (int i = amount - 1; i >= 0; i--) { | ||
intervals[i] = intervals[i + 1].minusYears(1); | ||
} | ||
} else if (intervalPeriod == IntervalPeriod.MONTH) { | ||
for (int i = amount - 1; i >= 0; i--) { | ||
intervals[i] = intervals[i + 1].minusMonths(1); | ||
} | ||
} else if (intervalPeriod == IntervalPeriod.WEEK) { | ||
for (int i = amount - 1; i >= 0; i--) { | ||
intervals[i] = intervals[i + 1].minusWeeks(1); | ||
} | ||
} else if (intervalPeriod == IntervalPeriod.DAY) { | ||
for (int i = amount - 1; i >= 0; i--) { | ||
intervals[i] = intervals[i + 1].minusDays(1); | ||
} | ||
} else { | ||
for (int i = amount - 1; i >= 0; i--) { | ||
intervals[i] = intervals[i + 1].minusHours(1); | ||
} | ||
} | ||
|
||
return intervals; | ||
} | ||
|
||
/** | ||
* Method used to convert a LocalDateTime object to a String, in the format that the DPA uses. | ||
* | ||
* @param localDateTime The LocalDateTime object that should be converted to a String. | ||
* @return A String object in the format that the DPA uses that reflects the converted LocalDateTime object. | ||
*/ | ||
public static String dateToString(LocalDateTime localDateTime) { | ||
return localDateTime.toString() + "Z"; | ||
} | ||
|
||
/** | ||
* Method used to check whether the date contained in a certain LocalDateTime object is smaller than the date | ||
* contained in a certain String object. | ||
* | ||
* @param date1 The LocalDateTime object for which it will be checked if the contained date is smaller than the | ||
* contained date in s. | ||
* @param s The String object for which it will be checked whether the contained date is bigger than or equal | ||
* to the contained date in date1. | ||
* @return A boolean indicating whether the date contained in date1 is smaller than the date contained in s. | ||
*/ | ||
public static boolean isSmallerThan(LocalDateTime date1, String s) { | ||
LocalDateTime date2 = LocalDateTime.parse(s.split("Z")[0]); | ||
return date1.compareTo(date2) < 0; | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/nl/utwente/ing/misc/date/IntervalPeriod.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,13 @@ | ||
package nl.utwente.ing.misc.date; | ||
|
||
/** | ||
* The IntervalPeriod enum. | ||
* Used to enumerate the possible interval sizes. | ||
* | ||
* @author Daan Kooij | ||
*/ | ||
public enum IntervalPeriod { | ||
|
||
HOUR, DAY, WEEK, MONTH, YEAR; | ||
|
||
} |
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
91 changes: 91 additions & 0 deletions
91
src/main/java/nl/utwente/ing/model/bean/BalanceCandlestick.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,91 @@ | ||
package nl.utwente.ing.model.bean; | ||
|
||
/** | ||
* The Balance Candlestick class. | ||
* Used to store balance information about the balance information of a certain interval. | ||
* | ||
* @author Daan Kooij | ||
*/ | ||
public class BalanceCandlestick { | ||
|
||
private float open, close, high, low, volume; | ||
|
||
/** | ||
* The constructor of BalanceCandlestick. | ||
* Initially, only the opening balance is specified, after which this balance can be modified by using the mutate | ||
* method. Along the way, this bean keeps track of the opening balance, the closing balance, the highest balance, | ||
* the lowest balance and the volume of all the mutations combined. | ||
* | ||
* @param open The opening balance of this BalanceCandlestick. | ||
*/ | ||
public BalanceCandlestick(float open) { | ||
this.open = open; | ||
this.close = open; | ||
this.high = open; | ||
this.low = open; | ||
this.volume = 0; | ||
} | ||
|
||
/** | ||
* Method used to retrieve the opening balance of BalanceCandlestick. | ||
* | ||
* @return The opening balance of BalanceCandlestick. | ||
*/ | ||
public float getOpen() { | ||
return open; | ||
} | ||
|
||
/** | ||
* Method used to retrieve the closing balance of BalanceCandlestick. | ||
* | ||
* @return The closing balance of BalanceCandlestick. | ||
*/ | ||
public float getClose() { | ||
return close; | ||
} | ||
|
||
/** | ||
* Method used to retrieve the highest balance in the lifetime of BalanceCandlestick. | ||
* | ||
* @return The highest balance in the lifetime of BalanceCandlestick. | ||
*/ | ||
public float getHigh() { | ||
return high; | ||
} | ||
|
||
/** | ||
* Method used to retrieve the lowest balance in the lifetime of BalanceCandlestick. | ||
* | ||
* @return The lowest balance in the lifetime of BalanceCandlestick. | ||
*/ | ||
public float getLow() { | ||
return low; | ||
} | ||
|
||
/** | ||
* Method used to retrieve the volume of all the mutations done on BalanceCandlestick combined. | ||
* | ||
* @return The volume of all the mutations done on BalanceCandlestick combined. | ||
*/ | ||
public float getVolume() { | ||
return volume; | ||
} | ||
|
||
/** | ||
* Method used to indicate a mutation of the balance of BalanceCandlestick. | ||
* Along the way, this method updates the closing balance, the highest balance, the lowest balance | ||
* and the volume of all the mutations combined accordingly. | ||
* | ||
* @param amount The value with which the balance of BalanceCandlestick should be mutated. | ||
*/ | ||
public void mutation(float amount) { | ||
close += amount; | ||
if (close > high) { | ||
high = close; | ||
} else if (close < low) { | ||
low = close; | ||
} | ||
volume += Math.abs(amount); | ||
} | ||
|
||
} |
Oops, something went wrong.