// vol public double GetCurOptionPrice( Detail.ProductType callPut, double S, // stock price double X, // exercise price double remainDays, // maturity double r, // interest rate double v) { double d1 = 0.0; double d2 = 0.0; double dBlackScholes = 0.0; double T = (double)(remainDays) / 365.0; d1 = (Math.Log(S / X) + (r + v * v / 2.0) * T) / (v * Math.Sqrt(T)); d2 = d1 - v * Math.Sqrt(T); if (callPut == Detail.ProductType.CallOption) { dBlackScholes = S * CND(d1) - X * Math.Exp(-r * T) * CND(d2); } else if (callPut == Detail.ProductType.PutOption) { dBlackScholes = X * Math.Exp(-r * T) * CND(-d2) - S * CND(-d1); } return dBlackScholes; }
public RawMarketData Register(String code, String name, Detail.ProductType dpt) { Trace.Assert(dpt == Detail.ProductType.KtbSpot); logger.Info("{0}({1}), {2} is registered.", code, name, dpt.ToString()); RawMarketData rmd = new RawMarketData(code, name, dpt); _rmdDict.Add(code, rmd); return rmd; }
public RawMarketData(String code, Detail.ProductType dpt) { Code = code; DPT = dpt; this.BidPrice1 = double.MinValue; this.AskPrice1 = double.MaxValue; this.LastUpdatedTime = DateTime.Now.AddDays(-1); }
// vol public double GetDelta( Detail.ProductType callPut, double S, // stock price double X, // exercise price double remainDays, // maturity double r, // interest rate double v) { double price0 = GetCurOptionPrice(callPut, S - 1.0, X, remainDays, r, v); double price1 = GetCurOptionPrice(callPut, S, X, remainDays, r, v); double price2 = GetCurOptionPrice(callPut, S + 1.0, X, remainDays, r, v); return (price2 - price0) / 2; }
public MonitorEnter_CalFut( StrategyNode node, Detail.ProductType pt, String fut1, String spread, String fut2, ForwardBackward fb) { this._node = node; IMarketDataBoard board = null; switch (pt) { case Detail.ProductType.KospiFuture: board = RmdManager.Ins().KospiFuture; break; case Detail.ProductType.UsdFuture: board = RmdManager.Ins().Future; break; case Detail.ProductType.KtbFuture: board = RmdManager.Ins().Future; break; default: String errorMsg = String.Format("{0} is not valid type", pt); logger.Error(errorMsg); Util.KillWithNotice(errorMsg); break; } _refRmdFut1 = board.GetData(fut1); _refRmdSpread = board.GetData(spread); _refRmdFut2 = board.GetData(fut2); _referenceRmds.Add(_refRmdFut1); _referenceRmds.Add(_refRmdSpread); _referenceRmds.Add(_refRmdFut2); STR_Arb root = node.Root as STR_Arb; _futureAccount = root.FutureAccount; }
public RawMarketData Register(String code, String name, Detail.ProductType dpt) { return RmdManager.Register(code, name, dpt, _rmdDict); }
public static RawMarketData Register(String code, String name, Detail.ProductType dpt, Dictionary<String, RawMarketData> dict) { RawMarketData rmd = new RawMarketData(code, name, dpt); lock (dict) { if (!dict.ContainsKey(code)) { dict.Add(code, rmd); } else { logger.Warn("{0} is already registered", code); } } logger.Debug("{0}({1}), {2} is registered.", code, name, dpt.ToString()); return rmd; }
public RawMarketData Register(String code, String name, Detail.ProductType dpt) { switch (dpt) { case Detail.ProductType.KospiFuture: return KospiFuture.Register(code, name, dpt); case Detail.ProductType.CallOption: return Call.Register(code, name, dpt); case Detail.ProductType.PutOption: return Put.Register(code, name, dpt); default: logger.Warn("This is not implemented. {0}({1}), {2}", code, name, dpt.ToString()); break; } return null; }
List<double> GetAdjustedPriceList( Detail.ProductType dpt, double fixedPriceSum, double fixedPriceAverage, double fixedPriceMax, double fixedPriceMin, List<double> fixedData, double variablePriceSum, double variablePriceAverage, double variablePriceMax, double variablePriceMin, List<double> variableData) { double fixedDiff = fixedPriceMax - fixedPriceMin; double variableDiff = variablePriceMax - variablePriceMin; List<double> ret = new List<double>(); if (fixedDiff == 0 || variableDiff == 0) { ret.AddRange(fixedData); return ret; } for (int i = 0; i < variableData.Count; ++i) { if (DPT == Detail.ProductType.CallOption) { double curRatio = (variableData[i] - variablePriceMin) / (variableDiff); double curAdjustedPrice = fixedPriceMin + curRatio * fixedDiff; ret.Add(curAdjustedPrice); } else { double negativeDiff = variablePriceAverage - variableData[i]; double curAdjustedPrice = fixedPriceAverage + negativeDiff * (fixedDiff / variableDiff); ret.Add(curAdjustedPrice); } } return ret; }
public RawMarketData Register(String code, String name, Detail.ProductType dpt) { switch (dpt) { case Detail.ProductType.KospiFuture: return KospiFuture.Register(code, name, dpt); case Detail.ProductType.KospiFutureSpread: return KospiFuture.Register(code, name, dpt); case Detail.ProductType.CallOption: return Call.Register(code, name, dpt); case Detail.ProductType.PutOption: return Put.Register(code, name, dpt); case Detail.ProductType.Stock: return Stock.Register(code, name, dpt); case Detail.ProductType.ELW: return Elw.Register(code, name, dpt); case Detail.ProductType.KtbFuture: return Future.Register(code, name, dpt); case Detail.ProductType.BondSpot: Trace.Assert(false, "여기서 Register하면 안된다."); break; case Detail.ProductType.KtbSpot: Trace.Assert(false, "여기서 Register하면 안된다."); break; default: logger.Warn("This is not implemented. {0}({1}), {2}", code, name, dpt.ToString()); break; } return null; }
public static RawMarketData Register(String code, String name, Detail.ProductType dpt, Dictionary<String, RawMarketData> dict) { RawMarketData rmd = new RawMarketData(code, name, dpt); lock (dict) { dict.Add(code, rmd); } logger.Info("{0}, {1} is registered.", code, dpt.ToString()); return rmd; }
public long RoundProductCount(long count, Detail.ProductType pt) { if (pt == Detail.ProductType.ELW) { return ElwUtil.RoundElwCount(count); } else if (pt == Detail.ProductType.KtbSpot) { return KtbSpotUtil.Ins().RoundProductCount(count); } // 일단은 주식(5만원 이하 10주 이상)은 없다고 가정한다. return count; }
public RawMarketData Register(String code, String name, Detail.ProductType dpt) { logger.Error("This is not valid."); Util.KillWithNotice("This is not valid."); return null; }
public double GetImpliedVol( Detail.ProductType callPut, double S, // stock price double X, // exercise price int remainDays, // maturity double r, // interest rate double price) { double vol = 0.5; double range = 0.25; for (int i = 0; i < 7; ++i) { double priceCandidate = GetCurOptionPrice(callPut, S, X, remainDays, r, vol); if (priceCandidate > price) { vol = vol - range; } else if (priceCandidate < price) { vol = vol + range; } else { break; } range /= 2.0; } return vol; }
public RawMarketData Register(String code, String name, Detail.ProductType dpt) { logger.Info("{0}({1}), {2} is registered.", code, name, dpt.ToString()); return DataPool.Register(code, name, dpt); }