/ src / Features.java
Features.java
 1  import java.io.IOException;
 2  import java.math.BigDecimal;
 3  import java.util.HashMap;
 4  
 5  /**
 6   * Created by MichaelBick on 7/29/15.
 7   */
 8  public class Features {
 9      private static final int SPREAD = 10;
10  
11      private static final int PAST_DAYS = 3;
12  
13      private Symbol sp500;
14      private HashMap<Integer, BigDecimal> market = new HashMap<Integer, BigDecimal>();
15  
16      public Features() throws IOException{
17          sp500 = new Symbol("^GSPC");
18      }
19  
20      public double[] getFeatures(Symbol stock, int daysAgo) throws IOException {
21          double[] features = new double[5];
22  
23          features[0] = 1.0;
24  
25          features[1] = stock.getAdjClose(daysAgo).doubleValue();
26          
27          features[features.length - 3] = stock.getMA(daysAgo, 50).doubleValue();
28          features[features.length - 2] = stock.getMA(daysAgo, 200).doubleValue();
29          
30          features[features.length - 1] = sp500.getMA(daysAgo, 50).doubleValue();
31  
32          return features;
33      }
34  
35      public static void print(double[] weights) {
36          System.out.println("Constant: " + weights[0]);
37          System.out.println("Today's Price: " + weights[1]);
38          System.out.println("50 Day MA: " + weights[2]);
39          System.out.println("200 Day MA: " + weights[3]);
40          System.out.println("SP500 50 Day MA: " + weights[4]);
41      }
42  }