public double CalculatePositionCurPnL()
        {
            double tempPnL = 0.0;

            if (Futures == null && Options.Count == 0)
            {
                return(tempPnL);
            }

            if (Futures == null)
            {
                tempPnL += (FixedPnL / Options[0].PriceStep * Options[0].PriceStepValue);
            }
            else
            {
                tempPnL += Futures.Position.CalcCurrentPnLInCurrency(Futures.GetTradeBlotter(), Futures.PriceStep, Futures.PriceStepValue);
                tempPnL += (FixedPnL / Futures.PriceStep * Futures.PriceStepValue);
            }

            foreach (Option opt in Options)
            {
                tempPnL += opt.Position.CalcCurrentPnLInCurrency(opt.GetTradeBlotter(), opt.PriceStep, opt.PriceStepValue);
            }

            return(tempPnL);
        }
Ejemplo n.º 2
0
        public static Futures GetFakeFutures(double enterFutPrice, int futPosition, TradeBlotter blotter, double priceStep, double priceVal)
        {
            Futures fut = new Futures("", DateTime.Now, 0.0, 0.0, priceStep, priceVal);

            fut.AssignTradeBlotter(blotter);
            fut.Position.Quantity   = futPosition;
            fut.Position.EnterPrice = enterFutPrice;
            return(fut);
        }
        public double CalculatePositionPnL()
        {
            double tempPnL = 0.0;

            tempPnL += Futures == null ? 0.0 : Futures.Position.CalcCurrentPnL(Futures.GetTradeBlotter());
            tempPnL += FixedPnL;

            foreach (Option opt in Options)
            {
                tempPnL += opt.Position.CalcCurrentPnL(opt.GetTradeBlotter());
            }

            return(tempPnL);
        }
        public double GetCurrentPrice()
        {
            double price = 0.0;

            if (Options.Count > 0)
            {
                price = Options[0].Futures.GetTradeBlotter().AskPrice;
            }
            else if (Futures != null)
            {
                price = Futures.GetTradeBlotter().AskPrice;
            }

            return(price);
        }
Ejemplo n.º 5
0
 public Option(Futures futures, OptionType optionType, double strike, double marginRequirementCover, double marginRequirementNotCover, double marginRequirementBuyer, string ticker, double priceStep, double priceStepValue, DateTime expirationDate, double remainingDays)
 {
     this.Futures = futures;
     this.MarginRequirementCover    = marginRequirementCover;
     this.MarginRequirementNotCover = marginRequirementNotCover;
     this.MarginRequirementBuyer    = marginRequirementBuyer;
     this.PriceStep      = priceStep;
     this.PriceStepValue = priceStepValue;
     this.ExpirationDate = expirationDate;
     this.Ticker         = ticker;
     this.OptionType     = optionType;
     this.RemainingDays  = Math.Abs(remainingDays) < 0.0001 ? 0.4 : remainingDays; // HARDCORE 0.4
     this.Strike         = strike;
     this.Position       = new Position();
 }
Ejemplo n.º 6
0
        public static Option GetFakeOption(OptionType type, double strike, double enterOptPrice,
                                           double remainingDays, int optPosition, TradeBlotter futBlotter, TradeBlotter optBlotter, double priceStep, double priceVal)
        {
            Futures fut = Futures.GetFakeFutures(0.0, 0, futBlotter, priceStep, priceVal);

            Option option = new Option(fut, type, strike, 0.0, 0.0, 0.0, "", priceStep, priceVal, DateTime.Now, remainingDays);

            option.AssignTradeBlotter(optBlotter);
            option.Position.EnterPrice = enterOptPrice;
            option.Position.Quantity   = optPosition;

            option.UpdateAllGreeksTogether();

            return(option);
        }
        public bool GetCurrentPriceIfPossible(out double price)
        {
            price = 0.0;
            bool result = false;

            if (Options.Count > 0)
            {
                price  = Options[0].Futures.GetTradeBlotter().AskPrice;
                result = true;
            }
            else if (Futures != null)
            {
                price  = Futures.GetTradeBlotter().AskPrice;
                result = true;
            }

            return(result);
        }
 public void AddFutures(Futures futures)
 {
     if (Futures == null)
     {
         Futures = futures;
     }
     else
     {
         if (Futures.Position.Quantity == futures.Position.Quantity * -1)
         {
             FixedPnL += Futures.Position.CloseExistingPosAndGetFixedPnL(futures.Position.EnterPrice);
             Futures   = null;
         }
         else
         {
             Futures.Position.AddToExistingPos(futures.Position.EnterPrice, futures.Position.Quantity);
         }
     }
 }
        private double CalculatePositionsAbsDelta_GO(List <Option> options, Futures fut, double worstPrice, double worstVola)
        {
            double result = 0.0;
            double tempDelta;

            foreach (Option opt in options)
            {
                tempDelta = GreeksCalculator.CalculateDelta(
                    opt.OptionType,
                    worstPrice,
                    opt.Strike, opt.RemainingDays,
                    GreeksCalculator.DAYS_IN_YEAR,
                    worstVola) * opt.Position.Quantity;

                result += tempDelta;
            }

            if (fut != null)
            {
                result += fut.Position.Quantity;
            }

            return(-Math.Abs(result));
        }