package com.after_sunrise.cryptocurrency.cryptotrader.service.bitflyer;

import com.after_sunrise.cryptocurrency.cryptotrader.service.template.TemplateAdviser;

/**
 * @author takanori.takase
 * @version 0.0.1
 */
public class BitflyerAdviser extends TemplateAdviser implements BitflyerService {

    public BitflyerAdviser() {
        super(ID);
    }

}

@@ -123,40 +123,438 @@
 der.
-service.template.TemplateAdviser
+framework.Context;%0Aimport com.after_sunrise.cryptocurrency.cryptotrader.framework.Request;%0Aimport com.after_sunrise.cryptocurrency.cryptotrader.service.template.TemplateAdviser;%0Aimport lombok.extern.slf4j.Slf4j;%0A%0Aimport java.math.BigDecimal;%0Aimport java.time.Duration;%0Aimport java.time.Instant;%0Aimport java.time.ZoneId;%0Aimport java.time.ZonedDateTime;%0Aimport java.time.temporal.ChronoUnit;%0A%0Aimport static java.math.RoundingMode.UP
 ;%0A%0A/
@@ -605,16 +605,23 @@
 0.1%0A */%0A
+@Slf4j%0A
 public c
@@ -704,52 +704,1175 @@
    p
-ublic BitflyerAdviser() %7B%0A        super(ID);
+rivate static final ZoneId SWAP_ZONE = ZoneId.of(%22Asia/Tokyo%22);%0A%0A    private static final double SWAP_RATE = 0.0004;%0A%0A    public BitflyerAdviser() %7B%0A        super(ID);%0A    %7D%0A%0A    @Override%0A    protected BigDecimal calculateBasis(Context context, Request request) %7B%0A%0A        BigDecimal base = super.calculateBasis(context, request);%0A%0A        if (base == null) %7B%0A            return null;%0A        %7D%0A%0A        Instant now = request.getCurrentTime();%0A%0A        if (now == null) %7B%0A            return base;%0A        %7D%0A%0A        ZonedDateTime expiry = context.getExpiry(Context.Key.from(request));%0A%0A        if (expiry == null) %7B%0A            return base; // Not an expiry product.%0A        %7D%0A%0A        ZonedDateTime sod = expiry.truncatedTo(ChronoUnit.DAYS);%0A%0A        Duration swapFree = Duration.between(sod, expiry);%0A%0A        Duration maturity = Duration.between(request.getCurrentTime(), expiry);%0A%0A        if (maturity.compareTo(swapFree) %3C 0) %7B%0A            return base; // Expiring without swap.%0A        %7D%0A%0A        long swaps = maturity.toDays();%0A%0A        double rate = Math.pow(1 + SWAP_RATE, swaps) - 1;%0A%0A        return base.add(BigDecimal.valueOf(rate)).setScale(SCALE, UP);%0A
 %0A   

Swap rate adjustment.