コード例 #1
0
ファイル: ExportWizard.java プロジェクト: jahzoo/portfolio
  @Override
  public boolean performFinish() {
    Object exportItem = exportPage.getExportItem();
    Class<?> exportClass = exportPage.getExportClass();

    File file = getFile(exportItem);

    try {
      // account transactions
      if (exportItem == AccountTransaction.class) {
        new CSVExporter().exportAccountTransactions(file, client.getAccounts());
      } else if (exportClass == AccountTransaction.class) {
        new CSVExporter().exportAccountTransactions(file, (Account) exportItem);
      }

      // portfolio transactions
      else if (exportItem == PortfolioTransaction.class) {
        new CSVExporter().exportPortfolioTransactions(file, client.getPortfolios());
      } else if (exportClass == PortfolioTransaction.class) {
        new CSVExporter().exportPortfolioTransactions(file, (Portfolio) exportItem);
      }

      // master data
      else if (exportItem == Security.class) {
        new CSVExporter()
            .exportSecurityMasterData(
                new File(file, Messages.ExportWizardSecurityMasterData + ".csv"),
                client.getSecurities()); // $NON-NLS-1$
      } else if (exportClass == Security.class) {
        if (Messages.ExportWizardSecurityMasterData.equals(exportItem))
          new CSVExporter().exportSecurityMasterData(file, client.getSecurities());
        else if (Messages.ExportWizardMergedSecurityPrices.equals(exportItem))
          new CSVExporter().exportMergedSecurityPrices(file, client.getSecurities());
      }

      // historical quotes
      else if (exportItem == SecurityPrice.class) {
        new CSVExporter().exportSecurityPrices(file, client.getSecurities());
      } else if (exportClass == SecurityPrice.class) {
        new CSVExporter().exportSecurityPrices(file, (Security) exportItem);
      } else {
        throw new UnsupportedOperationException(
            MessageFormat.format(Messages.ExportWizardUnsupportedExport, exportClass, exportItem));
      }
    } catch (IOException e) {
      PortfolioPlugin.log(e);
      MessageDialog.openError(getShell(), Messages.ExportWizardErrorExporting, e.getMessage());
    }

    return true;
  }
コード例 #2
0
  private static Map<Security, SecurityPerformanceRecord> initRecords(Client client) {
    Map<Security, SecurityPerformanceRecord> records =
        new HashMap<Security, SecurityPerformanceRecord>();

    for (Security s : client.getSecurities()) records.put(s, new SecurityPerformanceRecord(s));
    return records;
  }
コード例 #3
0
  @Test
  public void testVolatilityIfSecurityIsSoldAndLaterBoughtDuringReportingPeriod()
      throws IOException {
    ReportingPeriod report =
        new ReportingPeriod.FromXtoY(Dates.date("2014-01-31"), Dates.date("2015-02-20"));
    List<Exception> warnings = new ArrayList<>();

    Security basf =
        client.getSecurities().stream().filter(s -> "Basf SE".equals(s.getName())).findAny().get();
    PerformanceIndex index = PerformanceIndex.forInvestment(client, basf, report, warnings);

    assertThat(warnings, empty());
    assertThat(
        index.getVolatility().getStandardDeviation(),
        closeTo(0.0134468200485513, 0.00001)); // excel
    assertThat(index.getDates()[index.getDates().length - 1], is(Dates.date("2015-02-20")));
  }
コード例 #4
0
  @Test
  public void testVolatilityIfBenchmarkHasNoQuotes() throws IOException {
    ReportingPeriod report =
        new ReportingPeriod.FromXtoY(Dates.date("2014-01-31"), Dates.date("2015-01-31"));
    List<Exception> warnings = new ArrayList<>();

    PerformanceIndex index = PerformanceIndex.forClient(client, report, warnings);

    Security sap =
        client.getSecurities().stream().filter(s -> "Sap AG".equals(s.getName())).findAny().get();
    PerformanceIndex sapIndex = PerformanceIndex.forSecurity(index, sap, warnings);

    assertThat(warnings, empty());
    // quotes only until December 31st
    assertThat(sapIndex.getDates()[sapIndex.getDates().length - 1], is(Dates.date("2014-12-31")));
    assertThat(
        sapIndex.getVolatility().getStandardDeviation(),
        closeTo(0.0126152529671108, 0.00001)); // excel
  }
コード例 #5
0
  @Test
  public void testVolatilityIfSecurityIsSoldDuringReportingPeriod() throws IOException {
    ReportingPeriod report =
        new ReportingPeriod.FromXtoY(Dates.date("2014-01-31"), Dates.date("2015-01-31"));
    List<Exception> warnings = new ArrayList<>();

    Security basf =
        client.getSecurities().stream().filter(s -> "Basf SE".equals(s.getName())).findAny().get();
    PerformanceIndex index = PerformanceIndex.forInvestment(client, basf, report, warnings);

    assertThat(warnings, empty());
    assertThat(
        index.getVolatility().getStandardDeviation(), closeTo(0.01371839502, 0.00001)); // excel
    assertThat(index.getDates()[index.getDates().length - 1], is(Dates.date("2015-01-31")));

    // compare with client -> must be lower because cash has volatility of 0
    PerformanceIndex clientIndex = PerformanceIndex.forClient(client, report, warnings);
    assertThat(
        clientIndex.getVolatility().getStandardDeviation(),
        lessThan(index.getVolatility().getStandardDeviation()));
  }
コード例 #6
0
 public UpdateQuotesJob(Client client, boolean includeHistoricQuotes, long repeatPeriod) {
   this(client, client.getSecurities(), includeHistoricQuotes, repeatPeriod);
 }
コード例 #7
0
 @Override
 public Status process(Security security) {
   // might have been added via a transaction
   if (!client.getSecurities().contains(security)) client.addSecurity(security);
   return Status.OK_STATUS;
 }