BonosCE.vb 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. Public Class BonosCE
  2. Private _CodigoInversion As String
  3. Private _DocumentoBase As String
  4. Private _TipoBase As String
  5. Private _CodigoEmpresa As String
  6. Private _CodigoInstrumentoFinanciero As String = "BONO"
  7. Private _DescripcionInstrumentoFinanciero As String = "Bonos"
  8. Private _dtImpuestosYComisiones As DataTable
  9. Private _SumaImpuestosYComisionesVenta As Double
  10. Private _dtIngresos As DataTable
  11. Private _SumaIngresos As Double
  12. Private _SumaImpuestosIngresos As Double
  13. Private _SumaliquidoIngresos As Double
  14. Private Operaciones As New Operaciones
  15. Public Overridable ReadOnly Property CodigoInstrumentoFinanciero As String
  16. Get
  17. Return _CodigoInstrumentoFinanciero
  18. End Get
  19. End Property
  20. Public Overridable ReadOnly Property DescripcionInstrumentoFinanciero
  21. Get
  22. Return _DescripcionInstrumentoFinanciero
  23. End Get
  24. End Property
  25. Public Property Ingresos As DataTable
  26. Get
  27. Return _dtIngresos
  28. End Get
  29. Set(value As DataTable)
  30. _dtIngresos = value
  31. End Set
  32. End Property
  33. Private _PeriodicidadCompra As String
  34. Private _ValorNominalCompra As Double
  35. Private _UltimaFechaCuponCompra As Date
  36. Private _SiguienteFechaCuponCompra As Date
  37. Private _FechaLiquidacionCompra As Date
  38. Private _FechaVencimientoCompra As Date
  39. Private _PorcentajeCuponCompra As Double
  40. Private _YTMAlVencimientoComisionCompra As Double
  41. Private _YTMAlVencimientoCompra As Double
  42. Private _PrecioAlVencimientoCompra As Double
  43. Private _PrecioCompra As Double
  44. Private _DiasBaseCompra As Integer
  45. Private _DiasAcumuladosCompra As Integer
  46. Private _DiasAlVencimientoCompra As Integer
  47. Private _PorcentajeInteresAcumuladoCompra As Double
  48. Private _InteresAcumuladoCompra As Double
  49. Private _PrecioSucioCompra As Double
  50. Private _ValorTransadoCompra As Double
  51. Private _MontoAPagarCompra As Double
  52. Private _CostoDeTransferenciaCompra As Double
  53. Private _SumaImpuestosyComisionesCompra As Double
  54. Private _ValorNominalVenta As Double
  55. Private _UltimaFechaCuponVenta As Date
  56. Private _SiguienteFechaCuponVenta As Date
  57. Private _FechaLiquidacionVenta As Date
  58. Private _FechaVencimientoVenta As Date
  59. Private _PorcentajeCuponVenta As Double
  60. Private _YTMAlVencimientoComisionVenta As Double
  61. Private _YTMAlVencimientoVenta As Double
  62. Private _PrecioAlVencimientoVenta As Double
  63. Private _PrecioVenta As Double
  64. Private _DiasBaseVenta As Integer
  65. Private _DiasAcumuladosVenta As Integer
  66. Private _DiasAlVencimientoVenta As Integer
  67. Private _InteresAcumuladoVenta As Double
  68. Private _InteresAcumuladoPorcentajeVenta As Double
  69. Private _PrecioSucioVenta As Double
  70. Private _ValorTransadoVenta As Double
  71. Private _MontoARecibirVenta As Double
  72. Private _PeriodicidadVenta As String
  73. Private _PorcentajeComisionCasaVenta As Double
  74. Private _PorcentajeComisionBolsaVenta As Double
  75. Private _CostoDeTransferenciaVenta As Double
  76. Private _ComisionBolsaVenta As Double
  77. Private _ComisionCasaVenta As Double
  78. Private _ValorNominalRO As Double
  79. Private _DiasPlazoRO As Integer
  80. Private _PrecioCompraRO As Double
  81. Private _PrecioVentaRO As Double
  82. Private _GananciaPerdidaDeCapital As Double
  83. Private _IngresoPorInteres As Double
  84. Private _CostosTotales As Double
  85. Private _GananciaPerdidaTotal As Double
  86. Private _RendimientoGananciaPerdida As Double
  87. Private _RendimientoDeIntereses As Double
  88. Private _RendimientoAntesImpuestos As Double
  89. Private _RendimientoDespuesImpuestos As Double
  90. Public Property ImpuestosYComisiones As DataTable
  91. Get
  92. Return _dtImpuestosYComisiones
  93. End Get
  94. Set(value As DataTable)
  95. _dtImpuestosYComisiones = value
  96. CalcularSumaImpuestosyComisiones()
  97. End Set
  98. End Property
  99. 'COMPRA
  100. Public Property PeriodicidadCompra As String
  101. Get
  102. Return _PeriodicidadCompra
  103. End Get
  104. Set(value As String)
  105. _PeriodicidadCompra = value
  106. End Set
  107. End Property
  108. Public Property ValorNominalCompra As Double
  109. Get
  110. Return _ValorNominalCompra
  111. End Get
  112. Set(value As Double)
  113. _ValorNominalCompra = value
  114. CalcularInteresAcumuladoCompra()
  115. CalcularPorcentajeInteresAcumuladoCompra()
  116. CalcularValorTransadoCompra()
  117. End Set
  118. End Property
  119. Public Property UltimaFechaCuponCompra As Date
  120. Get
  121. Return _UltimaFechaCuponCompra
  122. End Get
  123. Set(value As Date)
  124. _UltimaFechaCuponCompra = value
  125. CalcularDiasAcumuladosCompra()
  126. End Set
  127. End Property
  128. Public Property SiguienteFechaCuponCompra As Date
  129. Get
  130. Return _SiguienteFechaCuponCompra
  131. End Get
  132. Set(value As Date)
  133. _SiguienteFechaCuponCompra = value
  134. CalcularDiasAcumuladosCompra()
  135. CalcularUltimaFechaCuponVenta()
  136. 'CalcularTablaIngresos()
  137. End Set
  138. End Property
  139. Public Property FechaLiquidacionCompra As Date
  140. Get
  141. Return _FechaLiquidacionCompra
  142. End Get
  143. Set(value As Date)
  144. _FechaLiquidacionCompra = value
  145. CalcularYTMAlVencimientoCompra()
  146. CalcularDiasAcumuladosCompra()
  147. CalcularDiasPlazoRO()
  148. End Set
  149. End Property
  150. Public Property FechaVencimientoCompra As Date
  151. Get
  152. Return _FechaVencimientoCompra
  153. End Get
  154. Set(value As Date)
  155. _FechaVencimientoCompra = value
  156. CalcularYTMAlVencimientoCompra()
  157. End Set
  158. End Property
  159. Public Property PorcentajeCuponCompra As Double
  160. Get
  161. Return _PorcentajeCuponCompra
  162. End Get
  163. Set(value As Double)
  164. _PorcentajeCuponCompra = value
  165. CalcularYTMAlVencimientoCompra()
  166. CalcularInteresAcumuladoCompra()
  167. End Set
  168. End Property
  169. Public ReadOnly Property YTMAlVencimientoComisionCompra As Double
  170. Get
  171. Return _YTMAlVencimientoComisionCompra
  172. End Get
  173. End Property
  174. Public ReadOnly Property YTMAlVencimientoCompra As Double
  175. Get
  176. Return _YTMAlVencimientoCompra
  177. End Get
  178. End Property
  179. Public Property PrecioAlVencimientoCompra As Double
  180. Get
  181. Return _PrecioAlVencimientoCompra
  182. End Get
  183. Set(value As Double)
  184. _PrecioAlVencimientoCompra = value
  185. CalcularYTMAlVencimientoCompra()
  186. End Set
  187. End Property
  188. Public Property PrecioCompra As Double
  189. Get
  190. Return _PrecioCompra
  191. End Get
  192. Set(value As Double)
  193. _PrecioCompra = value
  194. CalcularYTMAlVencimientoCompra()
  195. CalcularPrecioSucioCompra()
  196. CalcularValorTransadoCompra()
  197. End Set
  198. End Property
  199. Public Property DiasBaseCompra As Integer
  200. Get
  201. Return _DiasBaseCompra
  202. End Get
  203. Set(value As Integer)
  204. _DiasBaseCompra = value
  205. CalcularInteresAcumuladoCompra()
  206. CalcularDiasAlVencimientoCompra()
  207. CalcularDiasAcumuladosCompra()
  208. CalcularYTMAlVencimientoComisionCompra()
  209. CalcularPorcentajeInteresAcumuladoCompra()
  210. CalcularDiasPlazoRO()
  211. CalcularRendimientoGananciaPerdida()
  212. CalcularRendimientoDeIntereses()
  213. CalcularRendimientoDespuesImpuestos()
  214. End Set
  215. End Property
  216. Public ReadOnly Property DiasAcumuladosCompra As Integer
  217. Get
  218. Return _DiasAcumuladosCompra
  219. End Get
  220. End Property
  221. Public ReadOnly Property DiasAlVencimientoCompra As Integer
  222. Get
  223. Return _DiasAlVencimientoCompra
  224. End Get
  225. End Property
  226. Public ReadOnly Property PorcentajeInteresAcumuladoCompra As Double
  227. Get
  228. Return _PorcentajeInteresAcumuladoCompra
  229. End Get
  230. End Property
  231. Public ReadOnly Property InteresAcumuladoCompra As Double
  232. Get
  233. Return _InteresAcumuladoCompra
  234. End Get
  235. End Property
  236. Public ReadOnly Property PrecioSucioCompra As Double
  237. Get
  238. Return _PrecioSucioCompra
  239. End Get
  240. End Property
  241. Public ReadOnly Property ValorTransadoCompra As Double
  242. Get
  243. Return _ValorTransadoCompra
  244. End Get
  245. End Property
  246. Public ReadOnly Property MontoAPagarCompra As Double
  247. Get
  248. Return _MontoAPagarCompra
  249. End Get
  250. End Property
  251. Public Property CostoDeTransferenciaCompra As Double
  252. Get
  253. Return _CostoDeTransferenciaCompra
  254. End Get
  255. Set(value As Double)
  256. _CostoDeTransferenciaCompra = value
  257. CalcularMontoAPagarCompra()
  258. End Set
  259. End Property
  260. 'VENTA
  261. Public Property ValorNominalVenta As Double
  262. Get
  263. Return _ValorNominalVenta
  264. End Get
  265. Set(value As Double)
  266. _ValorNominalVenta = value
  267. CalcularInteresAcumuladoVenta()
  268. CalcularInteresAcumuladoPorcentajeVenta()
  269. CalcularValorTransadoVenta()
  270. CalcularInteresAcumuladoPorcentajeVenta()
  271. End Set
  272. End Property
  273. Public Property UltimaFechaCuponVenta As Date
  274. Get
  275. Return _UltimaFechaCuponVenta
  276. End Get
  277. Set(value As Date)
  278. _UltimaFechaCuponVenta = value
  279. End Set
  280. End Property
  281. Public Property SiguienteFechaCuponVenta As Date
  282. Get
  283. Return _SiguienteFechaCuponVenta
  284. End Get
  285. Set(value As Date)
  286. _SiguienteFechaCuponVenta = value
  287. End Set
  288. End Property
  289. Public Property FechaLiquidacionVenta As Date
  290. Get
  291. Return _FechaLiquidacionVenta
  292. End Get
  293. Set(value As Date)
  294. _FechaLiquidacionVenta = value
  295. CalcularDiasAcumuladosVenta()
  296. CalcularDiasAlVencimientoVenta()
  297. CalcularYTMAlVencimientoVenta()
  298. CalcularDiasPlazoRO()
  299. End Set
  300. End Property
  301. Public Property FechaVencimientoVenta As Date
  302. Get
  303. Return _FechaVencimientoVenta
  304. End Get
  305. Set(value As Date)
  306. _FechaVencimientoVenta = value
  307. CalcularDiasAlVencimientoVenta()
  308. CalcularYTMAlVencimientoVenta()
  309. End Set
  310. End Property
  311. Public Property PorcentajeCuponVenta As Double
  312. Get
  313. Return _PorcentajeCuponVenta
  314. End Get
  315. Set(value As Double)
  316. _PorcentajeCuponVenta = value
  317. CalcularYTMAlVencimientoVenta()
  318. CalcularInteresAcumuladoVenta()
  319. CalcularInteresAcumuladoPorcentajeVenta()
  320. End Set
  321. End Property
  322. Public ReadOnly Property YTMAlVencimientoComisionVenta As Double
  323. Get
  324. Return _YTMAlVencimientoComisionVenta
  325. End Get
  326. End Property
  327. Public ReadOnly Property YTMAlVencimientoVenta As Double
  328. Get
  329. Return _YTMAlVencimientoVenta
  330. End Get
  331. End Property
  332. Public Property PrecioAlVencimientoVenta As Double
  333. Get
  334. Return _PrecioAlVencimientoVenta
  335. End Get
  336. Set(value As Double)
  337. _PrecioAlVencimientoVenta = value
  338. CalcularYTMAlVencimientoVenta()
  339. End Set
  340. End Property
  341. Public Property PrecioVenta As Double
  342. Get
  343. Return _PrecioVenta
  344. End Get
  345. Set(value As Double)
  346. _PrecioVenta = value
  347. CalcularYTMAlVencimientoVenta()
  348. CalcularPrecioSucioVenta()
  349. CalcularValorTransadoVenta()
  350. End Set
  351. End Property
  352. Public Property DiasBaseVenta As Integer
  353. Get
  354. Return _DiasBaseVenta
  355. End Get
  356. Set(value As Integer)
  357. _DiasBaseVenta = value
  358. CalcularYTMAlVencimientoComisionVenta()
  359. CalcularDiasAcumuladosVenta()
  360. CalcularDiasAlVencimientoVenta()
  361. CalcularInteresAcumuladoVenta()
  362. CalcularInteresAcumuladoPorcentajeVenta()
  363. CalcularInteresAcumuladoPorcentajeVenta()
  364. End Set
  365. End Property
  366. Public ReadOnly Property DiasAcumuladosVenta As Integer
  367. Get
  368. Return _DiasAcumuladosVenta
  369. End Get
  370. End Property
  371. Public ReadOnly Property DiasAlVencimientoVenta As Integer
  372. Get
  373. Return _DiasAlVencimientoVenta
  374. End Get
  375. End Property
  376. Public ReadOnly Property InteresAcumuladoVenta As Double
  377. Get
  378. Return _InteresAcumuladoVenta
  379. End Get
  380. End Property
  381. Public ReadOnly Property InteresAcumuladoPorcentajeVenta As Double
  382. Get
  383. Return _InteresAcumuladoPorcentajeVenta
  384. End Get
  385. End Property
  386. Public ReadOnly Property PrecioSucioVenta As Double
  387. Get
  388. Return _PrecioSucioVenta
  389. End Get
  390. End Property
  391. Public ReadOnly Property ValorTransadoVenta As Double
  392. Get
  393. Return _ValorTransadoVenta
  394. End Get
  395. End Property
  396. Public ReadOnly Property MontoARecibirVenta As Double
  397. Get
  398. Return _MontoARecibirVenta
  399. End Get
  400. End Property
  401. Public Property CostoDeTransferenciaVenta As Double
  402. Get
  403. Return _CostoDeTransferenciaVenta
  404. End Get
  405. Set(value As Double)
  406. _CostoDeTransferenciaVenta = value
  407. End Set
  408. End Property
  409. Public ReadOnly Property ValorNominalRO As Double
  410. Get
  411. Return _ValorNominalRO
  412. End Get
  413. End Property
  414. Public ReadOnly Property DiasPlazoRO As Integer
  415. Get
  416. Return _DiasPlazoRO
  417. End Get
  418. End Property
  419. Public ReadOnly Property PrecioCompraRO As Double
  420. Get
  421. Return _PrecioCompraRO
  422. End Get
  423. End Property
  424. Public ReadOnly Property PrecioVentaRO As Double
  425. Get
  426. Return _PrecioVentaRO
  427. End Get
  428. End Property
  429. Public ReadOnly Property GananciaPerdidaDeCapital As Double
  430. Get
  431. Return _GananciaPerdidaDeCapital
  432. End Get
  433. End Property
  434. Public ReadOnly Property IngresoPorInteres As Double
  435. Get
  436. Return _IngresoPorInteres
  437. End Get
  438. End Property
  439. Public ReadOnly Property CostosTotales As Double
  440. Get
  441. Return _CostosTotales
  442. End Get
  443. End Property
  444. Public ReadOnly Property GananciaPerdidaTotal As Double
  445. Get
  446. Return _GananciaPerdidaTotal
  447. End Get
  448. End Property
  449. Public ReadOnly Property RendimientoGananciaPerdida As Double
  450. Get
  451. Return _RendimientoGananciaPerdida
  452. End Get
  453. End Property
  454. Public ReadOnly Property RendimientoDeIntereses As Double
  455. Get
  456. Return _RendimientoDeIntereses
  457. End Get
  458. End Property
  459. Public ReadOnly Property RendimientoAntesImpuestos As Double
  460. Get
  461. Return _RendimientoAntesImpuestos
  462. End Get
  463. End Property
  464. Public ReadOnly Property RendimientoDespuesImpuestos As Double
  465. Get
  466. Return _RendimientoDespuesImpuestos
  467. End Get
  468. End Property
  469. Public Sub New()
  470. _ValorNominalCompra = 0
  471. _UltimaFechaCuponCompra = Date.Now.Date
  472. _SiguienteFechaCuponCompra = Date.Now.Date
  473. _FechaLiquidacionCompra = Date.Now.Date
  474. _FechaVencimientoCompra = Date.Now.Date
  475. _ValorNominalVenta = 0
  476. _SiguienteFechaCuponVenta = Date.Now.Date
  477. _FechaLiquidacionVenta = Date.Now.Date
  478. _FechaVencimientoVenta = Date.Now.Date
  479. End Sub
  480. 'CALCULOS
  481. Private Sub CalcularYTMAlVencimientoComisionCompra()
  482. Dim valor As Double
  483. Try
  484. valor = _YTMAlVencimientoCompra - (_SumaImpuestosyComisionesCompra * _DiasBaseCompra / _DiasAlVencimientoCompra)
  485. Catch ex As Exception
  486. valor = 0
  487. End Try
  488. _YTMAlVencimientoComisionCompra = valor
  489. End Sub
  490. Private Sub CalcularDiasAcumuladosCompra()
  491. Dim valor As Integer
  492. valor = Utilidades.Days360(_UltimaFechaCuponCompra, _FechaLiquidacionCompra)
  493. _DiasAcumuladosCompra = valor
  494. CalcularInteresAcumuladoCompra()
  495. End Sub
  496. Private Sub CalcularDiasAlVencimientoCompra()
  497. Dim valor As Integer
  498. If _DiasBaseCompra = 360 Then
  499. valor = Utilidades.Days360(_FechaLiquidacionCompra, _FechaVencimientoCompra)
  500. Else
  501. valor = DateDiff(DateInterval.Day, _FechaLiquidacionCompra, _FechaVencimientoCompra)
  502. End If
  503. _DiasAlVencimientoCompra = valor
  504. CalcularYTMAlVencimientoComisionCompra()
  505. CalcularYTMAlVencimientoCompra()
  506. End Sub
  507. Private Sub CalcularInteresAcumuladoCompra()
  508. Dim valor As Double
  509. Try
  510. valor = _ValorNominalCompra * _PorcentajeCuponCompra * _DiasAcumuladosCompra / _DiasBaseCompra
  511. Catch ex As Exception
  512. valor = 0
  513. End Try
  514. _InteresAcumuladoCompra = valor
  515. CalcularPorcentajeInteresAcumuladoCompra()
  516. CalcularMontoAPagarCompra()
  517. End Sub
  518. Private Sub CalcularPorcentajeInteresAcumuladoCompra()
  519. Dim valor As Double
  520. Dim vDiasPeriodo As Integer = Utilidades.DiasDeUnPeriodo(_PeriodicidadCompra)
  521. Try
  522. valor = _InteresAcumuladoCompra / _ValorNominalCompra * _DiasBaseCompra / vDiasPeriodo
  523. Catch ex As Exception
  524. valor = 0
  525. End Try
  526. _PorcentajeInteresAcumuladoCompra = valor
  527. CalcularPrecioSucioCompra()
  528. End Sub
  529. Private Sub CalcularPrecioSucioCompra()
  530. Dim valor As Double
  531. Try
  532. 'valor = _PrecioCompra * 0.01 + _PorcentajeInteresAcumuladoCompra
  533. valor = _PrecioCompra + _PorcentajeInteresAcumuladoCompra
  534. Catch ex As Exception
  535. valor = 0
  536. End Try
  537. _PrecioSucioCompra = valor
  538. End Sub
  539. Private Sub CalcularValorTransadoCompra()
  540. Dim valor As Double
  541. valor = (_PrecioCompra) * _ValorNominalCompra
  542. _ValorTransadoCompra = valor
  543. CalcularMontoAPagarCompra()
  544. CalcularGananciaPerdidaDeCapital()
  545. CalcularRendimientoGananciaPerdida()
  546. CalcularRendimientoDeIntereses()
  547. CalcularRendimientoDespuesImpuestos()
  548. End Sub
  549. Private Sub CalcularMontoAPagarCompra()
  550. Dim valor As Double
  551. Try
  552. valor = _ValorTransadoCompra + _SumaImpuestosyComisionesCompra + _InteresAcumuladoCompra + _CostoDeTransferenciaCompra
  553. Catch ex As Exception
  554. valor = 0
  555. End Try
  556. _MontoAPagarCompra = valor
  557. End Sub
  558. 'CALCULOS VENTA
  559. Private Sub CalcularUltimaFechaCuponVenta()
  560. Dim valor As Date
  561. Dim vDiasPeriodo As Integer = Utilidades.DiasDeUnPeriodo(_PeriodicidadVenta)
  562. Try
  563. _SiguienteFechaCuponCompra.AddDays(vDiasPeriodo + 1)
  564. valor = _SiguienteFechaCuponCompra
  565. Catch ex As Exception
  566. valor = Date.Now.Date
  567. End Try
  568. _UltimaFechaCuponVenta = valor
  569. CalcularSiguienteFechaCuponVenta()
  570. CalcularDiasAcumuladosVenta()
  571. End Sub
  572. Private Sub CalcularSiguienteFechaCuponVenta()
  573. Dim valor As Date
  574. Dim vDiasPeriodo As Integer = Utilidades.DiasDeUnPeriodo(_PeriodicidadVenta)
  575. valor = _UltimaFechaCuponVenta.AddDays(vDiasPeriodo + 1)
  576. _SiguienteFechaCuponVenta = valor
  577. End Sub
  578. Private Sub CalcularYTMAlVencimientoComisionVenta()
  579. Dim valor As Double
  580. Try
  581. valor = _YTMAlVencimientoVenta - (_PorcentajeComisionCasaVenta * _DiasBaseVenta / _DiasAlVencimientoVenta) - (_PorcentajeComisionBolsaVenta * _DiasBaseVenta / _DiasAlVencimientoVenta)
  582. Catch ex As Exception
  583. valor = 0
  584. End Try
  585. _YTMAlVencimientoComisionVenta = valor
  586. End Sub
  587. Private Sub CalcularDiasAcumuladosVenta()
  588. Dim valor As Integer
  589. If _DiasBaseVenta = 360 Then
  590. valor = Utilidades.Days360(_UltimaFechaCuponVenta, _FechaLiquidacionVenta)
  591. Else
  592. valor = DateDiff(DateInterval.Day, _UltimaFechaCuponVenta, _FechaLiquidacionVenta)
  593. End If
  594. _DiasAcumuladosVenta = valor
  595. CalcularYTMAlVencimientoVenta()
  596. CalcularInteresAcumuladoVenta()
  597. CalcularInteresAcumuladoPorcentajeVenta()
  598. End Sub
  599. Private Sub CalcularDiasAlVencimientoVenta()
  600. Dim valor As Integer
  601. If _DiasBaseVenta = 360 Then
  602. valor = Utilidades.Days360(_FechaLiquidacionVenta, _FechaVencimientoVenta)
  603. Else
  604. valor = DateDiff(DateInterval.Day, _FechaLiquidacionVenta, _FechaVencimientoVenta)
  605. End If
  606. _DiasAlVencimientoVenta = valor
  607. CalcularYTMAlVencimientoVenta()
  608. CalcularYTMAlVencimientoComisionVenta()
  609. End Sub
  610. Private Sub CalcularInteresAcumuladoVenta()
  611. Dim valor As Double
  612. Try
  613. valor = _ValorNominalVenta * _PorcentajeCuponVenta * _DiasAcumuladosVenta / _DiasBaseVenta
  614. Catch ex As Exception
  615. valor = 0
  616. End Try
  617. _InteresAcumuladoVenta = valor
  618. CalcularInteresAcumuladoPorcentajeVenta()
  619. CalcularMontoARecibirVenta()
  620. End Sub
  621. Private Sub CalcularInteresAcumuladoPorcentajeVenta()
  622. Dim valor As Double
  623. Dim vDiasPeriodo As Integer = Utilidades.DiasDeUnPeriodo(_PeriodicidadVenta)
  624. Try
  625. valor = _InteresAcumuladoVenta / _ValorNominalVenta * _DiasBaseVenta / vDiasPeriodo
  626. valor = valor * 100
  627. Catch ex As Exception
  628. valor = 0
  629. End Try
  630. _InteresAcumuladoPorcentajeVenta = valor
  631. CalcularPrecioSucioVenta()
  632. End Sub
  633. Private Sub CalcularPrecioSucioVenta()
  634. Dim valor As Double
  635. Try
  636. valor = _PrecioVenta + _InteresAcumuladoPorcentajeVenta
  637. valor = valor
  638. Catch ex As Exception
  639. valor = 0
  640. End Try
  641. _PrecioSucioVenta = valor
  642. End Sub
  643. Private Sub CalcularValorTransadoVenta()
  644. Dim valor As Double
  645. Try
  646. valor = _PrecioVenta * _ValorNominalVenta
  647. Catch ex As Exception
  648. valor = 0
  649. End Try
  650. _ValorTransadoVenta = valor
  651. CalcularMontoARecibirVenta()
  652. CalcularGananciaPerdidaDeCapital()
  653. End Sub
  654. Private Sub CalcularMontoARecibirVenta()
  655. Dim valor As Double
  656. Try
  657. valor = _ValorTransadoVenta - _ComisionBolsaVenta - _ComisionCasaVenta + _InteresAcumuladoVenta
  658. Catch ex As Exception
  659. valor = 0
  660. End Try
  661. _MontoARecibirVenta = valor
  662. End Sub
  663. Private Sub CalcularDiasPlazoRO()
  664. Dim valor As Integer
  665. If _DiasBaseCompra = 360 Then
  666. valor = Utilidades.Days360(_FechaLiquidacionCompra, _FechaLiquidacionVenta)
  667. Else
  668. valor = DateDiff(DateInterval.Day, _FechaLiquidacionCompra, _FechaLiquidacionVenta)
  669. End If
  670. _DiasPlazoRO = valor
  671. CalcularRendimientoGananciaPerdida()
  672. CalcularRendimientoDeIntereses()
  673. CalcularRendimientoDespuesImpuestos()
  674. End Sub
  675. Private Sub CalcularGananciaPerdidaDeCapital()
  676. Dim valor As Double
  677. valor = _ValorTransadoVenta - _ValorTransadoCompra
  678. _GananciaPerdidaDeCapital = valor
  679. CalcularGananciaPerdidaTotal()
  680. CalcularRendimientoGananciaPerdida()
  681. End Sub
  682. Private Sub CalcularGananciaPerdidaTotal()
  683. Dim valor As Double
  684. valor = _GananciaPerdidaDeCapital + _IngresoPorInteres
  685. _GananciaPerdidaTotal = valor
  686. CalcularRendimientoDespuesImpuestos()
  687. End Sub
  688. Private Sub CalcularRendimientoGananciaPerdida()
  689. Dim valor As Double
  690. Try
  691. valor = _GananciaPerdidaDeCapital / _ValorTransadoCompra * _DiasBaseCompra / _DiasPlazoRO
  692. Catch ex As Exception
  693. valor = 0
  694. End Try
  695. _RendimientoGananciaPerdida = valor
  696. End Sub
  697. Private Sub CalcularRendimientoDeIntereses()
  698. Dim valor As Double
  699. Try
  700. valor = _IngresoPorInteres / _ValorTransadoCompra * _DiasBaseCompra / _DiasPlazoRO
  701. Catch ex As Exception
  702. valor = 0
  703. End Try
  704. _RendimientoDeIntereses = valor
  705. End Sub
  706. Private Sub CalcularRendimientoDespuesImpuestos()
  707. Dim valor As Double
  708. Try
  709. valor = _GananciaPerdidaTotal / _ValorTransadoCompra * _DiasBaseCompra / _DiasPlazoRO
  710. valor = valor * 100
  711. Catch ex As Exception
  712. valor = 0
  713. End Try
  714. _RendimientoDespuesImpuestos = valor
  715. End Sub
  716. Private Sub CalcularSumaImpuestosyComisiones()
  717. If Not Double.TryParse(_dtImpuestosYComisiones.Compute("SUM(MontoImp)", "TipoOper='C'").ToString, _SumaImpuestosyComisionesCompra) Then
  718. _SumaImpuestosyComisionesCompra = 0
  719. End If
  720. If Not Double.TryParse(_dtImpuestosYComisiones.Compute("SUM(MontoImp)", "TipoOper='V'").ToString, _SumaImpuestosYComisionesVenta) Then
  721. _SumaImpuestosYComisionesVenta = 0
  722. End If
  723. End Sub
  724. Private Sub CalcularYTMAlVencimientoCompra()
  725. Dim vRedemption As Double = (_PrecioAlVencimientoCompra * 100) 'Amortizacion,Precio al vencimiento
  726. Dim vRate As Double = _PorcentajeCuponCompra 'Porcentaje de cupon, tasa
  727. Dim vFrecuency As Integer = 0 'For annual payments, frequency = 1; for semiannual, frequency = 2; for quarterly, frequency = 4.
  728. Dim vPar As Double = (_PrecioCompra * 100) 'Precio de Compra
  729. Dim vA As Integer = _DiasAcumuladosCompra 'Dias Acumulados
  730. Dim vE As Integer = Utilidades.DiasDeUnPeriodo(_PeriodicidadCompra) 'número de días en el período del cupón.
  731. Dim vDSR As Integer = _DiasAlVencimientoCompra 'número de días desde la fecha de liquidación hasta la fecha de amortización.
  732. 'If vA = 0 Then vA = 1
  733. If _PeriodicidadCompra = "A" Then vFrecuency = 1
  734. If _PeriodicidadCompra = "S" Then vFrecuency = 2
  735. If _PeriodicidadCompra = "T" Then vFrecuency = 4
  736. _YTMAlVencimientoCompra = (vRedemption / 100) + (vRate / vFrecuency)
  737. _YTMAlVencimientoCompra = _YTMAlVencimientoCompra - ((vPar / 100) + ((vA / vE) * (vRate / vFrecuency)))
  738. _YTMAlVencimientoCompra = _YTMAlVencimientoCompra / ((vPar / 100) + ((vA / vE) * (vRate / vFrecuency)))
  739. _YTMAlVencimientoCompra = _YTMAlVencimientoCompra * ((vFrecuency * vE) / vDSR)
  740. End Sub
  741. Public Function CalcularYTMComision(ByVal YTMVen As Double, ByVal ComisionCasa As Double, ByVal DiasVencimiento As Integer, ByVal ComisionBolsa As Double, ByVal Fecha1 As Date, ByVal Fecha2 As Date, ByVal IndexBase As Integer)
  742. Dim Valor As Double = 0.0
  743. If (DiasVencimiento <> 0) Then
  744. If (IndexBase = 0) Then
  745. Valor = YTMVen - ((ComisionCasa) * 360 / DiasVencimiento) - ((ComisionBolsa) * 360 / DiasVencimiento)
  746. Return Valor
  747. ElseIf (IndexBase = 1) Then
  748. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  749. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  750. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha366Varios(Fecha1, Fecha2)
  751. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha365Varios(Fecha1, Fecha2)
  752. If (DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  753. PrOpc1 = ((ComisionCasa) * 366 / DiasPrimeraFecha) - ((ComisionBolsa) * 366 / DiasPrimeraFecha)
  754. PrOpc2 = ((ComisionCasa) * 365 / DiasSegundaFecha) - ((ComisionBolsa) * 365 / DiasSegundaFecha)
  755. Valor = YTMVen - PrOpc1 + PrOpc2
  756. ElseIf (Not DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  757. Valor = YTMVen - ((ComisionCasa) * 365 / DiasSegundaFecha) - ((ComisionBolsa) * 365 / DiasSegundaFecha)
  758. ElseIf (DiasPrimeraFecha > 0 And Not DiasSegundaFecha > 0) Then
  759. Valor = YTMVen - ((ComisionCasa) * 366 / DiasPrimeraFecha) - ((ComisionBolsa) * 366 / DiasPrimeraFecha)
  760. Else
  761. Valor = 0
  762. End If
  763. Return Valor
  764. ElseIf (IndexBase = 2) Then
  765. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  766. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  767. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha360Bi(Fecha1, Fecha2)
  768. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha360(Fecha1, Fecha2)
  769. If (DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  770. PrOpc1 = ((ComisionCasa) * 366 / DiasPrimeraFecha) - ((ComisionBolsa) * 366 / DiasPrimeraFecha)
  771. PrOpc2 = ((ComisionCasa) * 365 / DiasSegundaFecha) - ((ComisionBolsa) * 365 / DiasSegundaFecha)
  772. Valor = YTMVen - PrOpc1 + PrOpc2
  773. ElseIf (Not DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  774. Valor = YTMVen - ((ComisionCasa) * 365 / DiasSegundaFecha) - ((ComisionBolsa) * 365 / DiasSegundaFecha)
  775. ElseIf (DiasPrimeraFecha > 0 And Not DiasSegundaFecha > 0) Then
  776. Valor = YTMVen - ((ComisionCasa) * 366 / DiasPrimeraFecha) - ((ComisionBolsa) * 366 / DiasPrimeraFecha)
  777. Else
  778. Valor = 0
  779. End If
  780. Return Valor
  781. Else
  782. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  783. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  784. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha366Varios(Fecha1, Fecha2)
  785. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha365Varios(Fecha1, Fecha2)
  786. If (DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  787. PrOpc1 = ((ComisionCasa) * 360 / DiasPrimeraFecha) - ((ComisionBolsa) * 360 / DiasPrimeraFecha)
  788. PrOpc2 = ((ComisionCasa) * 360 / DiasSegundaFecha) - ((ComisionBolsa) * 360 / DiasSegundaFecha)
  789. Valor = YTMVen - PrOpc1 + PrOpc2
  790. ElseIf (Not DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  791. Valor = YTMVen - ((ComisionCasa) * 360 / DiasSegundaFecha) - ((ComisionBolsa) * 360 / DiasSegundaFecha)
  792. ElseIf (DiasPrimeraFecha > 0 And Not DiasSegundaFecha > 0) Then
  793. Valor = YTMVen - ((ComisionCasa) * 360 / DiasPrimeraFecha) - ((ComisionBolsa) * 360 / DiasPrimeraFecha)
  794. Else
  795. Valor = 0
  796. End If
  797. Return Valor
  798. End If
  799. End If
  800. Return Valor
  801. End Function
  802. Private Sub CalcularYTMAlVencimientoVenta()
  803. Dim vRedemption As Double = (_PrecioAlVencimientoVenta * 100) 'Amortizacion,Precio al vencimiento
  804. Dim vRate As Double = _PorcentajeCuponVenta 'Porcentaje de cupon, tasa
  805. Dim vFrecuency As Integer = 0 'For annual payments, frequency = 1; for semiannual, frequency = 2; for quarterly, frequency = 4.
  806. Dim vPar As Double = (_PrecioVenta * 100) 'Precio de Compra
  807. Dim vA As Integer = _DiasAcumuladosVenta 'Dias Acumulados
  808. Dim vE As Integer = Utilidades.DiasDeUnPeriodo(_PeriodicidadVenta) 'número de días en el período del cupón.
  809. Dim vDSR As Integer = _DiasAlVencimientoVenta 'número de días desde la fecha de liquidación hasta la fecha de amortización.
  810. 'If vA = 0 Then vA = 1
  811. If _PeriodicidadVenta = "A" Then vFrecuency = 1
  812. If _PeriodicidadVenta = "S" Then vFrecuency = 2
  813. If _PeriodicidadVenta = "T" Then vFrecuency = 4
  814. _YTMAlVencimientoVenta = (vRedemption / 100) + (vRate / vFrecuency)
  815. _YTMAlVencimientoVenta = _YTMAlVencimientoVenta - ((vPar / 100) + ((vA / vE) * (vRate / vFrecuency)))
  816. _YTMAlVencimientoVenta = _YTMAlVencimientoVenta / ((vPar / 100) + ((vA / vE) * (vRate / vFrecuency)))
  817. _YTMAlVencimientoVenta = _YTMAlVencimientoVenta * ((vFrecuency * vE) / vDSR)
  818. End Sub
  819. End Class