Пример #1
0
  public static void ImportPortfolios(String filename, Map<String, Portfolio> pss)
      throws IOException, ParseException {
    // String filename = "ExportedPortfolios.txt";
    BufferedReader br = new BufferedReader(new FileReader(filename));
    String line = "";
    while ((line = br.readLine()) != null) {
      List<String> strings = Arrays.asList(line.split("\\|"));
      // System.out.println(strings.get(0)+" "+strings.get(1));
      String name = strings.get(0);
      String pass = decrypt(strings.get(1));

      users.put(name, pass);
      Map<String, Integer> equitie = new HashMap<String, Integer>();
      Map<String, Account> Accountt = new HashMap<String, Account>();
      List<Transaction> trans = new ArrayList<Transaction>();

      for (int i = 2; i < strings.size(); i++) {
        String s = strings.get(i);
        String[] lst = s.split(",");
        if (lst.length >= 3) {
          if (lst[0].equals("e")) {
            equitie.put(lst[1], Integer.parseInt(lst[2]));
          } else if (lst[0].equals("a")) {
            SimpleDateFormat sdf =
                new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
            Date d = sdf.parse(lst[5]);
            Account ac =
                new Account(lst[1], lst[2], Float.parseFloat(lst[3]), Float.parseFloat(lst[4]), d);
            Accountt.put(lst[2], ac);
          } else if (lst[0].equals("t")) {
            SimpleDateFormat sdf =
                new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
            Date d = sdf.parse(lst[4]);
            trans.add(new Transaction(lst[1], lst[2], Float.parseFloat(lst[3]), d));
          } else if (lst[0].equals("b")) {
            SimpleDateFormat sdf =
                new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
            Date d = sdf.parse(lst[4]);
            trans.add(
                new Transaction(
                    lst[0], sEquities.get(lst[1]), Integer.parseInt(lst[2]), lst[3], d));
          }
        }
      }
      Portfolio p = new Portfolio(name, equitie, Accountt);
      p.setTrans(trans);
      pss.put(name, p);
    }
  }
Пример #2
0
 public PositionView createPositionView(Portfolio portfolio, Integer instrumentId) {
   Double lastPrice = mapStockPrices.get(instrumentId);
   if (lastPrice == null) return null;
   Position position = portfolio.getPosition(instrumentId);
   return new PositionView(
       portfolio.pmId,
       instrumentId,
       position.quantity,
       lastPrice,
       position.calculateProfitLoss(lastPrice));
 }
Пример #3
0
  public static void ExportPortfolios() throws FileNotFoundException, UnsupportedEncodingException {
    String filename = "xp.txt";
    Iterator it = users.entrySet().iterator();
    PrintWriter writer = new PrintWriter(filename, "UTF-8");
    while (it.hasNext()) {
      Map.Entry pair = (Map.Entry) it.next();

      writer.print(pair.getKey() + "|" + encrypt((String) pair.getValue()));
      writer.print("|");
      Portfolio p = portfolios.get(pair.getKey());
      Map<String, Integer> equitiess = p.getEquities();
      Iterator it1 = equitiess.entrySet().iterator();
      while (it1.hasNext()) {
        Map.Entry e = (Map.Entry) it1.next();
        writer.print("e," + e.getKey() + "," + e.getValue() + "|");
      }
      Map<String, Account> accountss = p.getAccounts();
      Iterator it2 = accountss.entrySet().iterator();
      while (it2.hasNext()) {
        Map.Entry a = (Map.Entry) it2.next();
        Date d = ((Account) a.getValue()).getDateAdded();
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
        String da = sdf.format(d);
        writer.print(
            "a,"
                + ((Account) a.getValue()).getType()
                + ","
                + ((Account) a.getValue()).getName()
                + ","
                + (((Account) a.getValue()).getInitialAmount()
                    + ","
                    + (((Account) a.getValue()).getCurrentAmount())
                    + ","
                    + da
                    + "|"));
      }
      for (Transaction tr : p.getTrans()) {
        if (tr.getType().equals("t")) {
          Date d = tr.getDate();
          SimpleDateFormat sdf =
              new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
          String da = sdf.format(d);
          writer.print(
              "t," + tr.getA1() + "," + tr.getA2() + "," + tr.getAmount() + "," + da + "|");
        } else {
          Date d = tr.getDate();
          SimpleDateFormat sdf =
              new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
          String da = sdf.format(d);
          writer.print(
              tr.getType()
                  + ","
                  + tr.getEquity().getTicker()
                  + ","
                  + tr.getNumber()
                  + ","
                  + tr.getA1()
                  + da
                  + "|");
        }
      }
      writer.println();
    }
    writer.close();
  }