Guest User

Untitled

a guest
Jun 12th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. package alproxy;
  2.  
  3. import com.calypso.tk.bo.BOCre;
  4. import com.calypso.tk.core.JDatetime;
  5. import com.calypso.tk.core.Product;
  6. import com.calypso.tk.core.Trade;
  7. import com.calypso.tk.product.Bond;
  8. import com.calypso.tk.product.CA;
  9. import com.calypso.tk.service.DSConnection;
  10. import com.calypso.tk.util.ConnectionUtil;
  11. import com.rbos.cmpp.translations.TranslateHelper;
  12. import com.rbos.cmpp.util.Formatter;
  13. import com.rbos.cmpp.util.LiquidationTradeInfo;
  14. import com.rbos.cmpp.util.NonStaticFormatter;
  15.  
  16. public class PayDownCreTest {
  17. private static final String user = "calypso_user";
  18. private static final String password = "calypso";
  19. private static final String appname = "test";
  20. private static final String env = "UAT1";
  21.  
  22. public static void main(String[] args) throws Exception {
  23. DSConnection ds = null;
  24. try {
  25. ds = ConnectionUtil.connect(user, password, appname, env);
  26.  
  27. BOCre bocre = ds.getRemoteBO().getBOCre(69758561);
  28.  
  29.  
  30. LiquidationTradeInfo lti = getLiquidatingAndLiquidatedTradeIds(
  31. ds.getRemoteTrade().getTrade(bocre.getTradeId()), bocre);
  32.  
  33. String fktName = "setupSpecific: ";
  34. double remainingQuantity = 0.0d;
  35. double caAmount = bocre.getAmount(4);
  36. double redemptionPrice = bocre.getAmount(3);
  37. double realisedAmount = bocre.getAmount(0);
  38.  
  39. Trade payDownTrade = lti.getLiquidatingTrade();
  40. Trade liquidatedTrade = lti.getLiquidatedTrade();
  41.  
  42.  
  43. remainingQuantity = payDownTrade.getQuantity();
  44. System.out.println(fktName + "remainingQuantity: " + remainingQuantity);
  45. double weightedAverage = bocre.getAmount(1);
  46. System.out.println(fktName + "weightedAverage: " + weightedAverage);
  47. // LIQQuantity = Remaining_Quantity * CA_Amount
  48. double liqQuantity = remainingQuantity * caAmount;
  49. System.out.println(fktName + "liqQuantity: " + liqQuantity);
  50. bocre.addAttribute("LiquidatedQuantity", Double.toString(Math.abs(liqQuantity)));
  51. // LIQCost = Remaining_Quantity * CA_Amount * weightedAvgPrice
  52. double liquidatedCost = remainingQuantity * caAmount * redemptionPrice;
  53. System.out.println(fktName + "liquidatedCost: " + liquidatedCost);
  54. System.out.println(fktName + "liquidatedCost2: " + remainingQuantity * caAmount * (redemptionPrice / 100D));
  55. bocre.addAttribute("PrincipalCostLiquidated", String.valueOf(Math.abs(liquidatedCost)));
  56.  
  57. // RealisedAmount = Remaining_Quantity * CA_Amount * [RedemptionPrice -weightedAvgPrice]
  58. if (payDownTrade != null && payDownTrade.getQuantity() < 0.0D) {
  59. // short position: calculation is ok on long position, so correct the short one here
  60. Product p = payDownTrade.getProduct();
  61. if (p != null) {
  62. if (p instanceof CA) {
  63. Bond b = (Bond) ((CA) p).getSecurity();
  64. System.out.println("liquidatedTrade.getNegociatedPrice() " + liquidatedTrade.getNegociatedPrice());
  65. System.out.println("b.getRedemptionPrice() " + b.getRedemptionPrice());
  66. System.out.println("liquidatedCost " + liquidatedCost);
  67. realisedAmount = (liquidatedTrade.getNegociatedPrice() - b.getRedemptionPrice()) * liquidatedCost;
  68. } else {
  69. System.out.println(fktName + "cannot calculate realisedAmount, unknown Product " + p.getId() + "/" + p.getType());
  70. }
  71. } else {
  72. System.out.println(fktName + "could not get product on trade " + lti.getLiquidatingTradeId());
  73. }
  74. }
  75.  
  76. System.out.println("Amount = " + realisedAmount);
  77.  
  78. }
  79. catch(Exception e)
  80. {
  81. System.out.println(e);
  82. }
  83. finally {
  84. ds.disconnect();
  85. }
  86. }
  87.  
  88. private static LiquidationTradeInfo getLiquidatingAndLiquidatedTradeIds(Trade buyTrade, BOCre bocre){
  89. Trade sellTrade = null;
  90. int sellTradeId = bocre.getLinkedTradeId();
  91. int buyTradeId = buyTrade.getId();
  92. JDatetime buyTradeTradeDate = buyTrade.getTradeDate();
  93. LiquidationTradeInfo lti = new LiquidationTradeInfo();
  94. JDatetime sellTradeTradeDate = null;
  95. try{
  96. //TODO: pass down ds connection
  97. sellTrade = DSConnection.getDefault().getRemoteTrade().getTrade(sellTradeId);
  98. sellTradeTradeDate = sellTrade.getTradeDate();
  99. }
  100. catch(Exception e){
  101. System.out.println("getLiquidatingAndLiquidatedTradeIds: could not get linked(sell) Trade " + sellTradeId + " on trade (buy) " + buyTradeId);
  102. }
  103. if(sellTradeTradeDate != null && buyTradeTradeDate != null){
  104. if(sellTradeTradeDate.equals(buyTradeTradeDate))
  105. System.out.println("getLiquidatingAndLiquidatedTradeIds: CRE " + bocre.getId() + " could not determine liquidated and liquidating trade. SellTrade " +
  106. sellTrade.getId() + " Trade date " +
  107. sellTradeTradeDate + " Buy Trade: " + buyTrade.getId() + " Trade date " + buyTradeTradeDate);
  108. if(sellTradeTradeDate.after(buyTradeTradeDate)){
  109. lti.setLiquidatedTrade(buyTradeId);
  110. lti.setLiquidatingTrade(sellTradeId);
  111. lti.setIsBuy(sellTrade.getQuantity());
  112. } else {
  113. lti.setLiquidatedTrade(sellTradeId);
  114. lti.setLiquidatingTrade(buyTradeId);
  115. lti.setIsBuy(buyTrade.getQuantity());
  116. }
  117. }
  118. return lti;
  119. }
  120. }
Add Comment
Please, Sign In to add comment