FormulasBonoCE.vb 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. Public Class FormulasBonoCE
  2. Dim ElementosConsulta As New CargarElementosDAO
  3. Dim V_CodEmpr = ElementosConsulta.CodEmpr
  4. Dim V_CodEmis = ElementosConsulta.CodEmis
  5. Dim V_CodECalRi = ElementosConsulta.CodECalRi
  6. Dim V_CodPais = ElementosConsulta.CodPais
  7. Dim V_ListaPlazo = ElementosConsulta.ListaPlazosFactor
  8. Dim V_ListaTiposMercados = ElementosConsulta.ListaTiposMercado
  9. Dim V_ListaPeriodos = ElementosConsulta.ListaPeriodos
  10. Dim V_ListaTipoTasa = ElementosConsulta.ListaTipoTasa
  11. Dim V_ListaTipoRenta = ElementosConsulta.ListaTipoRenta
  12. Dim V_ListaEstado = ElementosConsulta.ListaEstado
  13. Dim Operaciones As New Operaciones
  14. Dim V_ListaCasasCorredoras = ElementosConsulta.ListaCasasCorredoras
  15. Public Function DiasVencimiento(ByVal fecha1 As DateTime, ByVal fecha2 As DateTime, ByVal Base As Integer)
  16. fecha1 = Format(fecha1, "dd/MM/yyyy")
  17. fecha2 = Format(fecha2, "dd/MM/yyyy")
  18. Dim Total As Integer
  19. If (Base = 0 Or Base = 2) Then
  20. Total = Base360(fecha1, fecha2)
  21. ElseIf (Base = 1 Or Base = 3) Then
  22. Total = Base365(fecha1, fecha2)
  23. Else
  24. Total = 0
  25. End If
  26. Return Total
  27. End Function
  28. Public Function InteresAcumulado(ByVal ValorNominal As Double, ByVal Cupon As Double, ByVal Fecha1 As Date, ByVal Fecha2 As Date, ByVal DiasAcumulados As Double, ByVal IndexBase As Integer)
  29. Dim Valor As Double = 0
  30. If (IndexBase = 0) Then
  31. Valor = ValorNominal * Cupon * DiasAcumulados / 360
  32. Return Valor
  33. ElseIf (IndexBase = 1) Then
  34. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  35. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  36. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha366Varios(Fecha1, Fecha2)
  37. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha365Varios(Fecha1, Fecha2)
  38. If (DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  39. PrOpc1 = ValorNominal * Cupon * DiasPrimeraFecha / 366
  40. PrOpc2 = ValorNominal * Cupon * DiasSegundaFecha / 365
  41. Valor = PrOpc1 + PrOpc2
  42. ElseIf (Not DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  43. Valor = ValorNominal * Cupon * DiasSegundaFecha / 365
  44. ElseIf (DiasPrimeraFecha > 0 And Not DiasSegundaFecha > 0) Then
  45. Valor = ValorNominal * Cupon * DiasPrimeraFecha / 366
  46. Else
  47. Valor = 0
  48. End If
  49. Return Valor
  50. ElseIf (IndexBase = 2) Then
  51. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  52. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  53. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha360Bi(Fecha1, Fecha2)
  54. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha360(Fecha1, Fecha2)
  55. If (DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  56. PrOpc1 = ValorNominal * Cupon * DiasPrimeraFecha / 366
  57. PrOpc2 = ValorNominal * Cupon * DiasSegundaFecha / 365
  58. Valor = PrOpc1 + PrOpc2
  59. ElseIf (Not DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  60. Valor = ValorNominal * Cupon * DiasSegundaFecha / 365
  61. ElseIf (DiasPrimeraFecha > 0 And Not DiasSegundaFecha > 0) Then
  62. Valor = ValorNominal * Cupon * DiasPrimeraFecha / 366
  63. Else
  64. Valor = 0
  65. End If
  66. Return Valor
  67. Else
  68. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  69. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  70. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha366Varios(Fecha1, Fecha2)
  71. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha365Varios(Fecha1, Fecha2)
  72. If (DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  73. PrOpc1 = ValorNominal * Cupon * DiasPrimeraFecha / 360
  74. PrOpc2 = ValorNominal * Cupon * DiasSegundaFecha / 360
  75. Valor = PrOpc1 + PrOpc2
  76. ElseIf (Not DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  77. Valor = ValorNominal * Cupon * DiasSegundaFecha / 360
  78. ElseIf (DiasPrimeraFecha > 0 And Not DiasSegundaFecha > 0) Then
  79. Valor = ValorNominal * Cupon * DiasPrimeraFecha / 360
  80. Else
  81. Valor = 0
  82. End If
  83. Return Valor
  84. End If
  85. End Function
  86. Public Function InteresAcumuladoPor(ByVal InteresAcumulado As Double, ByVal ValorNominal As Double, ByVal Periodicidad As Double, ByVal IndexBase As Integer)
  87. Dim Valor As Double = 0
  88. If (IndexBase = 0 Or IndexBase = 2) Then
  89. Valor = ((InteresAcumulado / ValorNominal) * 360) / (Periodicidad * 30)
  90. Return Valor
  91. ElseIf (IndexBase = 1 Or IndexBase = 3) Then
  92. Valor = ((InteresAcumulado / ValorNominal) * 365) / (Periodicidad * 30)
  93. Return Valor
  94. End If
  95. Return Valor
  96. End Function
  97. Public Function PrecioSucio(ByVal PrecioCompra As Double, ByVal InteresAcumulado As Double)
  98. Dim Proceso = (PrecioCompra * 0.01 + InteresAcumulado) * 100
  99. Return Proceso
  100. End Function
  101. Public Function ValorTrasado(ByVal PrecioCompra As Double, ByVal ValorNominal As Double)
  102. Dim Proceso = (PrecioCompra / 100) * ValorNominal
  103. Return Proceso
  104. End Function
  105. Public Function MontoPagar(ByVal ValorTrasado As Double, ByVal ComisionBolsa As Double, ByVal ComisionCasa As Double, ByVal InteresAcumulado As Double, ByVal CostoTransferencias As Double)
  106. Dim Valor = ValorTrasado + ComisionBolsa + ComisionCasa + InteresAcumulado + CostoTransferencias
  107. Return Valor
  108. End Function
  109. Public Function MontoRecibir(ByVal ValorTrasado As Double, ByVal ComisionBolsa As Double, ByVal ComisionCasa As Double, ByVal InteresAcumulado As Double)
  110. Dim Valor = ValorTrasado - ComisionBolsa - ComisionCasa + InteresAcumulado
  111. Return Valor
  112. End Function
  113. Public Function Base360(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
  114. Dim dia As Integer
  115. Dim dias31 As Integer
  116. Dim febreros As Integer
  117. Dim bisiesto As Integer
  118. While (Fecha1 < Fecha2)
  119. dia = dia + 1
  120. If (Fecha1.Day = 31) Then
  121. dias31 = dias31 + 1
  122. End If
  123. If (Fecha1.Month = 2 And Fecha1.Day = 28) Then
  124. febreros = febreros + 2
  125. End If
  126. If (Fecha1.Month = 2 And Fecha1.Day = 29) Then
  127. bisiesto = bisiesto + 1
  128. End If
  129. Fecha1 = Fecha1.AddDays(1)
  130. End While
  131. Dim Total = dia - dias31 + febreros - bisiesto
  132. Return Total
  133. End Function
  134. Public Function Base365(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
  135. Dim dias = DateDiff(DateInterval.Day, Fecha1, Fecha2)
  136. Return dias
  137. End Function
  138. End Class