instrument-calculations.service.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. // Para vcn
  162. vcnCalc(
  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. valor_par: boolean;
  171. valor_nominal: number;
  172. comision_casa_porcentaje: number;
  173. comision_bolsa_porcentaje: number;
  174. rendimiento_bruto: number;
  175. otros_costos: number;
  176. renta_porcentaje: number;
  177. fecha_operacion: string;
  178. fecha_liquidacion: string;
  179. fecha_ultima_cupon: string;
  180. fecha_vencimiento: string;
  181. }
  182. ): Observable<boolean> {
  183. return this.http
  184. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  185. codigo_instrumento,
  186. info_inversion,
  187. info_instrumento
  188. })
  189. .pipe(
  190. map(response => {
  191. return response;
  192. }),
  193. catchError(this.errorHandl)
  194. );
  195. }
  196. // Para pbur
  197. pburCalc(
  198. codigo_instrumento: string,
  199. info_inversion: {
  200. id_tipo_base: number;
  201. id_periodicidad: number;
  202. id_formato_ingreso: number;
  203. },
  204. info_instrumento: {
  205. valor_par: boolean;
  206. valor_nominal: number;
  207. comision_casa_porcentaje: number;
  208. comision_bolsa_porcentaje: number;
  209. rendimiento_bruto: number;
  210. otros_costos: number;
  211. plazo: number;
  212. renta_porcentaje: number;
  213. fecha_operacion: string;
  214. fecha_liquidacion: string;
  215. fecha_ultima_cupon: string;
  216. }
  217. ): Observable<boolean> {
  218. return this.http
  219. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  220. codigo_instrumento,
  221. info_inversion,
  222. info_instrumento
  223. })
  224. .pipe(
  225. map(response => {
  226. return response;
  227. }),
  228. catchError(this.errorHandl)
  229. );
  230. }
  231. dapCalc(
  232. codigo_instrumento: string,
  233. info_inversion: {
  234. id_tipo_base: number;
  235. id_periodicidad: number;
  236. id_formato_ingreso: number;
  237. },
  238. info_instrumento: {
  239. monto_inversion: number;
  240. tasa_porcentaje: number;
  241. renta_porcentaje: number;
  242. plazo: number;
  243. fecha_operacion: string;
  244. //fecha_vencimiento: string;
  245. }
  246. ): Observable<boolean> {
  247. return this.http
  248. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  249. codigo_instrumento,
  250. info_inversion,
  251. info_instrumento
  252. })
  253. .pipe(
  254. map(response => {
  255. return response;
  256. }),
  257. catchError(this.errorHandl)
  258. );
  259. }
  260. projectionCalc(id: string, proyecciones: any): Observable<boolean> {
  261. return this.http
  262. .put<any>(`${environment.productionApiUrl}/autocomplete/${id}`, {
  263. proyecciones
  264. })
  265. .pipe(
  266. map(response => {
  267. return response;
  268. }),
  269. catchError(this.errorHandl)
  270. );
  271. }
  272. projectionModification(id: string, proyecciones: any): Observable<boolean> {
  273. return this.http
  274. .put<any>(
  275. `${environment.productionApiUrl}/proyeccion/${id}`,
  276. proyecciones
  277. )
  278. .pipe(
  279. map(response => {
  280. return response;
  281. }),
  282. catchError(this.errorHandl)
  283. );
  284. }
  285. errorHandl(error) {
  286. let errorMessage = "";
  287. if (error.error) {
  288. // Get client-side error
  289. errorMessage = error.error;
  290. } else {
  291. // Get server-side error
  292. errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
  293. }
  294. return throwError(errorMessage);
  295. }
  296. }