Ejemplo n.º 1
0
        // returns true on success
        public bool RunTest()
        {
            try
            {
                CurrentMarketValue = NewMarketValue = 0;

                foreach (AccountDataSet.StressTestRow row in StressTestDataTable)
                {
                    if (row.IsOption && (row.Current_Position != 0))
                    {
                        double daystoexpiration = row.ExpirationDate.AddHours(16).ToOADate() - DateTime.Now.ToOADate();
                        if (daystoexpiration > 0)
                        {
                            AccountDataSet.IndicesRow index = Indices.FindBySymbol(row.UnderlyingSymbol);
                            if (index != null)
                            {
                                row.Current_Theoretical = m_model.GetPrice((row.OptionType == "Call") ? OptionTypeEnum.CallOption : OptionTypeEnum.PutOption,
                                                                           index.LastPrice,
                                                                           (double)row.StrikePrice,
                                                                           daystoexpiration / 365,
                                                                           RiskFreeInterestRate / 100,
                                                                           row.ImpliedVol / 100);

                                row.New_Theoretical = m_model.GetPrice((row.OptionType == "Call") ? OptionTypeEnum.CallOption : OptionTypeEnum.PutOption,
                                                                       index.LastPrice * (1 + ChangeInMarket),
                                                                       (double)row.StrikePrice,
                                                                       daystoexpiration / 365,
                                                                       RiskFreeInterestRate / 100,
                                                                       row.ImpliedVol * (1 + ChangeInVolatility) / 100);
                            }
                        }
                    }
                    else
                    {
                        row.Current_Theoretical = row.Current_Price;
                        row.New_Theoretical     = row.Current_Price * (1 + ChangeInMarket);
                    }

                    if (!row.IsCurrent_TheoreticalNull())
                    {
                        row.Current_Market_Value = row.Current_Position * row.Current_Theoretical * row.Multiplier;
                        CurrentMarketValue      += row.Current_Market_Value;

                        row.New_Market_Value = row.Current_Position * row.New_Theoretical * row.Multiplier;
                        NewMarketValue      += row.New_Market_Value;

                        row.P_and_L = row.New_Market_Value - row.Current_Market_Value;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public PositionGridTable(AccountDataSet.IndicesRow index, double strikeIncrement)
        {
            m_indexSymbol         = index.Symbol;
            m_strikeIncrement     = (decimal)strikeIncrement;
            m_atmStrike           = (decimal)(Math.Round(index.LastPrice / strikeIncrement) * strikeIncrement);
            m_down10PercentStrike = (decimal)(Math.Round(index.LastPrice * .9 / strikeIncrement) * strikeIncrement);
            m_down2PercentStrike  = (decimal)(Math.Round(index.LastPrice * .98 / strikeIncrement) * strikeIncrement);

            Columns.Add(new DataColumn("Strike", typeof(PositionGridStrike)));
            PrimaryKey = new DataColumn[1] {
                Columns[0]
            };
        }
        private static AccountDataSet.IndicesDataTable BuildIndicesTable(SentoniServiceReference.Portfolio portfolio)
        {
            AccountDataSet.IndicesDataTable indicesTable = new AccountDataSet.IndicesDataTable();

            if (portfolio.Indices != null)
            {
                foreach (SentoniServiceReference.Index indexRow in portfolio.Indices)
                {
                    AccountDataSet.IndicesRow newRow = indicesTable.NewIndicesRow();

                    newRow.Symbol           = indexRow.Symbol;
                    newRow.Weight           = indexRow.Weight;
                    newRow.TargetValue      = indexRow.TargetValue;
                    newRow.TotalDeltaPct    = indexRow.TotalDeltaPct;
                    newRow.CallDeltaPct     = indexRow.CallDeltaPct;
                    newRow.PutDeltaPct      = indexRow.PutDeltaPct;
                    newRow.FaceValuePutsPct = indexRow.FaceValuePutsPct;
                    newRow.ShortPct         = indexRow.ShortPct;
                    newRow.TimePremium      = indexRow.TimePremium;
                    newRow.Caks             = indexRow.Caks;
                    newRow.GammaPct         = indexRow.GammaPct;
                    newRow.ThetaAnnualized  = indexRow.ThetaAnnualized;
                    newRow.DeltasToTrade    = indexRow.DeltasToTrade;
                    if (portfolio.Indices.Length > 2)
                    {
                        newRow.PutsToRebalance = indexRow.PutsToRebalance;
                    }
                    newRow.PutsToTrade = indexRow.PutsToTrade;

                    if (indexRow.LastPrice.HasValue)
                    {
                        newRow.LastPrice = indexRow.LastPrice.Value;
                    }
                    if (indexRow.PrevClose.HasValue)
                    {
                        newRow.PrevClose = indexRow.PrevClose.Value;
                    }

                    indicesTable.Rows.Add(newRow);
                }
            }
            return(indicesTable);
        }
Ejemplo n.º 4
0
        private void FormPutCalculator_Load(object sender, EventArgs e)
        {
            try
            {
                m_loadedSuccessfully = true;

                if (m_snapshot.Indices.Rows.Count > 0)  // must have at least one index and a total
                {
                    AccountDataSet.IndicesRow totalRow = m_snapshot.Indices[m_snapshot.Indices.Rows.Count - 1];
                    textBoxCurrentDelta.Text = String.Format("{0:f3}", m_currentDeltaPercent = totalRow.TotalDeltaPct);
                }
                else
                {
                    ShowError("No delta percent supplied");
                    m_loadedSuccessfully = false;
                }

                if (m_snapshot.AccountData.Count > 0)
                {
                    m_desiredDeltaPercent = m_snapshot.AccountData[0].DeltaGoal;
                    if (m_desiredDeltaPercent < .0001)
                    {
                        m_desiredDeltaPercent = m_snapshot.AccountData[0].TargetDelta;
                    }
                    textBoxDesiredDelta.Text = String.Format("{0:f3}", m_desiredDeltaPercent);

                    m_currentEquity = m_snapshot.AccountData[0].CurrentEquity;
                    textBoxMaxNotionalValue.Text = String.Format("{0:N0}", m_maxNotionalValue = m_snapshot.AccountData[0].BaseEquity);
                }
                else
                {
                    ShowError("No account info supplied");
                    m_loadedSuccessfully = false;
                }

                if (m_snapshot.Positions != null)
                {
                    List <AccountDataSet.PortfolioRow> rows = new List <AccountDataSet.PortfolioRow>(m_snapshot.Positions.Where(x =>
                                                                                                                                (!x.IsOptionTypeNull()) &&
                                                                                                                                (x.OptionType == "Put") &&
                                                                                                                                (x.AccountName == m_snapshot.AccountName) &&
                                                                                                                                (x.Current_Position != -x.NettingAdjustment)));
                    rows.Sort(new SortByDelta());
                    dataGridView1.DataSource = rows;
                }
                else
                {
                    ShowError("No positions supplied");
                    m_loadedSuccessfully = false;
                }

                double changeInDelta = 0;
                m_loadedSuccessfully            &= CalculateRisk(ref m_currentNotionalValue, ref changeInDelta, ref m_indexPrice);
                textBoxCurrentNotionalValue.Text = String.Format("{0:N0}", m_currentNotionalValue);
            }
            catch (Exception ex)
            {
                ShowError("Error loading info", ex);
                m_loadedSuccessfully = false;
            }
        }