-
Notifications
You must be signed in to change notification settings - Fork 13
/
OSmoveScalingLaw.java
119 lines (105 loc) · 3.52 KB
/
OSmoveScalingLaw.java
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package scalinglaws;
import ievents.DcOS;
import market.Price;
import tools.Tools;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by author.
*
* This class is dedicated to the computation of the "Overshoot scaling law", Law 9 (os) from
* the "Patterns in high-frequency FX data: Discovery of 12 empirical scaling laws".
*
* One of the results of the computation is a file with two columns: Delta, OSmove.
* Another result is the coefficients of the scaling law.
*
* In order to run the code one should:
* choose the lowest and highest size of thresholds;
* define number of points between the chosen thresholds;
* choose whether to store results to a file or no.
*/
public class OSmoveScalingLaw {
private double[] arrayDeltas;
private DcOS[] dcOses;
private double[] osMoves;
private double[] numDCs;
private int numPoints;
private double[] scalingLawParam;
/**
* The constructor of the class.
* @param lowDelta
* @param higDelta
* @param numPoints
*/
public OSmoveScalingLaw(float lowDelta, float higDelta, int numPoints){
arrayDeltas = Tools.GenerateLogSpace(lowDelta, higDelta, numPoints);
dcOses = new DcOS[numPoints];
for (int i = 0; i < numPoints; i++){
double delta = arrayDeltas[i];
dcOses[i] = new DcOS(delta, delta, 1, delta, delta, true);
}
numDCs = new double[numPoints];
osMoves = new double[numPoints];
this.numPoints = numPoints;
}
/**
*
* @param aPrice is the next observed (generated, recorded...) price
*/
public void run(Price aPrice){
for (int i = 0; i < numPoints; i++){
int event = dcOses[i].run(aPrice);
if (event == 1 || event == -1){
osMoves[i] += dcOses[i].getOsL();
numDCs[i] += 1;
}
}
}
/**
* Here the method simply finds average value of each overshoot set
*/
public void finish(){
for (int i = 0; i < numPoints; i++){
if (numDCs[i] != 0){
osMoves[i] /= numDCs[i];
}
}
}
/**
* The function finds the scaling law parameters defined in "Patterns in high-frequency FX data: Discovery of 12
* empirical scaling laws J.B.", page 13
* @return the same what the function Tools.computeScalingParams returns
*/
public double[] computeParams(){
scalingLawParam = Tools.computeScalingParams(arrayDeltas, osMoves);
return scalingLawParam;
}
/**
*
* @param dirName is the name of the output folder.
*/
public void saveResults(String dirName){
Tools.CheckDirectory(dirName);
try {
String dateString = new SimpleDateFormat("yyyy-MM-dd_hh-mm-ss").format(new Date());
String fileName = "17_osMoveScalingLaw" + "_" + dateString + ".csv";
PrintWriter writer = new PrintWriter(dirName + "/" + fileName, "UTF-8");
writer.println("Delta;OSmove");
for (int i = 0; i < numPoints; i++){
writer.println(arrayDeltas[i] + ";" + osMoves[i]);
}
writer.close();
System.out.println("The file is saved as: " + fileName);
} catch (Exception ex){
ex.printStackTrace();
}
}
public double[] getNumDCs() {
return numDCs;
}
public double[] getOsMoves() { return osMoves;}
public double[] getArrayDeltas() {
return arrayDeltas;
}
}