Example #1
0
        public void SetPosition(OOMigrationLib.Global.Position position)
        {
            // new position ?
            if (position.index == -1)
            {
                position.index = AddPosition().index;
            }

            // get position row
            OptionsOracle.Data.OptionsSet.PositionsTableRow row = core.PositionsTable.FindByIndex(position.index);
            if (row == null)
            {
                return;
            }

            row.Enable = position.enable;

            row.Type = ((position.direction == OOMigrationLib.Global.Position.DirectionT.Short) ? "Short " : "Long ") +
                       ((position.type == OOMigrationLib.Global.Position.PositionT.Underlying) ? "Stock" :
                        ((position.type == OOMigrationLib.Global.Position.PositionT.Call) ? "Call" : "Put"));

            row.Symbol = position.symbol;

            row.Strike     = position.strike;
            row.Expiration = position.expiration;
            row.Quantity   = position.quantity;

            row.Price     = position.price.actual;
            row.LastPrice = position.price.last;

            row.ToOpen = (position.operation == OOMigrationLib.Global.Position.OperationT.Open);

            row.Commission = position.commission;
            row.NetMargin  = position.margin;
            row.Interest   = position.interest;
            row.Investment = position.investment;

            row.MktValue = position.value.purchase;

            row.Flags = position.flags;

            row.Exposure = position.exposure;
            row.Coverage = position.coverage;

            row.Volatility = position.volatility;

            row.ImpliedVolatility = position.greeks.implied_volatility;
            row.Delta             = position.greeks.delta;
            row.Gamma             = position.greeks.gamma;
            row.Vega  = position.greeks.vega;
            row.Theta = position.greeks.theta;

            row.AcceptChanges();

            // update position and cross-position values
            core.sm.CalculatePosition(position.index, "Symbol", false);
            CalculateAll();
        }
Example #2
0
        public void DeletePosition(OOMigrationLib.Global.Position position)
        {
            // get position row
            OptionsOracle.Data.OptionsSet.PositionsTableRow row = core.PositionsTable.FindByIndex(position.index);
            if (row == null)
            {
                return;
            }

            // delete position row
            row.Delete();
            core.PositionsTable.AcceptChanges();
        }
Example #3
0
        // strategy positions data
        public List <OOMigrationLib.Global.Position> GetPositionList()
        {
            List <OOMigrationLib.Global.Position> li = new List <OOMigrationLib.Global.Position>();

            foreach (OptionsOracle.Data.OptionsSet.PositionsTableRow row in core.PositionsTable.Rows)
            {
                OOMigrationLib.Global.Position p = GetPosition(row.Index);
                if (p != null && !string.IsNullOrEmpty(p.symbol))
                {
                    li.Add(p);
                }
            }

            return(li);
        }
Example #4
0
        // position data
        public OOMigrationLib.Global.Position GetPosition(int index)
        {
            OptionsOracle.Data.OptionsSet.PositionsTableRow row = core.PositionsTable.FindByIndex(index);
            if (row == null)
            {
                return(null);
            }

            OOMigrationLib.Global.Position position = new OOMigrationLib.Global.Position();

            position.index = row.Index;

            if (row.IsTypeNull() || row.IsSymbolNull())
            {
                return(position);
            }

            if (row.Type.Contains("Short"))
            {
                position.direction = OOMigrationLib.Global.Position.DirectionT.Short;
            }
            else
            {
                position.direction = OOMigrationLib.Global.Position.DirectionT.Long;
            }

            if (row.Type.Contains("Stock"))
            {
                position.type = OOMigrationLib.Global.Position.PositionT.Underlying;
            }
            else if (row.Type.Contains("Call"))
            {
                position.type = OOMigrationLib.Global.Position.PositionT.Call;
            }
            else if (row.Type.Contains("Put"))
            {
                position.type = OOMigrationLib.Global.Position.PositionT.Put;
            }
            else
            {
                return(null);
            }

            position.enable = row.Enable;
            position.symbol = row.Symbol;

            position.strike     = row.Strike;
            position.expiration = row.Expiration;
            position.quantity   = row.Quantity;

            position.price.actual = row.Price;
            position.price.last   = row.LastPrice;

            if (row.ToOpen)
            {
                position.operation = OOMigrationLib.Global.Position.OperationT.Open;
            }
            else
            {
                position.operation = OOMigrationLib.Global.Position.OperationT.Close;
            }

            position.commission = row.Commission;
            position.margin     = row.NetMargin;
            position.interest   = row.Interest;
            position.investment = row.Investment;

            position.value.purchase = row.MktValue;
            position.value.market   = 0;

            position.flags = row.Flags;

            position.exposure = row.Exposure;
            position.coverage = row.Coverage;

            position.volatility = row.Volatility;

            position.greeks = new OOMigrationLib.Global.Greeks();

            position.greeks.implied_volatility = row.ImpliedVolatility;
            position.greeks.delta = row.Delta;
            position.greeks.gamma = row.Gamma;
            position.greeks.vega  = row.Vega;
            position.greeks.theta = row.Theta;

            return(position);
        }
 // single position greeks
 public OOMigrationLib.Global.Greeks GetPositionGreeks(OOMigrationLib.Global.Position position, OOMigrationLib.Global.Quote quote, double at_underlying_price, DateTime at_date, double at_volatility)
 {
     return(Convert.GreeksToGreeksNG(core, core.om.GetPositionGreeks(position.index, at_underlying_price, at_date, at_volatility)));
 }
 // single position current return (return if closed now)
 public double GetPositionCurrentReturn(OOMigrationLib.Global.Position position)
 {
     return(core.om.GetPositionCurrentReturn(position.index));
 }
 // single position return
 public double GetPositionReturn(OOMigrationLib.Global.Position position, OOMigrationLib.Global.Quote quote, double at_underlying_price, DateTime at_date, double at_volatility)
 {
     return(core.om.GetPositionReturn(position.index, at_underlying_price, at_date, at_volatility));
 }