示例#1
0
        internal static void GetOptVega(IEnumerable <IPosition> positions,
                                        double f, double k, double dT, double sigma, double r, bool isCall,
                                        out double vega)
        {
            vega = 0;
            foreach (IPosition pos in positions)
            {
                //if (pos.EntrySignalName.StartsWith("CHT-RI-03.", StringComparison.InvariantCultureIgnoreCase))
                //{
                //    string str = "";
                //}

                // Пока что State лучше не трогать
                //if (pos.PositionState == PositionState.HaveError)
                {
                    int    sign    = pos.IsLong ? 1 : -1;
                    double qty     = Math.Abs(pos.Shares);
                    double optVega = FinMath.GetOptionVega(f, k, dT, sigma, r, isCall);
                    vega += sign * optVega * qty;
                }
            }
        }
示例#2
0
        internal static void GetOptGreek(IEnumerable <IPosition> positions,
                                         double f, double k, double dT, double sigma, double ratePct, bool isCall,
                                         Greeks greek, out double optGreek)
        {
            optGreek = 0;
            foreach (IPosition pos in positions)
            {
                // Пока что State лучше не трогать
                //if (pos.PositionState == PositionState.HaveError)
                {
                    int    sign = pos.IsLong ? 1 : -1;
                    double qty  = Math.Abs(pos.Shares);
                    double tmp;
                    switch (greek)
                    {
                    case Greeks.Delta:
                        tmp = FinMath.GetOptionDelta(f, k, dT, sigma, ratePct, isCall);
                        break;

                    case Greeks.Theta:
                        tmp = FinMath.GetOptionTheta(f, k, dT, sigma, ratePct, isCall);
                        break;

                    case Greeks.Vega:
                        tmp = FinMath.GetOptionVega(f, k, dT, sigma, ratePct, isCall);
                        break;

                    case Greeks.Gamma:
                        tmp = FinMath.GetOptionGamma(f, k, dT, sigma, ratePct, isCall);
                        break;

                    default:
                        throw new NotImplementedException("Greek '" + greek + "' is not yet supported.");
                    }
                    optGreek += sign * tmp * qty;
                }
            }
        }