FormulasBonoCE.vb 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. Public Class FormulasBonoCE
  2. Dim ElementosConsulta As New CargarElementosDAO
  3. Dim V_CodEmpr = ElementosConsulta.CodEmpr
  4. 'Dim V_CodIF = ElementosConsulta.CodIF
  5. Dim V_CodEmis = ElementosConsulta.CodEmis
  6. Dim V_CodECalRi = ElementosConsulta.CodECalRi
  7. Dim V_CodPais = ElementosConsulta.CodPais
  8. Dim V_ListaPlazo = ElementosConsulta.ListaPlazosFactor
  9. Dim V_ListaTiposMercados = ElementosConsulta.ListaTiposMercado
  10. Dim V_ListaPeriodos = ElementosConsulta.ListaPeriodos
  11. Dim V_ListaTipoTasa = ElementosConsulta.ListaTipoTasa
  12. Dim V_ListaTipoRenta = ElementosConsulta.ListaTipoRenta
  13. Dim V_ListaEstado = ElementosConsulta.ListaEstado
  14. Dim Operaciones As New Operaciones
  15. Dim V_ListaCasasCorredoras = ElementosConsulta.ListaCasasCorredoras
  16. Public ReadOnly Property ListaCasasCorredoras
  17. Get
  18. Return V_ListaCasasCorredoras
  19. End Get
  20. End Property
  21. Public ReadOnly Property ListaEstado
  22. Get
  23. Return V_ListaEstado
  24. End Get
  25. End Property
  26. Public ReadOnly Property ListaTipoRenta
  27. Get
  28. Return V_ListaTipoRenta
  29. End Get
  30. End Property
  31. Public ReadOnly Property ListaTipoTasa
  32. Get
  33. Return V_ListaTipoTasa
  34. End Get
  35. End Property
  36. Public ReadOnly Property ListaPeriodos
  37. Get
  38. Return V_ListaPeriodos
  39. End Get
  40. End Property
  41. Public ReadOnly Property CodPais
  42. Get
  43. Return V_CodPais
  44. End Get
  45. End Property
  46. Public ReadOnly Property CodEmpr
  47. Get
  48. Return V_CodEmpr
  49. End Get
  50. End Property
  51. Public ReadOnly Property ListaTiposMercados
  52. Get
  53. Return V_ListaTiposMercados
  54. End Get
  55. End Property
  56. Public ReadOnly Property ListaPlazo
  57. Get
  58. Return V_ListaPlazo
  59. End Get
  60. End Property
  61. Public ReadOnly Property CodEmis
  62. Get
  63. Return V_CodEmis
  64. End Get
  65. End Property
  66. Public ReadOnly Property CodECalRi
  67. Get
  68. Return V_CodECalRi
  69. End Get
  70. End Property
  71. Public Function DiasVencimiento(ByVal fecha1 As DateTime, ByVal fecha2 As DateTime, ByVal Base As Integer)
  72. fecha1 = Format(fecha1, "dd/MM/yyyy")
  73. fecha2 = Format(fecha2, "dd/MM/yyyy")
  74. Dim Total As Integer
  75. If (Base = 0 Or Base = 2) Then
  76. Total = Base360(fecha1, fecha2)
  77. ElseIf (Base = 1 Or Base = 3) Then
  78. Total = Base365(fecha1, fecha2)
  79. Else
  80. Total = 0
  81. End If
  82. Return Total
  83. End Function
  84. Public Function DiasAcumulados(ByVal fecha1 As DateTime, ByVal fecha2 As DateTime, ByVal Base As Integer)
  85. Dim Total As Integer
  86. If (Base = 0 Or Base = 2) Then
  87. Total = Base360(fecha1, fecha2)
  88. ElseIf (Base = 1 Or Base = 3) Then
  89. Total = Base365(fecha1, fecha2)
  90. Else
  91. Total = 0
  92. End If
  93. Return Total
  94. End Function
  95. 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)
  96. Dim Valor As Double = 0
  97. If (IndexBase = 0) Then
  98. Valor = ValorNominal * Cupon * DiasAcumulados / 360
  99. Return Valor
  100. ElseIf (IndexBase = 1) Then
  101. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  102. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  103. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha366Varios(Fecha1, Fecha2)
  104. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha365Varios(Fecha1, Fecha2)
  105. If (DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  106. PrOpc1 = ValorNominal * Cupon * DiasPrimeraFecha / 366
  107. PrOpc2 = ValorNominal * Cupon * DiasSegundaFecha / 365
  108. Valor = PrOpc1 + PrOpc2
  109. ElseIf (Not DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  110. Valor = ValorNominal * Cupon * DiasSegundaFecha / 365
  111. ElseIf (DiasPrimeraFecha > 0 And Not DiasSegundaFecha > 0) Then
  112. Valor = ValorNominal * Cupon * DiasPrimeraFecha / 366
  113. Else
  114. Valor = 0
  115. End If
  116. Return Valor
  117. ElseIf (IndexBase = 2) Then
  118. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  119. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  120. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha360Bi(Fecha1, Fecha2)
  121. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha360(Fecha1, Fecha2)
  122. If (DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  123. PrOpc1 = ValorNominal * Cupon * DiasPrimeraFecha / 366
  124. PrOpc2 = ValorNominal * Cupon * DiasSegundaFecha / 365
  125. Valor = PrOpc1 + PrOpc2
  126. ElseIf (Not DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  127. Valor = ValorNominal * Cupon * DiasSegundaFecha / 365
  128. ElseIf (DiasPrimeraFecha > 0 And Not DiasSegundaFecha > 0) Then
  129. Valor = ValorNominal * Cupon * DiasPrimeraFecha / 366
  130. Else
  131. Valor = 0
  132. End If
  133. Return Valor
  134. Else
  135. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  136. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  137. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha366Varios(Fecha1, Fecha2)
  138. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha365Varios(Fecha1, Fecha2)
  139. If (DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  140. PrOpc1 = ValorNominal * Cupon * DiasPrimeraFecha / 360
  141. PrOpc2 = ValorNominal * Cupon * DiasSegundaFecha / 360
  142. Valor = PrOpc1 + PrOpc2
  143. ElseIf (Not DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  144. Valor = ValorNominal * Cupon * DiasSegundaFecha / 360
  145. ElseIf (DiasPrimeraFecha > 0 And Not DiasSegundaFecha > 0) Then
  146. Valor = ValorNominal * Cupon * DiasPrimeraFecha / 360
  147. Else
  148. Valor = 0
  149. End If
  150. Return Valor
  151. End If
  152. End Function
  153. Public Function InteresAcumuladoPor(ByVal InteresAcumulado As Double, ByVal ValorNominal As Double, ByVal Periodicidad As Double, ByVal IndexBase As Integer)
  154. Dim Valor As Double = 0
  155. If (IndexBase = 0 Or IndexBase = 2) Then
  156. Valor = ((InteresAcumulado / ValorNominal) * 360) / (Periodicidad * 30)
  157. Return Valor
  158. ElseIf (IndexBase = 1 Or IndexBase = 3) Then
  159. Valor = ((InteresAcumulado / ValorNominal) * 365) / (Periodicidad * 30)
  160. Return Valor
  161. End If
  162. Return Valor
  163. End Function
  164. Public Function PrecioSucio(ByVal PrecioCompra As Double, ByVal InteresAcumulado As Double)
  165. Dim Proceso = (PrecioCompra * 0.01 + InteresAcumulado) * 100
  166. Return Proceso
  167. End Function
  168. Public Function ValorTrasado(ByVal PrecioCompra As Double, ByVal ValorNominal As Double)
  169. Dim Proceso = (PrecioCompra / 100) * ValorNominal
  170. Return Proceso
  171. End Function
  172. Public Function Comisiones(ByVal Comision As Double, ByVal ValorTrasado As Double)
  173. Dim Valor = CDec(Comision) * CDec(ValorTrasado)
  174. Return Valor / 100
  175. End Function
  176. Public Function MontoPagar(ByVal ValorTrasado As Double, ByVal ComisionBolsa As Double, ByVal ComisionCasa As Double, ByVal InteresAcumulado As Double, ByVal CostoTransferencias As Double)
  177. Dim Valor = ValorTrasado + ComisionBolsa + ComisionCasa + InteresAcumulado + CostoTransferencias
  178. Return Valor
  179. End Function
  180. Public Function MontoRecibir(ByVal ValorTrasado As Double, ByVal ComisionBolsa As Double, ByVal ComisionCasa As Double, ByVal InteresAcumulado As Double)
  181. Dim Valor = ValorTrasado - ComisionBolsa - ComisionCasa + InteresAcumulado
  182. Return Valor
  183. End Function
  184. Public Function MontoRecibir(ByVal ValorTrasado As Double, ByVal ComisionBolsa As Double, ByVal ComisionCasa As Double, ByVal InteresAcumulado As Double, ByVal InteresGenerado As Double)
  185. Dim Valor = ValorTrasado - ComisionBolsa - ComisionCasa + InteresAcumulado + InteresGenerado
  186. Return Valor
  187. End Function
  188. Public Function Base360(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
  189. Dim dia As Integer
  190. Dim dias31 As Integer
  191. Dim febreros As Integer
  192. Dim bisiesto As Integer
  193. While (Fecha1 < Fecha2)
  194. dia = dia + 1
  195. If (Fecha1.Day = 31) Then
  196. dias31 = dias31 + 1
  197. End If
  198. If (Fecha1.Month = 2 And Fecha1.Day = 28) Then
  199. febreros = febreros + 2
  200. End If
  201. If (Fecha1.Month = 2 And Fecha1.Day = 29) Then
  202. bisiesto = bisiesto + 1
  203. End If
  204. Fecha1 = Fecha1.AddDays(1)
  205. End While
  206. Dim Total = dia - dias31 + febreros - bisiesto
  207. Return Total
  208. End Function
  209. Public Function Base365(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
  210. Dim dias = DateDiff(DateInterval.Day, Fecha1, Fecha2)
  211. Return dias
  212. End Function
  213. End Class