Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ptltrader
- Overview
- Source
- Commits
- Branches
- Pull requests
- Pipelines
- Deployments
- Deployments
- Downloads
- Boards
- Boards
- Settings
- Karel Vavra ptltrader Source
- TripleBandLogic.java
- Branchmaster Check out branch Source Diff History ptltrader / src / main / java / com / pairtradinglab / ptltrader / trading / TripleBandLogic.java
- 0e62405 2017-11-06 Full commit Blame Raw Edit More file actions
- 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
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- package com.pairtradinglab.ptltrader.trading;
- import net.jcip.annotations.Immutable;
- @Immutable
- class TripleBandLogic {
- final double inThreshold;
- final double outThreshold;
- final double downTickThreshold;
- final double maxScore;
- final int entryMode;
- TripleBandLogic(double inThreshold, double outThreshold, double downTickThreshold, double maxScore, int entryMode) {
- this.inThreshold = inThreshold;
- this.outThreshold = outThreshold;
- this.downTickThreshold = downTickThreshold;
- this.maxScore = maxScore;
- this.entryMode = entryMode;
- }
- EntrySignal entryLogic(double scoreAsk, double scoreBid, double lastScoreAsk, double lastScoreBid) {
- int out = PairTradingModel.SIGNAL_NONE;
- if (entryMode == PairTradingModel.ENTRY_MODE_UPTICK) {
- // uptick
- if (scoreAsk <= -inThreshold && (maxScore<0.01 || scoreAsk>-maxScore) && lastScoreAsk > -inThreshold) out = PairTradingModel.SIGNAL_LONG;
- else if (scoreBid >= inThreshold && (maxScore<0.01 || scoreBid<maxScore) && lastScoreBid < inThreshold) out = PairTradingModel.SIGNAL_SHORT;
- } else if (entryMode == PairTradingModel.ENTRY_MODE_DOWNTICK) {
- // downtick
- if (scoreAsk > -inThreshold && scoreAsk<-downTickThreshold && (maxScore<0.01 || scoreAsk>-maxScore) && lastScoreAsk <= -inThreshold) out = PairTradingModel.SIGNAL_LONG;
- else if (scoreBid < inThreshold && scoreBid>downTickThreshold && (maxScore<0.01 || scoreBid<maxScore) && lastScoreBid >= inThreshold) out = PairTradingModel.SIGNAL_SHORT;
- } else {
- // simple
- if (scoreAsk <= -inThreshold && (maxScore<0.01 || scoreAsk>-maxScore)) out = PairTradingModel.SIGNAL_LONG;
- else if (scoreBid >= inThreshold && (maxScore<0.01 || scoreBid<maxScore)) out = PairTradingModel.SIGNAL_SHORT;
- }
- double zscoreInvolved = 0;
- if (out == PairTradingModel.SIGNAL_LONG) zscoreInvolved = scoreAsk;
- else if (out == PairTradingModel.SIGNAL_SHORT) zscoreInvolved = scoreBid;
- return new EntrySignal(out, zscoreInvolved);
- }
- ExitSignal exitLogic(int position, double scoreAsk, double scoreBid) {
- if (position==PairTradingModel.SIGNAL_SHORT && scoreAsk<=outThreshold) {
- return new ExitSignal(true, scoreAsk);
- } else if (position==PairTradingModel.SIGNAL_LONG && scoreBid>=-outThreshold) {
- return new ExitSignal(true, scoreBid);
- } else {
- return new ExitSignal(false, 0);
- }
- }
- boolean checkReversal(double score, double lastExitScore) {
- return Math.abs(lastExitScore)>=inThreshold && Math.abs(score)>=inThreshold && score*lastExitScore>=0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement