instrument-calculations.service.ts 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. import { Injectable } from "@angular/core";
  2. import { of as observableOf, Observable, throwError } from "rxjs";
  3. import { HttpClient, HttpHeaders } from "@angular/common/http";
  4. import { retry, catchError, map, timeout } from "rxjs/operators";
  5. import { environment } from "@environments/environment";
  6. @Injectable({
  7. providedIn: "root"
  8. })
  9. export class InstrumentCalculations {
  10. time: number = 6000;
  11. constructor(private http: HttpClient) {}
  12. // Calculos para lete
  13. leteCalc(
  14. codigo_instrumento: string,
  15. info_inversion: { id_tipo_base: string },
  16. info_instrumento: {
  17. valor_nominal: number;
  18. plazo: number;
  19. comision_casa_porcentaje: number;
  20. comision_bolsa_porcentaje: number;
  21. rendimiento_bruto: number;
  22. fecha_operacion: string;
  23. fecha_liquidacion?: string;
  24. }
  25. ): Observable<boolean> {
  26. return this.http
  27. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  28. codigo_instrumento,
  29. info_inversion,
  30. info_instrumento
  31. })
  32. .pipe(
  33. map(response => {
  34. return response;
  35. }),
  36. catchError(this.errorHandl)
  37. );
  38. }
  39. ceteCalc(
  40. codigo_instrumento: string,
  41. info_inversion: {
  42. id_tipo_base: number;
  43. id_periodicidad: number;
  44. id_formato_ingreso: number;
  45. },
  46. info_instrumento: {
  47. valor_nominal: number;
  48. comision_casa_porcentaje: number;
  49. comision_bolsa_porcentaje: number;
  50. plazo: number;
  51. rendimiento_bruto: number;
  52. otros_costos: number;
  53. fecha_operacion: string;
  54. fecha_liquidacion: string;
  55. fecha_ultima_cupon: string;
  56. //fecha_vencimiento: string;
  57. }
  58. ): Observable<boolean> {
  59. return this.http
  60. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  61. codigo_instrumento,
  62. info_inversion,
  63. info_instrumento
  64. })
  65. .pipe(
  66. map(response => {
  67. return response;
  68. }),
  69. catchError(this.errorHandl)
  70. );
  71. }
  72. // Para familia de bonos (bonos, eurobonos, certificados)
  73. bonosCalc(
  74. codigo_instrumento: string,
  75. info_inversion: {
  76. id_tipo_base: number;
  77. id_periodicidad: number;
  78. id_formato_ingreso: number;
  79. },
  80. info_instrumento: {
  81. costo_cedeval: number;
  82. comision_casa_porcentaje_compra: number;
  83. comision_bolsa_porcentaje_compra: number;
  84. cupon_porcentaje_compra: number;
  85. valor_nominal_compra: number;
  86. costo_transferencia: number;
  87. precio_vencimiento_compra: number;
  88. precio_compra: number;
  89. fecha_ultima_cupon_compra: string;
  90. fecha_liquidacion_compra: string;
  91. fecha_vencimiento_compra: string;
  92. comision_casa_porcentaje_venta: number;
  93. comision_bolsa_porcentaje_venta: number;
  94. cupon_porcentaje_venta: number;
  95. valor_nominal_venta: number;
  96. precio_vencimiento_venta: number;
  97. precio_venta: number;
  98. fecha_ultima_cupon_venta: string;
  99. fecha_liquidacion_venta: string;
  100. fecha_vencimiento_venta: string;
  101. }
  102. ): Observable<boolean> {
  103. return this.http
  104. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  105. codigo_instrumento,
  106. info_inversion,
  107. info_instrumento
  108. })
  109. .pipe(
  110. map(response => {
  111. return response;
  112. }),
  113. catchError(this.errorHandl)
  114. );
  115. }
  116. titularizacionCalc(
  117. codigo_instrumento: string,
  118. info_inversion: {
  119. id_tipo_base: number;
  120. id_periodicidad: number;
  121. id_formato_ingreso: number;
  122. },
  123. info_instrumento: {
  124. comision_casa_porcentaje_compra: number;
  125. comision_bolsa_porcentaje_compra: number;
  126. cupon_porcentaje_compra: number;
  127. valor_nominal_compra: number;
  128. costo_transferencia: number;
  129. precio_vencimiento_compra: number;
  130. precio_compra: number;
  131. fecha_ultima_cupon_compra: string;
  132. fecha_liquidacion_compra: string;
  133. fecha_vencimiento_compra: string;
  134. comision_casa_porcentaje_venta: number;
  135. comision_bolsa_porcentaje_venta: number;
  136. cupon_porcentaje_venta: number;
  137. valor_nominal_venta: number;
  138. precio_vencimiento_venta: number;
  139. precio_venta: number;
  140. fecha_ultima_cupon_venta: string;
  141. fecha_liquidacion_venta: string;
  142. fecha_vencimiento_venta: string;
  143. fecha_emision: string;
  144. costo_cedeval: number;
  145. amortizacion_porcentajes: any;
  146. }
  147. ): Observable<boolean> {
  148. return this.http
  149. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  150. codigo_instrumento,
  151. info_inversion,
  152. info_instrumento
  153. })
  154. .pipe(
  155. map(response => {
  156. return response;
  157. }),
  158. catchError(this.errorHandl)
  159. );
  160. }
  161. // Fondos de inversion
  162. fondosCalc(
  163. codigo_instrumento: string,
  164. info_inversion: {
  165. id_tipo_base: number;
  166. id_periodicidad: number;
  167. id_formato_ingreso: number;
  168. },
  169. info_instrumento: {
  170. cuota_participacion: number;
  171. valor_participacion: number;
  172. comision_bolsa_porcentaje: number;
  173. comision_casa_porcentaje: number;
  174. dividendo_porcentaje: number;
  175. rendimiento_porcentaje: number;
  176. dias_liquidacion: number;
  177. dias_vencimiento: number;
  178. fecha_operacion: string;
  179. }
  180. ): Observable<boolean> {
  181. return this.http
  182. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  183. codigo_instrumento,
  184. info_inversion,
  185. info_instrumento
  186. })
  187. .pipe(
  188. map(response => {
  189. return response;
  190. }),
  191. catchError(this.errorHandl)
  192. );
  193. }
  194. // Para vcn
  195. vcnCalc(
  196. codigo_instrumento: string,
  197. info_inversion: {
  198. id_tipo_base: number;
  199. id_periodicidad: number;
  200. id_formato_ingreso: number;
  201. },
  202. info_instrumento: {
  203. valor_par: boolean;
  204. valor_nominal: number;
  205. comision_casa_porcentaje: number;
  206. comision_bolsa_porcentaje: number;
  207. rendimiento_bruto: number;
  208. otros_costos: number;
  209. renta_porcentaje: number;
  210. fecha_operacion: string;
  211. fecha_liquidacion: string;
  212. fecha_ultima_cupon: string;
  213. fecha_vencimiento: string;
  214. }
  215. ): Observable<boolean> {
  216. return this.http
  217. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  218. codigo_instrumento,
  219. info_inversion,
  220. info_instrumento
  221. })
  222. .pipe(
  223. map(response => {
  224. return response;
  225. }),
  226. catchError(this.errorHandl)
  227. );
  228. }
  229. // Para pbur
  230. pburCalc(
  231. codigo_instrumento: string,
  232. info_inversion: {
  233. id_tipo_base: number;
  234. id_periodicidad: number;
  235. id_formato_ingreso: number;
  236. },
  237. info_instrumento: {
  238. valor_par: boolean;
  239. valor_nominal: number;
  240. comision_casa_porcentaje: number;
  241. comision_bolsa_porcentaje: number;
  242. rendimiento_bruto: number;
  243. otros_costos: number;
  244. plazo: number;
  245. renta_porcentaje: number;
  246. fecha_operacion: string;
  247. fecha_liquidacion: string;
  248. fecha_ultima_cupon: string;
  249. }
  250. ): Observable<boolean> {
  251. return this.http
  252. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  253. codigo_instrumento,
  254. info_inversion,
  255. info_instrumento
  256. })
  257. .pipe(
  258. map(response => {
  259. return response;
  260. }),
  261. catchError(this.errorHandl)
  262. );
  263. }
  264. dapCalc(
  265. codigo_instrumento: string,
  266. info_inversion: {
  267. id_tipo_base: number;
  268. id_periodicidad: number;
  269. id_formato_ingreso: number;
  270. },
  271. info_instrumento: {
  272. monto_inversion: number;
  273. tasa_porcentaje: number;
  274. renta_porcentaje: number;
  275. plazo: number;
  276. fecha_operacion: string;
  277. //fecha_vencimiento: string;
  278. }
  279. ): Observable<boolean> {
  280. return this.http
  281. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  282. codigo_instrumento,
  283. info_inversion,
  284. info_instrumento
  285. })
  286. .pipe(
  287. map(response => {
  288. return response;
  289. }),
  290. catchError(this.errorHandl)
  291. );
  292. }
  293. projectionCalc(id: string, proyecciones: any): Observable<boolean> {
  294. return this.http
  295. .put<any>(`${environment.productionApiUrl}/autocomplete/${id}`, {
  296. proyecciones
  297. })
  298. .pipe(
  299. map(response => {
  300. return response;
  301. }),
  302. catchError(this.errorHandl)
  303. );
  304. }
  305. projectionModification(id: string, proyecciones: any): Observable<boolean> {
  306. return this.http
  307. .put<any>(
  308. `${environment.productionApiUrl}/proyeccion/${id}`,
  309. proyecciones
  310. )
  311. .pipe(
  312. map(response => {
  313. return response;
  314. }),
  315. catchError(this.errorHandl)
  316. );
  317. }
  318. errorHandl(error) {
  319. let errorMessage = "";
  320. if (error.error) {
  321. // Get client-side error
  322. errorMessage = error.error;
  323. } else {
  324. // Get server-side error
  325. errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
  326. }
  327. return throwError(errorMessage);
  328. }
  329. }