Repository navigation
Expand file tree
/
Copy pathtest.java
More file actions
48 lines (40 loc) · 1.49 KB
/
Copy pathtest.java
File metadata and controls
48 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package trading;
import game.DailyOutput;
import game.TradingManager;
import tradingstrategy.BaseTradingStrategy;
import dataobjects.DailyInput;
import exceptions.InsufficientFundsException;
import exceptions.InsufficientSharesException;
public class TradingStrategy extends BaseTradingStrategy {
public TradingStrategy(TradingManager tradingManager) {
super.tradingManager = tradingManager;
}
@Override
public DailyOutput makeDailyTrade(DailyInput input) throws InsufficientFundsException, InsufficientSharesException {
//use the trading manager to make trades based on input
DailyOutput output;
double variance = 100 - input.getLow()/input.getHigh() * 100;
//System.out.println(variance);
//250 days trading
//System.out.println(input);
if (variance > 15) {
output = tradingManager.sellAllShares(input);
}
else if (input.getOpen() - input.getClose() > 1) {
output = tradingManager.sellNumberOfShares(input, tradingManager.getSharesOwned());
}
else if (input.getOpen() - input.getClose() > 0.4) {
output = tradingManager.sellNumberOfShares(input, tradingManager.getSharesOwned()/2);
}
else if (input.getOpen() - input.getClose() < -0.1) {
output = tradingManager.buySharesOfValue(input, tradingManager.getAvailableFunds());
}
else if (input.getOpen() - input.getClose() < 0.2) {
output = tradingManager.buySharesOfValue(input, tradingManager.getAvailableFunds()/2);
}
else {
output = tradingManager.doNothing(input);
}
return output;
}
}