void CreateHedgingTradingData(MarketData md) { int curPositionSize = 0; double curGrossDelta = 0; double curHedgingFactor = EquityVolPredefinedVariables.FullHedgingFactor; double prevHedgingFactor = 0; double prevPrice = 0; int lastHedgedIndex = 0; for (int index = 0; index < md.GetTotalCount(); index++) { bool bHegingTest = false; DOHLC dohlc = md.GetByIndex(index); DateTime curDate = dohlc.CurDate; if (curDate.DayOfWeek == DayOfWeek.Saturday || curDate.DayOfWeek == DayOfWeek.Sunday) { continue; } double curPrice = dohlc.OHLC.Close; if (prevPrice != 0 && curPrice != 0) { double upDownRate = MathUtil.GetUpDownRate(prevPrice, curPrice); if (_upDownRates.Count == _volN) { _upDownRates.Dequeue(); } _upDownRates.Enqueue(upDownRate); } if (_bMATrendTester) { _leadingMA.Add(curPrice); _baseMA.Add(curPrice); //if(prevHedgingFactor == EquityVolPredefinedVariables.OverHedgingFactor // && MathUtil.GetUpDownRate(_nonNeutralHedgingEntryPrice, prevPrice) > 0.02) //{ // curHedgingFactor = EquityVolPredefinedVariables.FullHedgingFactor; //} //if (prevHedgingFactor == EquityVolPredefinedVariables.UnderHedgingFactor // && MathUtil.GetUpDownRate(_nonNeutralHedgingEntryPrice, prevPrice) < -0.02) //{ // curHedgingFactor = EquityVolPredefinedVariables.FullHedgingFactor; //} if (MathUtil.GetUpDownRate(prevPrice, curPrice) > -0.02) { curHedgingFactor = GetCurTrendHedgingFactor(); } //bHegingTest = (curHedgingFactor != prevHedgingFactor) || // ((lastHedgedIndex + (int)(EquityVolPredefinedVariables.RebalancingPeriod / 2) <= index) // && index % (_hedingInterval) == 0); bHegingTest = (curHedgingFactor != prevHedgingFactor) || (index % (_hedingInterval) == 0 && (lastHedgedIndex + (2 * _hedingInterval) <= index)); //bHegingTest = (curHedgingFactor != prevHedgingFactor); //bHegingTest = (curHedgingFactor != prevHedgingFactor) || // (lastHedgedIndex + (int)(EquityVolPredefinedVariables.RebalancingPeriod / 2) <= index); } else { bHegingTest = index % (2 * _hedingInterval) == 0; } if (bHegingTest) { if (_grossDeltas == null) { curGrossDelta = curHedgingFactor * 1.0; curPositionSize = GetGHedgingPositonSize(curGrossDelta, curPrice, _baseInvest); prevHedgingFactor = curHedgingFactor; lastHedgedIndex = index; } else if (_grossDeltas.ContainsKey(curDate)) { curGrossDelta = curHedgingFactor * _grossDeltas[curDate]; curPositionSize = GetGHedgingPositonSize(curGrossDelta, curPrice, _baseInvest); prevHedgingFactor = curHedgingFactor; lastHedgedIndex = index; } } if (curDate >= _startDate) { RawTradingData tradingData = new RawTradingData(MarketDataSetKey.KospiFuture, curDate, curPrice, curPositionSize); tradingData.AddDelta(curGrossDelta); _tradingDataList.Add(tradingData); } prevPrice = curPrice; } }
void CreateTradingData(MarketData md) { int curPositionSize = 0; double curFactor = 0; double entryPrice = 0; for (int index = 0; index < md.GetTotalCount(); index++) { double prevFactor = curFactor; DOHLC dohlc = md.GetByIndex(index); DateTime curDate = dohlc.CurDate; double curPrice = dohlc.OHLC.Close; if (_bMATrendTester) { _leadingMA.Add(curPrice); _baseMA.Add(curPrice); } double curLeadingMA = _leadingMA.GetCurMA(); double curBaseMA = _baseMA.GetCurMA(); //curFactor = GetTradingFactorWith3Value(curPrice, curLeadingMA, curBaseMA, curFactor, entryPrice); curFactor = GetMASpreadSwitchedTradingFactor(curPrice, curLeadingMA, curBaseMA, curFactor); //curFactor = GetMASpreadTradingFactor(maSpread, curFactor); if (!IsAvailableTimeRange(curDate, curFactor)) { curFactor = kNeutralFactor; //AddMATrendTester(10, 50); } //if (TestLossCut(prevFactor, entryPrice, curPrice)) //{ // curFactor = kNeutralFactor; //} curPositionSize = (int) curFactor; if (prevFactor == kNeutralFactor && curFactor != kNeutralFactor) { entryPrice = curPrice; } if (prevFactor < curFactor) { curPrice = curPrice + 0.025; } else if (prevFactor > curFactor) { curPrice = curPrice - 0.025; } RawTradingData tradingData = new RawTradingData(MarketDataSetKey.KospiFuture, curDate, curPrice, curPositionSize); _tradingDataList.Add(tradingData); } }
void CreateHedgingTradingData(MarketData md) { int curPositionSize = 0; double curGrossDelta = 0; double curHedgingFactor = EquityVolPredefinedVariables.FullHedgingFactor; double prevHedgingFactor = 0; double prevPrice = 0; int lastHedgedIndex = 0; for (int index = 0; index < md.GetTotalCount(); index++) { DOHLC dohlc = md.GetByIndex(index); DateTime curDate = dohlc.CurDate; if (curDate.DayOfWeek == DayOfWeek.Saturday || curDate.DayOfWeek == DayOfWeek.Sunday) { continue; } double curPrice = dohlc.OHLC.Close; if (prevPrice != 0 && curPrice != 0) { _leadingMA.Add(curPrice); _baseMA.Add(curPrice); double upDownRate = MathUtil.GetUpDownRate(prevPrice, curPrice); if (_upDownRates.Count == _volN) { _upDownRates.Dequeue(); } _upDownRates.Enqueue(upDownRate); } //if (MathUtil.GetUpDownRate(prevPrice, curPrice) > -0.02) //{ curHedgingFactor = GetCurTrendHedgingFactor(); //} if (curHedgingFactor != prevHedgingFactor) { if (_grossDeltas == null) { curGrossDelta = curHedgingFactor * 1.0; curPositionSize = GetGHedgingPositonSize(curGrossDelta, curPrice, _baseInvest); prevHedgingFactor = curHedgingFactor; lastHedgedIndex = index; } else if (_grossDeltas.ContainsKey(curDate)) { curGrossDelta = curHedgingFactor * _grossDeltas[curDate]; curPositionSize = GetGHedgingPositonSize(curGrossDelta, curPrice, _baseInvest); prevHedgingFactor = curHedgingFactor; lastHedgedIndex = index; } } if (curDate >= _startDate) { RawTradingData tradingData = new RawTradingData(MarketDataSetKey.KospiFuture, curDate, curPrice, curPositionSize); tradingData.AddDelta(curGrossDelta); _tradingDataList.Add(tradingData); } prevPrice = curPrice; } }