private void BuildPositionRow(HugoDataSet.PortfolioRow portfolioRow, AccountData accountData, Position newRow, double underlyingPrice) { int lineNumber = 0; try { lineNumber++; newRow.Account = portfolioRow.AcctName; lineNumber++; newRow.Symbol = portfolioRow.Symbol; lineNumber++; newRow.SubscriptionStatus = portfolioRow.SubscriptionStatus; lineNumber++; newRow.SODPosition = portfolioRow.SOD_Position; lineNumber++; newRow.SODPrice = portfolioRow.SOD_Price; // 5 lineNumber++; newRow.SODMarketValue = portfolioRow.SOD_Market_Value; lineNumber++; newRow.ChangeInPosition = portfolioRow.Change_in_Position; lineNumber++; newRow.ChangeInCost = portfolioRow.Change_in_Cost; lineNumber++; newRow.CurrentPosition = portfolioRow.Current_Position; lineNumber++; newRow.NettingAdjustment = portfolioRow.Netting_Adjustment; // 10 lineNumber++; newRow.CurrentPrice = portfolioRow.CurrentPrice; lineNumber++; newRow.CurrentCost = portfolioRow.Current_Cost; lineNumber++; newRow.Closed = portfolioRow.Closed; lineNumber++; newRow.OptionType = portfolioRow.IsOptionTypeNull() ? null : portfolioRow.OptionType; lineNumber++; newRow.UnderlyingSymbol = portfolioRow.IsUnderlyingSymbolNull() ? null : portfolioRow.UnderlyingSymbol; // 15 lineNumber++; newRow.Multiplier = portfolioRow.Multiplier; lineNumber++; newRow.IsStock = portfolioRow.IsStock == 1; lineNumber++; newRow.IsOption = portfolioRow.IsOption == 1; lineNumber++; newRow.IsFuture = portfolioRow.IsFuture == 1; lineNumber++; newRow.Open = portfolioRow.IsOpenNull() ? new System.Nullable <double>() : portfolioRow.Open; // 20 lineNumber++; newRow.PrevClose = portfolioRow.IsPrevCloseNull() ? new System.Nullable <double>() : portfolioRow.PrevClose; lineNumber++; newRow.LastPrice = portfolioRow.IsLastPriceNull() ? new System.Nullable <double>() : portfolioRow.LastPrice; lineNumber++; newRow.Bid = portfolioRow.IsBidNull() ? new System.Nullable <double>() : portfolioRow.Bid; lineNumber++; newRow.Ask = portfolioRow.IsAskNull() ? new System.Nullable <double>() : portfolioRow.Ask; lineNumber++; newRow.ClosingPrice = portfolioRow.IsClosingPriceNull() ? new System.Nullable <double>() : portfolioRow.ClosingPrice; // 25 // must use portfolioRow.PriceMultiplier for P&L purposes // newRow.Multiplier has been adjusted to reflect deltas on the associated index lineNumber++; newRow.CurrentMarketValue = portfolioRow.CurrentPrice * newRow.CurrentPosition * portfolioRow.PriceMultiplier; lineNumber++; newRow.PandL = newRow.CurrentMarketValue - newRow.CurrentCost; lineNumber++; newRow.ExpirationDate = portfolioRow.IsExpirationDateNull() ? new System.Nullable <DateTime>() : portfolioRow.ExpirationDate; lineNumber++; if (newRow.Bid.HasValue && newRow.Ask.HasValue) { lineNumber++; newRow.Mid = (newRow.Bid + newRow.Ask) / 2.0; // 30 } else { lineNumber++; newRow.Mid = 0; } lineNumber++; if (newRow.IsOption) { lineNumber++; newRow._100DeltaUSD = (newRow.CurrentPosition + newRow.NettingAdjustment) * newRow.Multiplier * underlyingPrice; lineNumber++; newRow.Delta = portfolioRow.IsDeltaNull() ? new System.Nullable <double>() : portfolioRow.Delta; lineNumber++; newRow.DeltaUSD = portfolioRow.IsDeltaNull() ? new System.Nullable <double>() : portfolioRow.Delta * (newRow.CurrentPosition + newRow.NettingAdjustment) * newRow.Multiplier * underlyingPrice; lineNumber++; newRow.Gamma = portfolioRow.IsGammaNull() ? new System.Nullable <double>() : portfolioRow.Gamma; // 35 lineNumber++; newRow.GammaUSD = portfolioRow.IsGammaNull() ? new System.Nullable <double>() : newRow.Gamma * (newRow.CurrentPosition + newRow.NettingAdjustment) * newRow.Multiplier * underlyingPrice; lineNumber++; newRow.Theta = portfolioRow.IsThetaNull() ? new System.Nullable <double>() : portfolioRow.Theta; lineNumber++; newRow.ThetaAnnualized = portfolioRow.IsThetaNull() ? new System.Nullable <double>() : newRow.Theta * (newRow.CurrentPosition + newRow.NettingAdjustment) * portfolioRow.PriceMultiplier * 360; lineNumber++; newRow.Vega = portfolioRow.IsVegaNull() ? new System.Nullable <double>() : portfolioRow.Vega; lineNumber++; newRow.ImpliedVol = portfolioRow.IsImpliedVolNull() ? new System.Nullable <double>() : portfolioRow.ImpliedVol; // 40 lineNumber++; newRow.StrikePrice = portfolioRow.IsStrikePriceNull() ? new System.Nullable <decimal>() : portfolioRow.StrikePrice; lineNumber++; if (newRow.OptionType == "Call") { lineNumber++; newRow.TimePremium = Math.Max(0, newRow.Mid.Value - Math.Max(0, underlyingPrice * newRow.Multiplier / 100 - (double)newRow.StrikePrice.Value)) * (newRow.CurrentPosition + newRow.NettingAdjustment) * portfolioRow.PriceMultiplier; } else { lineNumber++; newRow.TimePremium = Math.Max(0, newRow.Mid.Value - Math.Max(0, (double)newRow.StrikePrice.Value - underlyingPrice * newRow.Multiplier / 100)) * (newRow.CurrentPosition + newRow.NettingAdjustment) * portfolioRow.PriceMultiplier; lineNumber++; if (accountData != null) { if (((newRow.CurrentPosition + newRow.NettingAdjustment) > 0) && (newRow.Multiplier > 0) && newRow.StrikePrice.HasValue && (accountData.PutsOutOfMoneyThreshold < 1)) { lineNumber++; // 45 if ((double)newRow.StrikePrice.Value * 100 / newRow.Multiplier < (1 - accountData.PutsOutOfMoneyThreshold) * underlyingPrice) { lineNumber++; newRow.IsOutOfBounds = true; } else if ((double)newRow.StrikePrice.Value * 100 / newRow.Multiplier > (1 + accountData.PutsOutOfMoneyThreshold) * underlyingPrice) { lineNumber++; newRow.IsOutOfBounds = true; } } } } } } catch (Exception ex) { try { ReportError(String.Format("Error building position row, Account={0}, Symbol={1}. line number={2}", portfolioRow.AcctName, portfolioRow.Symbol, lineNumber), ex); } catch { ReportError("Error building position row", ex); } } }
private int BuildPositionsForAccount(HugoDataSet.PortfolioDataTable portfolio, List <Index> indices, Index totalRow, AccountData accountData, List <Position> positions) { int unsubscribedSymbols = 0; try { foreach (HugoDataSet.PortfolioRow portfolioRow in portfolio) { Position newRow = new Position(); Index indexRow = null; double underlyingPrice = 0; if (!portfolioRow.IsUnderlyingSymbolNull()) { if (indices != null) { indexRow = GetIndexData(indices, portfolioRow.UnderlyingSymbol); } if (indexRow != null) { underlyingPrice = indexRow.LastPrice.HasValue ? indexRow.LastPrice.Value : 0; } else { HugoDataSet.PortfolioRow underlyingRow = portfolio.FindByAcctNameSymbol(portfolioRow.AcctName, portfolioRow.UnderlyingSymbol); if (underlyingRow != null) { underlyingPrice = underlyingRow.CurrentPrice; } } } BuildPositionRow(portfolioRow, accountData, newRow, underlyingPrice); // accountData is null only if we are not interested in calculating totals for this account if (accountData != null) { AggregateAccountTotals(accountData, newRow, underlyingPrice); if (newRow.IsOption) { AggregateIndexTotals(newRow, indexRow, totalRow); } } if ((newRow.SubscriptionStatus != "Subscribed") && ((newRow.CurrentPosition != 0) || (newRow.SODPosition != 0) || newRow.IsStock)) { unsubscribedSymbols++; } newRow.UpdateTime = portfolioRow.IsUpdateTimeNull() ? new System.Nullable <TimeSpan>() : portfolioRow.UpdateTime; positions.Add(newRow); } } catch (Exception ex) { ReportError("Error building positions for account", ex); } return(unsubscribedSymbols); }