AccionesCE.vb 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. 
  2. Public Class AccionesCE
  3. Private _CodigoInversion As String
  4. Private _TipoOperacion As String
  5. Private _AccionPreferente As String
  6. Private _OperacionEnBolsa As String
  7. Private _FactorDeDividendo As Double
  8. Private _IngresoBruto As Double
  9. Private _IngresoBrutoPendiente As Double
  10. Private _ISR As Double
  11. Private _ISRPendiente As Double
  12. Private _IngresoNeto As Double
  13. Dim Operaciones As New Operaciones
  14. Private _IngresoNetoPendiente As Double
  15. Private _dtImpuestosYComisiones As DataTable
  16. Private _dtDividendos As DataTable
  17. Private _TipoInstrumento As String = "ACC"
  18. Private _CodigoInstrumentoFinanciero As String
  19. Private _DescripcionTipoInstrumento As String
  20. Private _Registro As DataTable
  21. Private _ComisionCompraCasa As Double
  22. Private _ComisionCompraBolsa As Double
  23. Private _ComisionVentaCasa As Double
  24. Private _ComisionVentaBolsa As Double
  25. Private _IOF As Boolean
  26. Private _Renta As Boolean
  27. Private _Tipo As String
  28. Private _RetornoBruto As Double
  29. Private _GananciaDeCapitalTotalVentasus As Double = 0
  30. Private _RetornoAnualizadoBrutoVentasus As Double = 0
  31. Private _MontoNetoVentasus As Double = 0
  32. Private _PrecioSucioVentasus As Double = 0
  33. Private _ComisionPorcentajeCompraCasa As Double = 0
  34. Private _ComisionPorcentajeCompraBolsa As Double = 0
  35. Private _ComisionPorcentajeVentaCasa As Double = 0
  36. Private _ComisionPorcentajeVentaBolsa As Double = 0
  37. Private _MontoNetoComprasus As Double = 0
  38. 'COMPRA
  39. Private _CodigoCasaCompra As String
  40. Private _PrecioLimpioCompra As Double
  41. Private _FechaOperacionCompra As Date
  42. Private _FechaLiquidacionCompra As Date
  43. Private _DiasDeTenenciaCompra As Integer
  44. Private _GananciaDeCapitalTotalCompra As Double
  45. Private _GananciaDeCapitalUnitarioCompra As Double
  46. Private _RetornoAnualizadoBrutoCompra As Double
  47. Private _RetornoAnualizadoNetoCompra As Double
  48. Private _CantidadCompra As Integer
  49. Private _ValorTransadoCompra As Double
  50. Private _MontoNetoCompra As Double
  51. Private _PrecioSucioCompra As Double
  52. Private _SumaImpuestosYComisionesCompra As Double
  53. 'VENTA
  54. Private _CodigoCasaVenta As String
  55. Private _PrecioLimpioVenta As Double
  56. Private _FechaOperacionVenta As Date
  57. Private _FechaLiquidacionVenta As Date
  58. Private _DiasDeTenenciaVenta As Integer
  59. Private _GananciaDeCapitalTotalVenta As Double
  60. Private _GananciaDeCapitalUnitarioVenta As Double
  61. Private _RetornoAnualizadoBrutoVenta As Double
  62. Private _RetornoAnualizadoNetoVenta As Double
  63. Private _CantidadVenta As Integer
  64. Private _ValorTransadoVenta As Double
  65. Private _MontoNetoVenta As Double
  66. Private _PrecioSucioVenta As Double
  67. Private _SumaImpuestosYComisionesVenta As Double
  68. 'GENERAL
  69. Public Property CodigoInversion
  70. Get
  71. Return _CodigoInversion
  72. End Get
  73. Set(value)
  74. _CodigoInversion = value
  75. End Set
  76. End Property
  77. Public Property AccionPreferente As String
  78. Get
  79. Return _AccionPreferente
  80. End Get
  81. Set(value As String)
  82. _AccionPreferente = value
  83. End Set
  84. End Property
  85. Public Property OperacionEnBolsa As String
  86. Get
  87. Return _OperacionEnBolsa
  88. End Get
  89. Set(value As String)
  90. _OperacionEnBolsa = value
  91. End Set
  92. End Property
  93. Public Property FactorDeDividendo As Double
  94. Get
  95. Return _FactorDeDividendo
  96. End Get
  97. Set(value As Double)
  98. _FactorDeDividendo = value
  99. End Set
  100. End Property
  101. Public Property ImpuestosYComisiones As DataTable
  102. Get
  103. Return _dtImpuestosYComisiones
  104. End Get
  105. Set(value As DataTable)
  106. _dtImpuestosYComisiones = value
  107. CalcularSumaImpuestosyComisiones()
  108. End Set
  109. End Property
  110. 'COMPRA
  111. Public Property CodigoCasaCompra As String
  112. Get
  113. Return _CodigoCasaCompra
  114. End Get
  115. Set(value As String)
  116. _CodigoCasaCompra = value
  117. End Set
  118. End Property
  119. Public Property PrecioLimpioCompra As Double
  120. Get
  121. Return _PrecioLimpioCompra
  122. End Get
  123. Set(value As Double)
  124. _PrecioLimpioCompra = value
  125. CalculaValorTrasadoCompra()
  126. End Set
  127. End Property
  128. Public Property FechaOperacionCompra As Date
  129. Get
  130. Return _FechaOperacionCompra
  131. End Get
  132. Set(value As Date)
  133. _FechaOperacionCompra = value
  134. End Set
  135. End Property
  136. Public Property FechaVencimientoCompra As Date
  137. Get
  138. Return _FechaLiquidacionCompra
  139. End Get
  140. Set(value As Date)
  141. _FechaLiquidacionCompra = value
  142. CalcularDiasDeTenenciaVenta()
  143. End Set
  144. End Property
  145. Public Property DiasDeTenenciaCompra As Integer
  146. Get
  147. Return _DiasDeTenenciaCompra
  148. End Get
  149. Set(value As Integer)
  150. _DiasDeTenenciaCompra = value
  151. End Set
  152. End Property
  153. Public Property ComisionVentaBolsa As Double
  154. Get
  155. Return _ComisionVentaBolsa
  156. End Get
  157. Set(value As Double)
  158. _ComisionVentaBolsa = value
  159. End Set
  160. End Property
  161. Public Property ComisionPorcentajeVentaBolsa As Double
  162. Get
  163. Return _ComisionPorcentajeVentaBolsa
  164. End Get
  165. Set(value As Double)
  166. _ComisionPorcentajeVentaBolsa = value
  167. End Set
  168. End Property
  169. Public Property ComisionVentaCasa As Double
  170. Get
  171. Return _ComisionVentaCasa
  172. End Get
  173. Set(value As Double)
  174. _ComisionVentaCasa = value
  175. End Set
  176. End Property
  177. Public Property ComisionPorcentajeVentaCasa As Double
  178. Get
  179. Return _ComisionPorcentajeVentaCasa
  180. End Get
  181. Set(value As Double)
  182. _ComisionPorcentajeVentaCasa = value
  183. End Set
  184. End Property
  185. Public Property ComisionCompraBolsa As Double
  186. Get
  187. Return _ComisionCompraBolsa
  188. End Get
  189. Set(value As Double)
  190. _ComisionCompraBolsa = value
  191. End Set
  192. End Property
  193. Public Property ComisionPorcentajeCompraBolsa As Double
  194. Get
  195. Return _ComisionPorcentajeCompraBolsa
  196. End Get
  197. Set(value As Double)
  198. _ComisionPorcentajeCompraBolsa = value
  199. End Set
  200. End Property
  201. Public Property ComisionCompraCasa As Double
  202. Get
  203. Return _ComisionCompraCasa
  204. End Get
  205. Set(value As Double)
  206. _ComisionCompraCasa = value
  207. End Set
  208. End Property
  209. Public Property ComisionPorcentajeCompraCasa As Double
  210. Get
  211. Return _ComisionPorcentajeCompraCasa
  212. End Get
  213. Set(value As Double)
  214. _ComisionPorcentajeCompraCasa = value
  215. End Set
  216. End Property
  217. Public Property IOF As Boolean
  218. Get
  219. Return _IOF
  220. End Get
  221. Set(value As Boolean)
  222. _IOF = value
  223. End Set
  224. End Property
  225. Public Property Renta As Boolean
  226. Get
  227. Return _Renta
  228. End Get
  229. Set(value As Boolean)
  230. _Renta = value
  231. End Set
  232. End Property
  233. Public Property GananciaDeCapitalTotalCompra As Double
  234. Get
  235. Return _GananciaDeCapitalTotalCompra
  236. End Get
  237. Set(value As Double)
  238. _GananciaDeCapitalTotalCompra = value
  239. End Set
  240. End Property
  241. Public Property GananciaDeCapitalUnitarioCompra As Double
  242. Get
  243. Return _GananciaDeCapitalUnitarioCompra
  244. End Get
  245. Set(value As Double)
  246. _GananciaDeCapitalUnitarioCompra = value
  247. End Set
  248. End Property
  249. Public Property RetornoAnualizadoBrutoCompra As Double
  250. Get
  251. Return _RetornoAnualizadoBrutoCompra
  252. End Get
  253. Set(value As Double)
  254. _RetornoAnualizadoBrutoCompra = value
  255. End Set
  256. End Property
  257. Public Property RetornoAnualizadoNetoCompra As Double
  258. Get
  259. Return _RetornoAnualizadoNetoCompra
  260. End Get
  261. Set(value As Double)
  262. _RetornoAnualizadoNetoCompra = value
  263. End Set
  264. End Property
  265. Public Property CantidadCompra As Integer
  266. Get
  267. Return _CantidadCompra
  268. End Get
  269. Set(value As Integer)
  270. _CantidadCompra = value
  271. CalculaValorTrasadoCompra()
  272. CalcularPrecioSucioCompra()
  273. End Set
  274. End Property
  275. Public Property ValorTransadoCompra As Double
  276. Get
  277. Return _ValorTransadoCompra
  278. End Get
  279. Set(value As Double)
  280. _ValorTransadoCompra = value
  281. End Set
  282. End Property
  283. Public Property MontoNetoCompra As Double
  284. Get
  285. Return _MontoNetoCompra
  286. End Get
  287. Set(value As Double)
  288. _MontoNetoCompra = value
  289. CalcularMontoNetoCompra()
  290. End Set
  291. End Property
  292. Public Property MontoNetoComprasus As Double
  293. Get
  294. Return _MontoNetoComprasus
  295. End Get
  296. Set(value As Double)
  297. _MontoNetoComprasus = value
  298. End Set
  299. End Property
  300. Public Property PrecioSucioCompra As Double
  301. Get
  302. Return _PrecioSucioCompra
  303. End Get
  304. Set(value As Double)
  305. _PrecioSucioCompra = value
  306. End Set
  307. End Property
  308. Public Property SumaImpuestosYComisionesCompra As Double
  309. Get
  310. Return _SumaImpuestosYComisionesCompra
  311. End Get
  312. Set(value As Double)
  313. _SumaImpuestosYComisionesCompra = value
  314. CalcularMontoNetoCompra()
  315. End Set
  316. End Property
  317. 'VENTA
  318. Public Property CodigoCasaVenta As String
  319. Get
  320. Return _CodigoCasaVenta
  321. End Get
  322. Set(value As String)
  323. _CodigoCasaVenta = value
  324. End Set
  325. End Property
  326. Public Property PrecioLimpioVenta As Double
  327. Get
  328. Return _PrecioLimpioVenta
  329. End Get
  330. Set(value As Double)
  331. _PrecioLimpioVenta = value
  332. CalcularValorTransadoVenta()
  333. End Set
  334. End Property
  335. Public Property FechaOperacionVenta As Date
  336. Get
  337. Return _FechaOperacionVenta
  338. End Get
  339. Set(value As Date)
  340. _FechaOperacionVenta = value
  341. End Set
  342. End Property
  343. Public Property FechaVencimientoVenta As Date
  344. Get
  345. Return _FechaLiquidacionVenta
  346. End Get
  347. Set(value As Date)
  348. _FechaLiquidacionVenta = value
  349. CalcularDiasDeTenenciaVenta()
  350. End Set
  351. End Property
  352. Public Property DiasDeTenenciaVenta As Integer
  353. Get
  354. Return _DiasDeTenenciaVenta
  355. End Get
  356. Set(value As Integer)
  357. _DiasDeTenenciaVenta = value
  358. End Set
  359. End Property
  360. Public Property GananciaDeCapitalTotalVenta As Double
  361. Get
  362. Return _GananciaDeCapitalTotalVenta
  363. End Get
  364. Set(value As Double)
  365. _GananciaDeCapitalTotalVenta = value
  366. End Set
  367. End Property
  368. Public Property GananciaDeCapitalTotalVentasus As Double
  369. Get
  370. Return _GananciaDeCapitalTotalVentasus
  371. End Get
  372. Set(value As Double)
  373. _GananciaDeCapitalTotalVentasus = value
  374. End Set
  375. End Property
  376. Public Property GananciaDeCapitalUnitarioVenta As Double
  377. Get
  378. Return _GananciaDeCapitalUnitarioVenta
  379. End Get
  380. Set(value As Double)
  381. _GananciaDeCapitalUnitarioVenta = value
  382. End Set
  383. End Property
  384. Public Property RetornoAnualizadoBrutoVenta As Double
  385. Get
  386. CalcularRetornoAnualBrutoVenta()
  387. Return _RetornoAnualizadoBrutoVenta
  388. End Get
  389. Set(value As Double)
  390. _RetornoAnualizadoBrutoVenta = value
  391. End Set
  392. End Property
  393. Public Property RetornoAnualizadoBrutoVentasus As Double
  394. Get
  395. Return _RetornoAnualizadoBrutoVentasus
  396. End Get
  397. Set(value As Double)
  398. _RetornoAnualizadoBrutoVentasus = value
  399. End Set
  400. End Property
  401. Public Property RetornoAnualizadoNetoVenta As Double
  402. Get
  403. CalcularRetornoAnualNetoVenta()
  404. Return _RetornoAnualizadoNetoVenta
  405. End Get
  406. Set(value As Double)
  407. _RetornoAnualizadoNetoVenta = value
  408. End Set
  409. End Property
  410. Public Property CantidadVenta As Integer
  411. Get
  412. Return _CantidadVenta
  413. End Get
  414. Set(value As Integer)
  415. _CantidadVenta = value
  416. CalcularValorTransadoVenta()
  417. CalcularGananciaDeCapitalUnitarioVenta()
  418. CalcularPrecioSucioVenta()
  419. End Set
  420. End Property
  421. Public Property Tipo As String
  422. Get
  423. Return _Tipo
  424. End Get
  425. Set(value As String)
  426. _Tipo = value
  427. End Set
  428. End Property
  429. Public Property RetornoBruto As Double
  430. Get
  431. Return _RetornoBruto
  432. End Get
  433. Set(value As Double)
  434. _RetornoBruto = value
  435. End Set
  436. End Property
  437. Public Property ValorTransadoVenta As Double
  438. Get
  439. Return _ValorTransadoVenta
  440. End Get
  441. Set(value As Double)
  442. _ValorTransadoVenta = value
  443. End Set
  444. End Property
  445. Public Property MontoNetoVenta As Double
  446. Get
  447. Return _MontoNetoVenta
  448. End Get
  449. Set(value As Double)
  450. _MontoNetoVenta = value
  451. End Set
  452. End Property
  453. Public Property MontoNetoVentasus As Double
  454. Get
  455. Return _MontoNetoVentasus
  456. End Get
  457. Set(value As Double)
  458. _MontoNetoVentasus = value
  459. End Set
  460. End Property
  461. Public Property PrecioSucioVenta As Double
  462. Get
  463. Return _PrecioSucioVenta
  464. End Get
  465. Set(value As Double)
  466. _PrecioSucioVenta = value
  467. End Set
  468. End Property
  469. Public Property PrecioSucioVentasus As Double
  470. Get
  471. Return _PrecioSucioVentasus
  472. End Get
  473. Set(value As Double)
  474. _PrecioSucioVentasus = value
  475. End Set
  476. End Property
  477. Public Property SumaImpuestosYComisionesVenta As Double
  478. Get
  479. Return _SumaImpuestosYComisionesVenta
  480. End Get
  481. Set(value As Double)
  482. _SumaImpuestosYComisionesVenta = value
  483. CalcularMontoNetoVenta()
  484. End Set
  485. End Property
  486. Public Sub New()
  487. 'GENERAL
  488. _IngresoBruto = 0
  489. _IngresoBrutoPendiente = 0
  490. _ISR = 0
  491. _ISRPendiente = 0
  492. _IngresoNeto = 0
  493. _IngresoNetoPendiente = 0
  494. _dtImpuestosYComisiones = New DataTable
  495. _dtDividendos = New DataTable
  496. _Registro = New DataTable
  497. 'COMPRA
  498. _PrecioLimpioCompra = 0
  499. _FechaOperacionCompra = Date.Now.Date
  500. _FechaLiquidacionCompra = Date.Now.Date
  501. _CantidadCompra = 1
  502. _DiasDeTenenciaCompra = 0
  503. _GananciaDeCapitalTotalCompra = 0
  504. _GananciaDeCapitalUnitarioCompra = 0
  505. _RetornoAnualizadoBrutoCompra = 0
  506. _RetornoAnualizadoNetoCompra = 0
  507. _ValorTransadoCompra = 0
  508. _MontoNetoCompra = 0
  509. _PrecioSucioCompra = 0
  510. 'VENTA
  511. _PrecioLimpioVenta = 0
  512. _FechaOperacionVenta = Date.Now.Date
  513. _FechaLiquidacionVenta = Date.Now.Date
  514. _CantidadVenta = 1
  515. _DiasDeTenenciaVenta = 0
  516. _GananciaDeCapitalTotalVenta = 0
  517. _GananciaDeCapitalUnitarioVenta = 0
  518. _RetornoAnualizadoBrutoVenta = 0
  519. _RetornoAnualizadoNetoVenta = 0
  520. _CantidadVenta = 0
  521. _ValorTransadoVenta = 0
  522. _MontoNetoVenta = 0
  523. _PrecioSucioVenta = 0
  524. End Sub
  525. 'CALCULOS COMPRA
  526. Private Sub CalculaValorTrasadoCompra()
  527. _ValorTransadoCompra = _CantidadCompra * _PrecioLimpioCompra
  528. CalcularMontoNetoCompra()
  529. End Sub
  530. Private Sub CalcularMontoNetoCompra()
  531. _MontoNetoCompra = _ValorTransadoCompra + _SumaImpuestosYComisionesCompra
  532. CalcularPrecioSucioCompra()
  533. CalcularGananciaDeCapitalTotalVenta()
  534. CalcularRetornoAnualBrutoVenta()
  535. CalcularRetornoAnualNetoVenta()
  536. End Sub
  537. Private Sub CalcularPrecioSucioCompra()
  538. If (String.IsNullOrEmpty(_CantidadCompra.ToString) Or _CantidadCompra.ToString = "0") Then
  539. _PrecioSucioCompra = "0.0"
  540. Else
  541. _PrecioSucioCompra = _MontoNetoCompra / _CantidadCompra
  542. End If
  543. End Sub
  544. 'CALCULOS VENTA
  545. Private Sub CalcularDiasDeTenenciaVenta()
  546. Dim valor As Integer
  547. If _FechaLiquidacionVenta > Date.Today.Date Then
  548. valor = DateDiff(DateInterval.Day, _FechaLiquidacionCompra, Date.Today.Date)
  549. Else
  550. valor = DateDiff(DateInterval.Day, _FechaLiquidacionCompra, _FechaLiquidacionVenta)
  551. End If
  552. _DiasDeTenenciaVenta = valor
  553. CalcularRetornoAnualBrutoVenta()
  554. CalcularRetornoAnualNetoVenta()
  555. End Sub
  556. Private Sub CalcularValorTransadoVenta()
  557. _ValorTransadoVenta = _PrecioLimpioVenta * _CantidadVenta
  558. CalcularMontoNetoVenta()
  559. End Sub
  560. Private Sub CalcularMontoNetoVenta()
  561. _MontoNetoVenta = _ValorTransadoVenta - _SumaImpuestosYComisionesVenta
  562. CalcularGananciaDeCapitalTotalVenta()
  563. CalcularPrecioSucioVenta()
  564. End Sub
  565. Private Sub CalcularGananciaDeCapitalTotalVenta()
  566. _GananciaDeCapitalTotalVenta = _MontoNetoVenta - _MontoNetoCompra
  567. CalcularGananciaDeCapitalUnitarioVenta()
  568. CalcularRetornoAnualBrutoVenta()
  569. CalcularRetornoAnualNetoVenta()
  570. End Sub
  571. Private Sub CalcularGananciaDeCapitalUnitarioVenta()
  572. _GananciaDeCapitalUnitarioVenta = _GananciaDeCapitalTotalVenta / _CantidadVenta
  573. _GananciaDeCapitalUnitarioVenta = Format(_GananciaDeCapitalUnitarioVenta, "0.0000")
  574. End Sub
  575. Private Sub CalcularRetornoAnualBrutoVenta()
  576. If _DiasDeTenenciaVenta = 0 Or _MontoNetoCompra = 0 Then
  577. _RetornoAnualizadoBrutoVenta = 0
  578. Else
  579. _RetornoAnualizadoBrutoVenta = ((_GananciaDeCapitalTotalVenta + Variables.IngresoBruto) / _MontoNetoCompra) * 365 / _DiasDeTenenciaVenta
  580. End If
  581. End Sub
  582. Private Sub CalcularRetornoAnualNetoVenta()
  583. If _DiasDeTenenciaVenta = 0 Or _MontoNetoCompra Then
  584. _RetornoAnualizadoNetoVenta = 0
  585. Else
  586. _RetornoAnualizadoNetoVenta = ((_GananciaDeCapitalTotalVenta + Variables.IngresoNeto) / _MontoNetoCompra) * 365 / _DiasDeTenenciaVenta
  587. End If
  588. End Sub
  589. Private Sub CalcularPrecioSucioVenta()
  590. _PrecioSucioVenta = _MontoNetoVenta / _CantidadVenta
  591. End Sub
  592. Private Sub CalcularSumaImpuestosyComisiones()
  593. If Not Double.TryParse(_dtImpuestosYComisiones.Compute("SUM(MontoImp)", "TipoOper='C'").ToString, _SumaImpuestosYComisionesCompra) Then
  594. _SumaImpuestosYComisionesCompra = 0
  595. End If
  596. If Not Double.TryParse(_dtImpuestosYComisiones.Compute("SUM(MontoImp)", "TipoOper='V'").ToString, _SumaImpuestosYComisionesVenta) Then
  597. _SumaImpuestosYComisionesVenta = 0
  598. End If
  599. CalcularMontoNetoCompra()
  600. CalcularMontoNetoVenta()
  601. End Sub
  602. End Class