Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package alproxy;
- import com.calypso.tk.bo.BOCre;
- import com.calypso.tk.core.JDatetime;
- import com.calypso.tk.core.Product;
- import com.calypso.tk.core.Trade;
- import com.calypso.tk.product.Bond;
- import com.calypso.tk.product.CA;
- import com.calypso.tk.service.DSConnection;
- import com.calypso.tk.util.ConnectionUtil;
- import com.rbos.cmpp.translations.TranslateHelper;
- import com.rbos.cmpp.util.Formatter;
- import com.rbos.cmpp.util.LiquidationTradeInfo;
- import com.rbos.cmpp.util.NonStaticFormatter;
- public class PayDownCreTest {
- private static final String user = "calypso_user";
- private static final String password = "calypso";
- private static final String appname = "test";
- private static final String env = "UAT1";
- public static void main(String[] args) throws Exception {
- DSConnection ds = null;
- try {
- ds = ConnectionUtil.connect(user, password, appname, env);
- BOCre bocre = ds.getRemoteBO().getBOCre(69758561);
- LiquidationTradeInfo lti = getLiquidatingAndLiquidatedTradeIds(
- ds.getRemoteTrade().getTrade(bocre.getTradeId()), bocre);
- String fktName = "setupSpecific: ";
- double remainingQuantity = 0.0d;
- double caAmount = bocre.getAmount(4);
- double redemptionPrice = bocre.getAmount(3);
- double realisedAmount = bocre.getAmount(0);
- Trade payDownTrade = lti.getLiquidatingTrade();
- Trade liquidatedTrade = lti.getLiquidatedTrade();
- remainingQuantity = payDownTrade.getQuantity();
- System.out.println(fktName + "remainingQuantity: " + remainingQuantity);
- double weightedAverage = bocre.getAmount(1);
- System.out.println(fktName + "weightedAverage: " + weightedAverage);
- // LIQQuantity = Remaining_Quantity * CA_Amount
- double liqQuantity = remainingQuantity * caAmount;
- System.out.println(fktName + "liqQuantity: " + liqQuantity);
- bocre.addAttribute("LiquidatedQuantity", Double.toString(Math.abs(liqQuantity)));
- // LIQCost = Remaining_Quantity * CA_Amount * weightedAvgPrice
- double liquidatedCost = remainingQuantity * caAmount * redemptionPrice;
- System.out.println(fktName + "liquidatedCost: " + liquidatedCost);
- System.out.println(fktName + "liquidatedCost2: " + remainingQuantity * caAmount * (redemptionPrice / 100D));
- bocre.addAttribute("PrincipalCostLiquidated", String.valueOf(Math.abs(liquidatedCost)));
- // RealisedAmount = Remaining_Quantity * CA_Amount * [RedemptionPrice -weightedAvgPrice]
- if (payDownTrade != null && payDownTrade.getQuantity() < 0.0D) {
- // short position: calculation is ok on long position, so correct the short one here
- Product p = payDownTrade.getProduct();
- if (p != null) {
- if (p instanceof CA) {
- Bond b = (Bond) ((CA) p).getSecurity();
- System.out.println("liquidatedTrade.getNegociatedPrice() " + liquidatedTrade.getNegociatedPrice());
- System.out.println("b.getRedemptionPrice() " + b.getRedemptionPrice());
- System.out.println("liquidatedCost " + liquidatedCost);
- realisedAmount = (liquidatedTrade.getNegociatedPrice() - b.getRedemptionPrice()) * liquidatedCost;
- } else {
- System.out.println(fktName + "cannot calculate realisedAmount, unknown Product " + p.getId() + "/" + p.getType());
- }
- } else {
- System.out.println(fktName + "could not get product on trade " + lti.getLiquidatingTradeId());
- }
- }
- System.out.println("Amount = " + realisedAmount);
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- finally {
- ds.disconnect();
- }
- }
- private static LiquidationTradeInfo getLiquidatingAndLiquidatedTradeIds(Trade buyTrade, BOCre bocre){
- Trade sellTrade = null;
- int sellTradeId = bocre.getLinkedTradeId();
- int buyTradeId = buyTrade.getId();
- JDatetime buyTradeTradeDate = buyTrade.getTradeDate();
- LiquidationTradeInfo lti = new LiquidationTradeInfo();
- JDatetime sellTradeTradeDate = null;
- try{
- //TODO: pass down ds connection
- sellTrade = DSConnection.getDefault().getRemoteTrade().getTrade(sellTradeId);
- sellTradeTradeDate = sellTrade.getTradeDate();
- }
- catch(Exception e){
- System.out.println("getLiquidatingAndLiquidatedTradeIds: could not get linked(sell) Trade " + sellTradeId + " on trade (buy) " + buyTradeId);
- }
- if(sellTradeTradeDate != null && buyTradeTradeDate != null){
- if(sellTradeTradeDate.equals(buyTradeTradeDate))
- System.out.println("getLiquidatingAndLiquidatedTradeIds: CRE " + bocre.getId() + " could not determine liquidated and liquidating trade. SellTrade " +
- sellTrade.getId() + " Trade date " +
- sellTradeTradeDate + " Buy Trade: " + buyTrade.getId() + " Trade date " + buyTradeTradeDate);
- if(sellTradeTradeDate.after(buyTradeTradeDate)){
- lti.setLiquidatedTrade(buyTradeId);
- lti.setLiquidatingTrade(sellTradeId);
- lti.setIsBuy(sellTrade.getQuantity());
- } else {
- lti.setLiquidatedTrade(sellTradeId);
- lti.setLiquidatingTrade(buyTradeId);
- lti.setIsBuy(buyTrade.getQuantity());
- }
- }
- return lti;
- }
- }
Add Comment
Please, Sign In to add comment