Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Text.RegularExpressions;
  7. using System.Globalization;
  8.  
  9. namespace EKB.FASWS.K4000
  10. {
  11. public partial class BloombergDataImport
  12. {
  13. private class Blmb_MDuration
  14. {
  15. public DateTime? Date { get; set; }
  16. public string SECURITIES { get; set; }
  17. public string ERROR_CODE { get; set; }
  18. public decimal? DUR_ADJ_MID { get; set; }
  19.  
  20. public Blmb_MDuration(DateTime? date, string securities, string error_code, decimal? dur_adj_mid)
  21. {
  22. Date = date;
  23. SECURITIES = securities;
  24. ERROR_CODE = error_code;
  25. DUR_ADJ_MID = dur_adj_mid;
  26. }
  27. }
  28.  
  29. private class Blmb_FundBondAmt
  30. {
  31. public DateTime? Date { get; set; }
  32. public string SECURITIES { get; set; }
  33. public string ERROR_CODE { get; set; }
  34. public decimal? FUND_TOTAL_ASSETS { get; set; }
  35. public decimal? AMT_OUTSTANDING { get; set; }
  36.  
  37. public Blmb_FundBondAmt(DateTime? date, string securities, string error_code, decimal? fund_total_assets, decimal? amt_outstanding)
  38. {
  39. Date = date;
  40. SECURITIES = securities;
  41. ERROR_CODE = error_code;
  42. FUND_TOTAL_ASSETS = fund_total_assets;
  43. AMT_OUTSTANDING = amt_outstanding;
  44. }
  45. }
  46.  
  47. private class Blmb_KainosYield
  48. {
  49. public DateTime? Date { get; set; }
  50. public string SECURITIES { get; set; }
  51. public string ERROR_CODE { get; set; }
  52. public decimal? MHIS_CLOSE_ON_PX_1_P { get; set; }
  53. public decimal? PX_LAST { get; set; }
  54. public decimal? MHIS_CLOSE_ON_PX_1_Y { get; set; }
  55. public string CRNCY { get; set; }
  56.  
  57. public Blmb_KainosYield(DateTime? date, string securities, string error_code, decimal? mhis_close_on_px_1_p, decimal? px_last,
  58. decimal? mhis_close_on_px_1_y, string currency)
  59. {
  60. Date = date;
  61. SECURITIES = securities;
  62. ERROR_CODE = error_code;
  63. MHIS_CLOSE_ON_PX_1_P = mhis_close_on_px_1_p;
  64. PX_LAST = px_last;
  65. MHIS_CLOSE_ON_PX_1_Y = mhis_close_on_px_1_y;
  66. CRNCY = currency;
  67. }
  68. }
  69.  
  70. private class Blmb_LygInd
  71. {
  72. public DateTime? Date { get; set; }
  73. public string SECURITIES { get; set; }
  74. public string ERROR_CODE { get; set; }
  75. public decimal? MHIS_CLOSE_ON_PX_1_P { get; set; }
  76.  
  77. public Blmb_LygInd(DateTime? date, string securities, string error_code, decimal? mhis_close_on_px_1_p)
  78. {
  79. Date = date;
  80. SECURITIES = securities;
  81. ERROR_CODE = error_code;
  82. MHIS_CLOSE_ON_PX_1_P = mhis_close_on_px_1_p;
  83. }
  84. }
  85.  
  86. private class Blmb_Interest
  87. {
  88. public DateTime? Date { get; set; }
  89. public string SECURITIES { get; set; }
  90. public string ERROR_CODE { get; set; }
  91. public decimal? INT_ACC { get; set; }
  92.  
  93. public Blmb_Interest(DateTime? date, string securities, string error_code, decimal? int_acc)
  94. {
  95. Date = date;
  96. SECURITIES = securities;
  97. ERROR_CODE = error_code;
  98. INT_ACC = int_acc;
  99. }
  100. }
  101.  
  102. private class Blmb_SaliuReitingai
  103. {
  104. public DateTime? Date { get; set; }
  105. public string SECURITIES { get; set; }
  106. public string ERROR_CODE { get; set; }
  107. public string RTG_SP_LT_LC_ISSUER_CREDIT { get; set; }
  108. public string RTG_SP_LT_FC_ISSUER_CREDIT { get; set; }
  109. public string RTG_MDY_LT_LC_DEBT_RATING { get; set; }
  110. public string RTG_MDY_LT_FC_DEBT_RATING { get; set; }
  111. public string RTG_FITCH_LT_LC_DEBT { get; set; }
  112. public string RTG_FITCH_LT_FC_DEBT { get; set; }
  113.  
  114. public Blmb_SaliuReitingai(DateTime? date, string securities, string error_code, string rtg_sp_lt_lc_issuer_credit, string rtg_sp_lt_fc_issuer_credit,
  115. string rtg_mdy_lt_lc_debt_rating, string rtg_mdy_lt_fc_debt_rating, string rtg_fitch_lt_lc_debt, string rtg_fitch_lt_fc_debt)
  116. {
  117. Date = date;
  118. SECURITIES = securities;
  119. ERROR_CODE = error_code;
  120. RTG_SP_LT_LC_ISSUER_CREDIT = rtg_sp_lt_lc_issuer_credit;
  121. RTG_SP_LT_FC_ISSUER_CREDIT = rtg_sp_lt_fc_issuer_credit;
  122. RTG_MDY_LT_LC_DEBT_RATING = rtg_mdy_lt_lc_debt_rating;
  123. RTG_MDY_LT_FC_DEBT_RATING = rtg_mdy_lt_fc_debt_rating;
  124. RTG_FITCH_LT_LC_DEBT = rtg_fitch_lt_lc_debt;
  125. RTG_FITCH_LT_FC_DEBT = rtg_fitch_lt_fc_debt;
  126. }
  127. }
  128.  
  129. private class Blmb_BondReitingai
  130. {
  131. public DateTime? Date { get; set; }
  132. public string SECURITIES { get; set; }
  133. public string ERROR_CODE { get; set; }
  134. public string RTG_SP { get; set; }
  135. public string RTG_MOODY { get; set; }
  136. public string RTG_FITCH { get; set; }
  137.  
  138. public Blmb_BondReitingai(DateTime? date, string securities, string error_code, string rtg_sp, string rtg_moody, string rtg_fitch)
  139. {
  140. Date = date;
  141. SECURITIES = securities;
  142. ERROR_CODE = error_code;
  143. RTG_SP = rtg_sp;
  144. RTG_MOODY = rtg_moody;
  145. RTG_FITCH = rtg_fitch;
  146. }
  147. }
  148.  
  149. #region Private methods
  150.  
  151. private IEnumerable<string> ReadFile(string path, out DateTime? date)
  152. {
  153. string[] lines = new string[0];
  154. date = DateTime.Today;
  155. List<string> selectedLines = new List<string>();
  156. bool dataStarted = false;
  157.  
  158. try
  159. {
  160. lines = File.ReadAllLines(path);
  161. foreach (string line in lines)
  162. {
  163. if (Regex.IsMatch(line, "END-OF-DATA"))
  164. dataStarted = false;
  165.  
  166. if (Regex.IsMatch(line, "RUNDATE"))
  167. {
  168. string dateLine = line.Substring(8);
  169. date = DateTime.ParseExact(dateLine, "yyyyMMdd", null);
  170. }
  171.  
  172. if (dataStarted && !Regex.IsMatch(line, "SECURITIES") && !string.IsNullOrWhiteSpace(line))
  173. selectedLines.Add(line);
  174.  
  175. if (Regex.IsMatch(line, "START-OF-DATA"))
  176. dataStarted = true;
  177. }
  178. }
  179. catch (Exception ex)
  180. {
  181. sf.log.regLog(ex.ToString());
  182. }
  183.  
  184. return selectedLines.AsEnumerable();
  185. }
  186.  
  187. private List<Blmb_FundBondAmt> GetFundBondAmtValues()
  188. {
  189. List<Blmb_FundBondAmt> list = new List<Blmb_FundBondAmt>();
  190. try
  191. {
  192. DateTime? date;
  193. //string path = sf.configSQL.GetString("global", "Blmb_FundBondAmt_Path", "default path");
  194. string path = @"E:\Users\martynas\Desktop\Martynui\Fund_Bond.out";
  195. var lines = ReadFile(path, out date);
  196. foreach (string line in lines)
  197. {
  198. decimal parsing1;
  199. decimal parsing2;
  200. decimal? amt_outstanding = null;
  201. decimal? fundTotalAssets = null;
  202.  
  203. string[] values = line.Split(':');
  204. values[0] = values[0].Replace("\"", string.Empty);
  205. values[3] = Regex.Replace(values[3], @"\s+", string.Empty);
  206. values[4] = Regex.Replace(values[4], @"\s+", string.Empty);
  207. decimal.TryParse(values[3], System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out parsing1);
  208. if (parsing1 != 0)
  209. fundTotalAssets = parsing1;
  210.  
  211. decimal.TryParse(values[4], System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out parsing2);
  212. if (parsing2 != 0)
  213. amt_outstanding = parsing2;
  214.  
  215. list.Add(new Blmb_FundBondAmt(date, values[0], values[1], fundTotalAssets, amt_outstanding));
  216. }
  217. }
  218. catch (Exception ex)
  219. {
  220. sf.log.regLog(ex.ToString());
  221. }
  222.  
  223. return list;
  224. }
  225.  
  226. private List<Blmb_KainosYield> GetKainosYieldValues()
  227. {
  228. List<Blmb_KainosYield> list = new List<Blmb_KainosYield>();
  229. try
  230. {
  231. DateTime? date;
  232. //string path = sf.configSQL.GetString("global", "Blmb_KainosYield_Path", "default path");
  233. string path = @"E:\Users\martynas\Desktop\Martynui\Kainos_yield.out";
  234. var lines = ReadFile(path, out date);
  235. foreach (string line in lines)
  236. {
  237. decimal parsing1;
  238. decimal parsing2;
  239. decimal parsing3;
  240. decimal? MHIS_CLOSE_ON_PX_1_P = null;
  241. decimal? PX_LAST = null;
  242. decimal? MHIS_CLOSE_ON_PX_1_Y = null;
  243.  
  244. string[] values = line.Split(':');
  245.  
  246. values[0] = values[0].Replace("\"", string.Empty);
  247. values[6] = values[6].Replace("\"", string.Empty);
  248.  
  249. values[3] = Regex.Replace(values[3], @"\s+", string.Empty);
  250. values[4] = Regex.Replace(values[4], @"\s+", string.Empty);
  251. values[5] = Regex.Replace(values[5], @"\s+", string.Empty);
  252.  
  253. decimal.TryParse(values[3], System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out parsing1);
  254. if (parsing1 != 0)
  255. MHIS_CLOSE_ON_PX_1_P = parsing1;
  256.  
  257. decimal.TryParse(values[4], System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out parsing2);
  258. if (parsing2 != 0)
  259. PX_LAST = parsing2;
  260.  
  261. decimal.TryParse(values[5], System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out parsing3);
  262. if (parsing3 != 0)
  263. MHIS_CLOSE_ON_PX_1_Y = parsing2;
  264.  
  265. list.Add(new Blmb_KainosYield(date, values[0], values[1], MHIS_CLOSE_ON_PX_1_P, PX_LAST, MHIS_CLOSE_ON_PX_1_Y, values[6]));
  266. }
  267. }
  268. catch (Exception ex)
  269. {
  270. sf.log.regLog(ex.ToString());
  271. }
  272.  
  273. return list;
  274. }
  275.  
  276. private List<Blmb_LygInd> GetLygIndValues()
  277. {
  278. List<Blmb_LygInd> list = new List<Blmb_LygInd>();
  279. try
  280. {
  281. DateTime? date;
  282. //string path = sf.configSQL.GetString("global", "Blmb_LygInd_Path", "default path");
  283. string path = @"E:\Users\martynas\Desktop\Martynui\Lyginamieji_indeksai.out";
  284. var lines = ReadFile(path, out date);
  285. foreach (string line in lines)
  286. {
  287. decimal parsing1;
  288. decimal? MHIS_CLOSE_ON_PX_1_P = null;
  289.  
  290. string[] values = line.Split(':');
  291.  
  292. values[0] = values[0].Replace("\"", string.Empty);
  293. values[3] = Regex.Replace(values[3], @"\s+", string.Empty);
  294.  
  295. decimal.TryParse(values[3], System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out parsing1);
  296. if (parsing1 != 0)
  297. MHIS_CLOSE_ON_PX_1_P = parsing1;
  298.  
  299. list.Add(new Blmb_LygInd(date, values[0], values[1], MHIS_CLOSE_ON_PX_1_P));
  300. }
  301. }
  302. catch (Exception ex)
  303. {
  304. sf.log.regLog(ex.ToString());
  305. }
  306.  
  307. return list;
  308. }
  309.  
  310. private List<Blmb_MDuration> GetMDurationValues()
  311. {
  312. List<Blmb_MDuration> list = new List<Blmb_MDuration>();
  313. try
  314. {
  315. DateTime? date;
  316. //string path = sf.configSQL.GetString("global", "Blmb_MDuration_Path", "default path");
  317. string path = @"E:\Users\martynas\Desktop\Martynui\MDuration.out";
  318. var lines = ReadFile(path, out date);
  319. foreach (string line in lines)
  320. {
  321. decimal parsing1;
  322. decimal? DUR_ADJ_MID = null;
  323.  
  324. string[] values = line.Split(':');
  325.  
  326. values[0] = values[0].Replace("\"", string.Empty);
  327. values[3] = Regex.Replace(values[3], @"\s+", string.Empty);
  328.  
  329. decimal.TryParse(values[3], System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out parsing1);
  330. if (parsing1 != 0)
  331. DUR_ADJ_MID = parsing1;
  332.  
  333. list.Add(new Blmb_MDuration(date, values[0], values[1], DUR_ADJ_MID));
  334. }
  335. }
  336. catch (Exception ex)
  337. {
  338. sf.log.regLog(ex.ToString());
  339. }
  340.  
  341. return list;
  342. }
  343.  
  344. private List<Blmb_Interest> GetInterestValues()
  345. {
  346. List<Blmb_Interest> list = new List<Blmb_Interest>();
  347. try
  348. {
  349. DateTime? date;
  350. //string path = sf.configSQL.GetString("global", "Blmb_Interest_Path", "default path");
  351. string path = @"E:\Users\martynas\Desktop\Martynui\Palūkanos.out";
  352. var lines = ReadFile(path, out date);
  353. foreach (string line in lines)
  354. {
  355. decimal parsing1;
  356. decimal? INT_ACC = null;
  357.  
  358. string[] values = line.Split(':');
  359.  
  360. values[0] = values[0].Replace("\"", string.Empty);
  361. values[3] = Regex.Replace(values[3], @"\s+", string.Empty);
  362.  
  363. decimal.TryParse(values[3], System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out parsing1);
  364. if (parsing1 != 0)
  365. INT_ACC = parsing1;
  366.  
  367. list.Add(new Blmb_Interest(date, values[0], values[1], INT_ACC));
  368. }
  369. }
  370. catch (Exception ex)
  371. {
  372. sf.log.regLog(ex.ToString());
  373. }
  374. return list;
  375. }
  376.  
  377. private List<Blmb_SaliuReitingai> GetSaliuReitingaiValues()
  378. {
  379. List<Blmb_SaliuReitingai> list = new List<Blmb_SaliuReitingai>();
  380. try
  381. {
  382. DateTime? date;
  383. //string path = sf.configSQL.GetString("global", "Blmb_SaliuReitingai_Path", "default path");
  384. string path = @"E:\Users\martynas\Desktop\Martynui\Šalių_reitingai.out";
  385. var lines = ReadFile(path, out date);
  386. foreach (string line in lines)
  387. {
  388. string[] values = line.Split(':');
  389.  
  390. values[0] = values[0].Replace("\"", string.Empty);
  391. values[3] = values[3].Replace("\"", string.Empty);
  392. values[4] = values[4].Replace("\"", string.Empty);
  393. values[5] = values[5].Replace("\"", string.Empty);
  394. values[6] = values[6].Replace("\"", string.Empty);
  395. values[7] = values[7].Replace("\"", string.Empty);
  396. values[8] = values[8].Replace("\"", string.Empty);
  397.  
  398. list.Add(new Blmb_SaliuReitingai(date, values[0], values[1], values[3], values[4], values[5], values[6], values[7], values[8]));
  399. }
  400. }
  401. catch (Exception ex)
  402. {
  403. sf.log.regLog(ex.ToString());
  404. }
  405. return list;
  406. }
  407.  
  408. private List<Blmb_BondReitingai> GetBondReitingaiValues()
  409. {
  410. List<Blmb_BondReitingai> list = new List<Blmb_BondReitingai>();
  411. try
  412. {
  413. DateTime? date;
  414. //string path = sf.configSQL.GetString("global", "Blmb_BondReitingai_Path", "default path");
  415. string path = @"E:\Users\martynas\Desktop\Martynui\VP_Reitingai.out";
  416. var lines = ReadFile(path, out date);
  417. foreach (string line in lines)
  418. {
  419. string[] values = line.Split(':');
  420.  
  421. values[0] = values[0].Replace("\"", string.Empty);
  422. values[3] = values[3].Replace("\"", string.Empty);
  423. values[4] = values[4].Replace("\"", string.Empty);
  424. values[5] = values[5].Replace("\"", string.Empty);
  425.  
  426. list.Add(new Blmb_BondReitingai(date, values[0], values[1], values[3], values[4], values[5]));
  427. }
  428. }
  429. catch (Exception ex)
  430. {
  431. sf.log.regLog(ex.ToString());
  432. }
  433. return list;
  434. }
  435. #endregion
  436.  
  437. }
  438. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement