Search in sources :

Example 1 with PortfolioManager

use of com.github.jnidzwetzki.cryptobot.portfolio.PortfolioManager in project crypto-bot by jnidzwetzki.

the class TestCapitalAllocation method testCapitalAllocationExchange1.

@Test
public void testCapitalAllocationExchange1() throws APIException {
    final PortfolioManager portfolioManager = buildPortfolioManager();
    final Map<BitfinexCurrencyPair, CurrencyEntry> entries = new HashMap<>();
    final CurrencyEntry entry1 = new CurrencyEntry(BitfinexCurrencyPair.BTC_USD, 1000, 990);
    entries.put(BitfinexCurrencyPair.BTC_USD, entry1);
    portfolioManager.calculatePositionSizes(entries);
    // Max loss = 10, max capital allocation 50%
    Assert.assertEquals(0.45, entry1.getPositionSize(), DELTA);
}
Also used : HashMap(java.util.HashMap) BasePortfolioManager(com.github.jnidzwetzki.cryptobot.portfolio.BasePortfolioManager) PortfolioManager(com.github.jnidzwetzki.cryptobot.portfolio.PortfolioManager) CurrencyEntry(com.github.jnidzwetzki.cryptobot.CurrencyEntry) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) Test(org.junit.Test)

Example 2 with PortfolioManager

use of com.github.jnidzwetzki.cryptobot.portfolio.PortfolioManager in project crypto-bot by jnidzwetzki.

the class TestCapitalAllocation method testCapitalAllocationExchangeMaxPositionLoss1.

@Test
public void testCapitalAllocationExchangeMaxPositionLoss1() throws APIException {
    final PortfolioManager portfolioManager = buildPortfolioManager();
    final Map<BitfinexCurrencyPair, CurrencyEntry> entries = new HashMap<>();
    final CurrencyEntry entry1 = new CurrencyEntry(BitfinexCurrencyPair.BTC_USD, 1000, 0);
    entries.put(BitfinexCurrencyPair.BTC_USD, entry1);
    portfolioManager.calculatePositionSizes(entries);
    // Max loss = 10, max capital allocation 50%
    Assert.assertEquals(0.045, entry1.getPositionSize(), DELTA);
}
Also used : HashMap(java.util.HashMap) BasePortfolioManager(com.github.jnidzwetzki.cryptobot.portfolio.BasePortfolioManager) PortfolioManager(com.github.jnidzwetzki.cryptobot.portfolio.PortfolioManager) CurrencyEntry(com.github.jnidzwetzki.cryptobot.CurrencyEntry) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) Test(org.junit.Test)

Example 3 with PortfolioManager

use of com.github.jnidzwetzki.cryptobot.portfolio.PortfolioManager in project crypto-bot by jnidzwetzki.

the class TestCapitalAllocation method testCapitalAllocationExchange2.

@Test
public void testCapitalAllocationExchange2() throws APIException {
    final PortfolioManager portfolioManager = buildPortfolioManager();
    final Map<BitfinexCurrencyPair, CurrencyEntry> entries = new HashMap<>();
    final CurrencyEntry entry1 = new CurrencyEntry(BitfinexCurrencyPair.BTC_USD, 1000, 990);
    entries.put(BitfinexCurrencyPair.BTC_USD, entry1);
    final CurrencyEntry entry2 = new CurrencyEntry(BitfinexCurrencyPair.IOT_USD, 1000, 990);
    entries.put(BitfinexCurrencyPair.IOT_USD, entry2);
    portfolioManager.calculatePositionSizes(entries);
    // Max loss = 10, max capital allocation 50%
    Assert.assertEquals(0.45, entry1.getPositionSize(), DELTA);
    Assert.assertEquals(0.45, entry2.getPositionSize(), DELTA);
}
Also used : HashMap(java.util.HashMap) BasePortfolioManager(com.github.jnidzwetzki.cryptobot.portfolio.BasePortfolioManager) PortfolioManager(com.github.jnidzwetzki.cryptobot.portfolio.PortfolioManager) CurrencyEntry(com.github.jnidzwetzki.cryptobot.CurrencyEntry) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) Test(org.junit.Test)

Example 4 with PortfolioManager

use of com.github.jnidzwetzki.cryptobot.portfolio.PortfolioManager in project crypto-bot by jnidzwetzki.

the class DonchianBot method executeSystem.

/**
 * Execute the trading system
 * @throws APIException
 */
private void executeSystem() {
    for (final PortfolioManager portfolioManager : portfolioManagers) {
        logger.info("Apply orders to portfolio manager {}", portfolioManager);
        logger.info("===============================================");
        applySystemToPortfolioManager(portfolioManager);
        if (Thread.interrupted()) {
            return;
        }
    }
}
Also used : PortfolioManager(com.github.jnidzwetzki.cryptobot.portfolio.PortfolioManager) BasePortfolioManager(com.github.jnidzwetzki.cryptobot.portfolio.BasePortfolioManager)

Example 5 with PortfolioManager

use of com.github.jnidzwetzki.cryptobot.portfolio.PortfolioManager in project crypto-bot by jnidzwetzki.

the class TestCapitalAllocation method testCapitalAllocationExchangeMaxPositionLoss2.

@Test
public void testCapitalAllocationExchangeMaxPositionLoss2() throws APIException {
    final PortfolioManager portfolioManager = buildPortfolioManager();
    final Map<BitfinexCurrencyPair, CurrencyEntry> entries = new HashMap<>();
    final CurrencyEntry entry1 = new CurrencyEntry(BitfinexCurrencyPair.BTC_USD, 1000, 0);
    entries.put(BitfinexCurrencyPair.BTC_USD, entry1);
    final CurrencyEntry entry2 = new CurrencyEntry(BitfinexCurrencyPair.IOT_USD, 1000, 990);
    entries.put(BitfinexCurrencyPair.IOT_USD, entry2);
    portfolioManager.calculatePositionSizes(entries);
    // Max loss = 10, max capital allocation 50%
    Assert.assertEquals(0.045, entry1.getPositionSize(), DELTA);
    Assert.assertEquals(0.45, entry2.getPositionSize(), DELTA);
}
Also used : HashMap(java.util.HashMap) BasePortfolioManager(com.github.jnidzwetzki.cryptobot.portfolio.BasePortfolioManager) PortfolioManager(com.github.jnidzwetzki.cryptobot.portfolio.PortfolioManager) CurrencyEntry(com.github.jnidzwetzki.cryptobot.CurrencyEntry) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) Test(org.junit.Test)

Aggregations

BasePortfolioManager (com.github.jnidzwetzki.cryptobot.portfolio.BasePortfolioManager)7 PortfolioManager (com.github.jnidzwetzki.cryptobot.portfolio.PortfolioManager)7 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)6 CurrencyEntry (com.github.jnidzwetzki.cryptobot.CurrencyEntry)6 HashMap (java.util.HashMap)6 Test (org.junit.Test)6