Package name.abuchen.portfolio.model

Examples of name.abuchen.portfolio.model.Security


        DateMidnight endDate = new DateMidnight(2012, 4, 29); // a weekend
        long startPrice = 100 * Values.Amount.factor();

        Client client = new Client();

        Security security = new SecurityBuilder() //
                        .generatePrices(startPrice, startDate, endDate) //
                        .addTo(client);

        PortfolioBuilder portfolio = new PortfolioBuilder();

        // add some buy transactions
        DateMidnight date = startDate;
        while (date.isBefore(endDate))
        {
            long p = security.getSecurityPrice(date.toDate()).getValue();
            portfolio.inbound_delivery(security, date, 1 * Values.Share.factor(), p);
            date = date.plusDays(20);
        }

        portfolio.addTo(client);

        ReportingPeriod.FromXtoY period = new ReportingPeriod.FromXtoY(startDate.toDate(), endDate.toDate());

        List<Exception> warnings = new ArrayList<Exception>();
        ClientIndex index = PerformanceIndex.forClient(client, period, warnings);
        assertTrue(warnings.isEmpty());

        double[] accumulated = index.getAccumulatedPercentage();
        long lastPrice = security.getSecurityPrice(endDate.toDate()).getValue();

        assertThat((double) (lastPrice - startPrice) / (double) startPrice,
                        IsCloseTo.closeTo(accumulated[accumulated.length - 1], PRECISION));
    }
View Full Code Here


                        .addClassification("debt") //
                        .addClassification("equity") //
                        .addClassification("realestate") //
                        .addTo(client);

        Security a = new SecurityBuilder() //
                        .addPrice("2010-01-01", 1000) //
                        .assign(taxonomy, "debt") //
                        .addTo(client);

        Security c = new SecurityBuilder() //
                        .addPrice("2010-01-01", 1200) //
                        .assign(taxonomy, "equity") //
                        .addTo(client);

        Security d = new SecurityBuilder() //
                        .addPrice("2010-01-01", 1200) //
                        .assign(taxonomy, "equity") //
                        .addTo(client);

        Portfolio portfolio = new PortfolioBuilder() //
View Full Code Here

        Taxonomy taxonomy = new TaxonomyBuilder() //
                        .addClassification("debt") //
                        .addClassification("equity") //
                        .addTo(client);

        Security a = new SecurityBuilder() //
                        .addPrice("2010-01-01", 1000) //
                        .assign(taxonomy, "debt", Classification.ONE_HUNDRED_PERCENT / 2) //
                        .assign(taxonomy, "equity", Classification.ONE_HUNDRED_PERCENT / 2) //
                        .addTo(client);
View Full Code Here

                        .addClassification("debt") //
                        .addClassification("debt", "cat1") //
                        .addClassification("debt", "cat2") //
                        .addTo(client);

        Security a = new SecurityBuilder() //
                        .addPrice("2010-01-01", 1000) //
                        .assign(taxonomy, "cat1", Classification.ONE_HUNDRED_PERCENT / 2) //
                        .assign(taxonomy, "cat2", Classification.ONE_HUNDRED_PERCENT / 2) //
                        .addTo(client);
View Full Code Here

        Taxonomy taxonomy = new TaxonomyBuilder() //
                        .addClassification("debt") //
                        .addTo(client);

        Security a = new SecurityBuilder() //
                        .addPrice("2010-01-01", 1000) //
                        .addTo(client);

        Portfolio portfolio = new PortfolioBuilder() //
                        .inbound_delivery(a, "2010-01-01", 1000000, 10000) //
View Full Code Here

        Taxonomy taxonomy = new TaxonomyBuilder() //
                        .addClassification("debt") //
                        .addTo(client);

        Security a = new SecurityBuilder() //
                        .addPrice("2010-01-01", 1000) //
                        .assign(taxonomy, "debt", Classification.ONE_HUNDRED_PERCENT / 2) //
                        .addTo(client);

        Portfolio portfolio = new PortfolioBuilder() //
View Full Code Here

        new AccountBuilder() //
                        .deposit_(startDate, startPrice) //
                        .addTo(client);

        Security security = new SecurityBuilder() //
                        .generatePrices(startPrice, startDate, endDate) //
                        .addTo(client);

        // calculate performance indices

        List<Exception> warnings = new ArrayList<Exception>();

        ReportingPeriod reportInterval = new ReportingPeriod.FromXtoY(startDate.toDate(), endDate.toDate());
        ClientIndex clientIndex = PerformanceIndex.forClient(client, reportInterval, warnings);
        PerformanceIndex securityIndex = PerformanceIndex.forSecurity(clientIndex, security, warnings);

        // asserts

        assertTrue(warnings.isEmpty());

        Date[] dates = securityIndex.getDates();
        assertThat(dates[0], is(startDate.toDate()));
        assertThat(dates[dates.length - 1], is(endDate.toDate()));

        long lastPrice = security.getSecurityPrice(endDate.toDate()).getValue();
        double performance = (double) (lastPrice - startPrice) / (double) startPrice;

        double[] accumulated = securityIndex.getAccumulatedPercentage();
        assertThat(accumulated[0], is(0d));
        assertThat(accumulated[accumulated.length - 1], IsCloseTo.closeTo(performance, 0.000001d));
View Full Code Here

        new AccountBuilder() //
                        .deposit_(startDate, 100 * Values.Amount.factor()) //
                        .interest(startDate.plusDays(10), 10 * Values.Amount.factor()) //
                        .addTo(client);

        Security security = new SecurityBuilder() //
                        .generatePrices(50 * Values.Amount.factor(), middleDate, endDate) //
                        .addTo(client);

        // calculate performance indices

        List<Exception> warnings = new ArrayList<Exception>();

        ReportingPeriod reportInterval = new ReportingPeriod.FromXtoY(startDate.toDate(), endDate.toDate());
        ClientIndex clientIndex = PerformanceIndex.forClient(client, reportInterval, warnings);
        PerformanceIndex securityIndex = PerformanceIndex.forSecurity(clientIndex, security, warnings);

        // asserts

        assertTrue(warnings.isEmpty());

        Date[] clientDates = clientIndex.getDates();
        Date[] securityDates = securityIndex.getDates();

        assertThat(securityDates[0], is(middleDate.toDate()));
        assertThat(securityDates[securityDates.length - 1], is(endDate.toDate()));
        assertThat(new DateMidnight(clientDates[clientDates.length - 1]), is(new DateMidnight(
                        securityDates[securityDates.length - 1])));

        double[] clientAccumulated = clientIndex.getAccumulatedPercentage();
        double[] securityAccumulated = securityIndex.getAccumulatedPercentage();

        int index = Days.daysBetween(startDate, middleDate).getDays();
        assertThat(new DateMidnight(clientDates[index]), is(middleDate));
        assertThat(securityAccumulated[0], IsCloseTo.closeTo(clientAccumulated[index], 0.000001d));

        long middlePrice = security.getSecurityPrice(middleDate.toDate()).getValue();
        long lastPrice = security.getSecurityPrice(endDate.toDate()).getValue();

        // 10% is interest of the deposit
        double performance = (double) (lastPrice - middlePrice) / (double) middlePrice + 0.1d;
        assertThat(securityAccumulated[securityAccumulated.length - 1], IsCloseTo.closeTo(performance, 0.000001d));
    }
View Full Code Here

                        .interest(startDate.plusDays(10), 10 * Values.Amount.factor()) //
                        .addTo(client);

        int startPrice = 50 * Values.Amount.factor();

        Security security = new SecurityBuilder() //
                        .generatePrices(startPrice, startDate, middleDate) //
                        .addTo(client);

        // calculate performance indices

        List<Exception> warnings = new ArrayList<Exception>();

        ReportingPeriod reportInterval = new ReportingPeriod.FromXtoY(startDate.toDate(), endDate.toDate());
        ClientIndex clientIndex = PerformanceIndex.forClient(client, reportInterval, warnings);
        PerformanceIndex securityIndex = PerformanceIndex.forSecurity(clientIndex, security, warnings);

        // asserts

        assertTrue(warnings.isEmpty());

        Date[] clientDates = clientIndex.getDates();
        Date[] securityDates = securityIndex.getDates();

        assertThat(securityDates[0], is(startDate.toDate()));
        assertThat(securityDates[securityDates.length - 1], is(middleDate.toDate()));
        assertThat(new DateMidnight(clientDates[0]), is(new DateMidnight(securityDates[0])));

        double[] securityAccumulated = securityIndex.getAccumulatedPercentage();

        int index = Days.daysBetween(startDate, middleDate).getDays();
        assertThat(new DateMidnight(clientDates[index]), is(middleDate));
        assertThat(securityAccumulated[0], IsCloseTo.closeTo(0d, 0.000001d));

        long middlePrice = security.getSecurityPrice(middleDate.toDate()).getValue();
        double performance = (double) (middlePrice - startPrice) / (double) startPrice;
        assertThat(securityAccumulated[securityAccumulated.length - 1], IsCloseTo.closeTo(performance, 0.000001d));
    }
View Full Code Here

        new AccountBuilder() //
                        .deposit_(startDate, 100 * Values.Amount.factor()) //
                        .addTo(client);

        Security security = new Security();
        client.addSecurity(security);

        // calculate performance indices

        List<Exception> warnings = new ArrayList<Exception>();
View Full Code Here

TOP

Related Classes of name.abuchen.portfolio.model.Security

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.