public void Overwrite(Option o, DirectionT d, CalculationPriceT p) { underlying = o.underlying; symbol = o.symbol; type = (o.type == Option.OptionT.Call) ? PositionT.Call : PositionT.Put; direction = d; switch (p) { case CalculationPriceT.AskBidPrice: if (d == DirectionT.Long && o.price.ask > 0 && !double.IsNaN(o.price.ask)) { price.last = o.price.ask; } else if (d == DirectionT.Short && o.price.bid > 0 && !double.IsNaN(o.price.bid)) { price.last = o.price.bid; } else { price.last = o.price.last; } break; case CalculationPriceT.LastPrice: if (!double.IsNaN(o.price.last)) { price.last = o.price.last; } else { price.last = (o.price.ask + o.price.bid) * 0.5; } break; case CalculationPriceT.MidAskBidPrice: if (!double.IsNaN(o.price.ask) && !double.IsNaN(o.price.bid)) { price.last = (o.price.ask + o.price.bid) * 0.5; } else if (d == DirectionT.Long && o.price.ask > 0 && !double.IsNaN(o.price.ask)) { price.last = o.price.ask; } else if (d == DirectionT.Short && o.price.bid > 0 && !double.IsNaN(o.price.bid)) { price.last = o.price.bid; } else { price.last = o.price.last; } break; } if ((flags & FlagT.ManualPrice) == 0) { price.actual = price.last; flags |= FlagT.ManualPrice; // we set the price only once } if ((flags & FlagT.ManualContractSize) == 0) { contract_size = o.contract_size; } expiration = o.expiration; strike = o.strike; volatility = o.greeks.implied_volatility; greeks = new Greeks(); greeks.implied_volatility = o.greeks.implied_volatility; greeks.delta = contract_size * quantity * o.greeks.delta; greeks.gamma = contract_size * quantity * o.greeks.gamma; greeks.theta = contract_size * quantity * o.greeks.theta; greeks.vega = contract_size * quantity * o.greeks.vega; quote = null; option = o; }
public void Overwrite(Quote q, DirectionT d, CalculationPriceT p) { underlying = q.underlying; symbol = q.underlying; type = PositionT.Underlying; direction = d; switch (p) { case CalculationPriceT.AskBidPrice: if (d == DirectionT.Long && q.price.ask > 0 && !double.IsNaN(q.price.ask)) { price.last = q.price.ask; } else if (d == DirectionT.Short && q.price.bid > 0 && !double.IsNaN(q.price.bid)) { price.last = q.price.bid; } else { price.last = q.price.last; } break; case CalculationPriceT.LastPrice: if (!double.IsNaN(q.price.last)) { price.last = q.price.last; } else { price.last = (q.price.ask + q.price.bid) * 0.5; } break; case CalculationPriceT.MidAskBidPrice: if (!double.IsNaN(q.price.ask) && !double.IsNaN(q.price.bid)) { price.last = (q.price.ask + q.price.bid) * 0.5; } else if (d == DirectionT.Long && q.price.ask > 0 && !double.IsNaN(q.price.ask)) { price.last = q.price.ask; } else if (d == DirectionT.Short && q.price.bid > 0 && !double.IsNaN(q.price.bid)) { price.last = q.price.bid; } else { price.last = q.price.last; } break; } if ((flags & FlagT.ManualPrice) == 0) { price.actual = price.last; } if ((flags & FlagT.ManualContractSize) == 0) { contract_size = 1; } expiration = DateTime.MinValue; strike = double.NaN; volatility = double.NaN; greeks = new Greeks(); greeks.delta = contract_size * quantity; greeks.gamma = 0; greeks.vega = 0; greeks.theta = 0; quote = q; option = null; }