static void Close(ExcelData data) { data.xlWorkBook.Close(true, null, null); data.xlApp.Quit(); releaseObject(data.xlWorkSheet); releaseObject(data.xlWorkBook); releaseObject(data.xlApp); }
static void VerifyMaturityProfit(double strike, ExcelData elw_data, ExcelData option_data) { try { strike = Math.Round(strike, 2); Dictionary<String, Datum> elw_dict = GetElwDict(strike, elw_data); Dictionary<String, Datum> option_dict = GetOptionDict(strike, option_data); double maturity_close_distortion = GetMaturityCloseDistortion(elw_dict, option_dict); double close_distortion = GetCloseDistortion(elw_dict, option_dict); Console.WriteLine(String.Format( "만기일이라면 {0:n0} 만큼이 다음주 수요일 손익에 합산됩니다.", maturity_close_distortion)); Console.WriteLine(String.Format( "만기일이 아니라면 {0:n0} 만큼을 손익에 더해주세요.", close_distortion)); } catch (System.Exception ex) { Console.WriteLine(ex.ToString()); } }
static ExcelData GetExcelData(String path) { Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Open( path, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); ExcelData data = new ExcelData(); data.xlApp = xlApp; data.xlWorkBook = xlWorkBook; data.xlWorkSheet = xlWorkSheet; return data; }
static Dictionary<String, Datum> GetOptionDict(double strike, ExcelData option_data) { Excel.Worksheet ws = option_data.xlWorkSheet; Dictionary<String, Datum> dict = new Dictionary<string, Datum>(); //loop without header row. for (int i = 2; i <= ws.Rows.Count; ++i) { Excel.Range rngTicker = ws.Cells[i, 2] as Excel.Range; if (rngTicker.Value2 == null || rngTicker.Count == 0) { break; } String ticker = rngTicker.Value2.ToString(); Excel.Range rngCount = ws.Cells[i, 4] as Excel.Range; long count = Convert.ToInt64(rngCount.Value2); Excel.Range rngClose = ws.Cells[i, 7] as Excel.Range; double close = Convert.ToDouble(rngClose.Value2); Excel.Range rngMarketValue = ws.Cells[i, 9] as Excel.Range; double market_value = Convert.ToInt64(rngMarketValue.Value2); Excel.Range rngCurPnL = ws.Cells[i, 10] as Excel.Range; double cur_pnl = Convert.ToInt64(rngCurPnL.Value2); Excel.Range rngLongShort = ws.Cells[i, 8] as Excel.Range; String longShortKorean = rngLongShort.Value2.ToString(); TradingDirection long_short = TradingDirection.Short; if (longShortKorean.CompareTo("매수") == 0) { long_short = TradingDirection.Long; } double book_value = market_value + cur_pnl; KospiOptionInfo koi = OptionUtil.GetKOI(ticker); Datum datum = new Datum(); datum.Code = ticker; datum.Close = close; datum.Count = count; datum.BookValue = book_value; datum.MarketValue = market_value; datum.CallPut = koi.CallPut; datum.MaturityMarketValue = GetOptionMaturityMarketValue(datum, strike); datum.LongShort = long_short; dict.Add(ticker, datum); } return dict; }
static Dictionary<String, Datum> GetElwDict(double strike, ExcelData elw_data) { Excel.Worksheet ws = elw_data.xlWorkSheet; Dictionary<String, Datum> dict = new Dictionary<string, Datum>(); //loop without header row. for (int i = 2; i <= ws.Rows.Count; ++i) { Excel.Range rng1 = ws.Cells[i, 1] as Excel.Range; if (rng1.Value2 == null || rng1.Count == 0) { break; } String ticker = rng1.Value2.ToString(); Excel.Range rngCount = ws.Cells[i, 4] as Excel.Range; long count = Convert.ToInt64(rngCount.Value2); Excel.Range rngBookValue = ws.Cells[i, 12] as Excel.Range; long book_value = Convert.ToInt64(rngBookValue.Value2); Excel.Range rngClose = ws.Cells[i, 21] as Excel.Range; double close = Convert.ToDouble(rngClose.Value2); Excel.Range rngMarketValue = ws.Cells[i, 25] as Excel.Range; double market_value = Convert.ToInt64(rngMarketValue.Value2); ElwInfo ei = ElwUtil.GetElwInfo(ticker); Datum datum = new Datum(); datum.Code = ticker; datum.Close = close; datum.Count = count; datum.BookValue = book_value; datum.MarketValue = market_value; datum.CallPut = ei.CallPut; datum.MaturityMarketValue = GetElwMaturityMarketValue(datum, strike); datum.LongShort = TradingDirection.Long; dict.Add(ticker, datum); } return dict; }