instrument-calculations.service.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. comision_casa_porcentaje_compra: number;
  82. comision_bolsa_porcentaje_compra: number;
  83. cupon_porcentaje_compra: number;
  84. valor_nominal_compra: number;
  85. costo_transferencia: number;
  86. ytm_vencimiento_porcentaje_compra: 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. ytm_vencimiento_porcentaje_venta: number;
  97. precio_vencimiento_venta: number;
  98. precio_venta: number;
  99. fecha_ultima_cupon_venta: string;
  100. fecha_liquidacion_venta: string;
  101. fecha_vencimiento_venta: string;
  102. }
  103. ): Observable<boolean> {
  104. return this.http
  105. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  106. codigo_instrumento,
  107. info_inversion,
  108. info_instrumento
  109. })
  110. .pipe(
  111. map(response => {
  112. return response;
  113. }),
  114. catchError(this.errorHandl)
  115. );
  116. }
  117. titularizacionCalc(
  118. codigo_instrumento: string,
  119. info_inversion: {
  120. id_tipo_base: number;
  121. id_periodicidad: number;
  122. id_formato_ingreso: number;
  123. },
  124. info_instrumento: {
  125. comision_casa_porcentaje_compra: number;
  126. comision_bolsa_porcentaje_compra: number;
  127. cupon_porcentaje_compra: number;
  128. valor_nominal_compra: number;
  129. costo_transferencia: number;
  130. ytm_vencimiento_porcentaje_compra: number;
  131. precio_vencimiento_compra: number;
  132. precio_compra: number;
  133. fecha_ultima_cupon_compra: string;
  134. fecha_liquidacion_compra: string;
  135. fecha_vencimiento_compra: string;
  136. comision_casa_porcentaje_venta: number;
  137. comision_bolsa_porcentaje_venta: number;
  138. cupon_porcentaje_venta: number;
  139. valor_nominal_venta: number;
  140. ytm_vencimiento_porcentaje_venta: number;
  141. precio_vencimiento_venta: number;
  142. precio_venta: number;
  143. fecha_ultima_cupon_venta: string;
  144. fecha_liquidacion_venta: string;
  145. fecha_vencimiento_venta: string;
  146. fecha_emision: string;
  147. amortizacion_porcentajes: any;
  148. }
  149. ): Observable<boolean> {
  150. return this.http
  151. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  152. codigo_instrumento,
  153. info_inversion,
  154. info_instrumento
  155. })
  156. .pipe(
  157. map(response => {
  158. return response;
  159. }),
  160. catchError(this.errorHandl)
  161. );
  162. }
  163. // Para vcn
  164. vcnCalc(
  165. codigo_instrumento: string,
  166. info_inversion: {
  167. id_tipo_base: number;
  168. id_periodicidad: number;
  169. id_formato_ingreso: number;
  170. },
  171. info_instrumento: {
  172. valor_par: boolean;
  173. valor_nominal: number;
  174. comision_casa_porcentaje: number;
  175. comision_bolsa_porcentaje: number;
  176. rendimiento_bruto: number;
  177. otros_costos: number;
  178. renta_porcentaje: number;
  179. fecha_operacion: string;
  180. fecha_liquidacion: string;
  181. fecha_ultima_cupon: string;
  182. fecha_vencimiento: string;
  183. }
  184. ): Observable<boolean> {
  185. return this.http
  186. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  187. codigo_instrumento,
  188. info_inversion,
  189. info_instrumento
  190. })
  191. .pipe(
  192. map(response => {
  193. return response;
  194. }),
  195. catchError(this.errorHandl)
  196. );
  197. }
  198. // Para pbur
  199. pburCalc(
  200. codigo_instrumento: string,
  201. info_inversion: {
  202. id_tipo_base: number;
  203. id_periodicidad: number;
  204. id_formato_ingreso: number;
  205. },
  206. info_instrumento: {
  207. valor_par: boolean;
  208. valor_nominal: number;
  209. comision_casa_porcentaje: number;
  210. comision_bolsa_porcentaje: number;
  211. rendimiento_bruto: number;
  212. otros_costos: number;
  213. plazo: number;
  214. renta_porcentaje: number;
  215. fecha_operacion: string;
  216. fecha_liquidacion: string;
  217. fecha_ultima_cupon: string;
  218. }
  219. ): Observable<boolean> {
  220. return this.http
  221. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  222. codigo_instrumento,
  223. info_inversion,
  224. info_instrumento
  225. })
  226. .pipe(
  227. map(response => {
  228. return response;
  229. }),
  230. catchError(this.errorHandl)
  231. );
  232. }
  233. dapCalc(
  234. codigo_instrumento: string,
  235. info_inversion: {
  236. id_tipo_base: number;
  237. id_periodicidad: number;
  238. id_formato_ingreso: number;
  239. },
  240. info_instrumento: {
  241. monto_inversion: number;
  242. tasa_porcentaje: number;
  243. renta_porcentaje: number;
  244. plazo: number;
  245. fecha_operacion: string;
  246. //fecha_vencimiento: string;
  247. }
  248. ): Observable<boolean> {
  249. return this.http
  250. .post<any>(`${environment.productionApiUrl}/autocomplete`, {
  251. codigo_instrumento,
  252. info_inversion,
  253. info_instrumento
  254. })
  255. .pipe(
  256. map(response => {
  257. return response;
  258. }),
  259. catchError(this.errorHandl)
  260. );
  261. }
  262. projectionCalc(id: string, proyecciones: any): Observable<boolean> {
  263. return this.http
  264. .put<any>(`${environment.productionApiUrl}/autocomplete/${id}`, {
  265. proyecciones
  266. })
  267. .pipe(
  268. map(response => {
  269. return response;
  270. }),
  271. catchError(this.errorHandl)
  272. );
  273. }
  274. errorHandl(error) {
  275. let errorMessage = "";
  276. if (error.error) {
  277. // Get client-side error
  278. errorMessage = error.error;
  279. } else {
  280. // Get server-side error
  281. errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
  282. }
  283. return throwError(errorMessage);
  284. }
  285. }