예제 #1
0
static void
qsAppendSelectPropertyName(QLStatement * st, char *pn)
{
  char          **names =
      ensureCharsListSpace(st, &st->spNames, &st->spMax, st->spNext);
  names[st->spNext++] = pn;
  names[st->spNext] = NULL;
  QL_TRACE(fprintf(stderr, "--- appendSelectPropertyName: %s\n", pn));
}
예제 #2
0
QLOperation* newOrOperation(QLStatement *qs, QLOperation* lo, QLOperation* ro)
{
   QLOperation *op=qsAllocNew(qs,QLOperation);
   op->lhon=lo;
   op->rhon=ro;
   op->opr=QL_OR;
   op->ft=&qlOrOperationFt;
   QL_TRACE(fprintf(stderr,"--- newOrOperation %p (%p-%p)\n",op,lo,ro));
   return op;
}
예제 #3
0
QLOperation* newBinaryOperation(QLStatement *qs, QLOperation* lo)
{
   QLOperation *op=qsAllocNew(qs,QLOperation);
   op->lhon=lo;
   op->rhon=NULL;
   op->opr=QL_bin;
   op->ft=&qlBinOperationFt;
   QL_TRACE(fprintf(stderr,"--- newBinaryOperation %p (%p)\n",op,lo));
   return op;
}
예제 #4
0
QLOperand* newInstQueryOperand(QLStatement *qs, CMPIInstance* ci) 
{
   QLOperand *op=qsAllocNew(qs,QLOperand);
   QL_TRACE(fprintf(stderr,"--- newInstQueryOperand %p\n",ci));
   op->inst=ci;
   op->type=QL_Inst;
   op->fnc=QL_FNC_NoFunction;
   op->ft=&qLinstQueryOperandFt;
   return op;
}
예제 #5
0
QLOperand* newNameQueryOperand(QLStatement *qs, char* val) 
{
   QLOperand *op=qsAllocNew(qs,QLOperand);
   QL_TRACE(fprintf(stderr,"--- newNameQueryOperand %s\n",val));
   op->charsVal=val;
   op->type=QL_Name;
   op->fnc=QL_FNC_NoFunction;
   op->ft=&qLnameQueryOperandFt;
   return op;
}
예제 #6
0
QLOperand* newPropQueryOperand(QLStatement *qs, QLPropertyNameData* val) 
{
   QLOperand *op=qsAllocNew(qs,QLOperand);
   QL_TRACE(fprintf(stderr,"--- newPropQueryOperand %p\n",val));
   op->propertyName=val;
   op->type=QL_PropertyName;
   op->fnc=QL_FNC_NoFunction;
   op->ft=&qLpropQueryOperandFt;
   return op;
}
예제 #7
0
QLOperand* newBooleanQueryOperand(QLStatement *qs, unsigned char val) 
{
   QLOperand *op=qsAllocNew(qs,QLOperand);
   op->booleanVal=val;
   op->type=QL_Boolean;
   op->fnc=QL_FNC_NoFunction;
   op->ft=&qLbooleanQueryOperandFt;
   QL_TRACE(fprintf(stderr,"--- newBooleanQueryOperand %d %p\n",val,op));
   return op;
}
예제 #8
0
QLOperand* newDoubleQueryOperand(QLStatement *qs, double val) 
{
   QLOperand *op=qsAllocNew(qs,QLOperand);
   QL_TRACE(fprintf(stderr,"--- newDoubleQueryOperand %g\n",val));
   op->doubleVal=val;
   op->type=QL_Double;
   op->fnc=QL_FNC_NoFunction;
   op->ft=&qLdoubleQueryOperandFt;
   return op;
}
예제 #9
0
QLOperand* newIntQueryOperand(QLStatement *qs, long long val) 
{
   QLOperand *op=qsAllocNew(qs,QLOperand);
   QL_TRACE(fprintf(stderr,"--- newIntQueryOperand %lld\n",val));
   op->integerVal=val;
   op->type=QL_Integer;
   op->fnc=QL_FNC_NoFunction;
   op->ft=&qLintQueryOperandFt;
   return op;
}
예제 #10
0
QLOperation* newAndOperation(QLStatement *qs, QLOperation* lo, QLOperation* ro)
{
   QLOperation *op=qsAllocNew(qs,QLOperation);
   op->lhon=lo;
   op->rhon=ro;
   op->opr=QL_AND;
   op->ft=&qlAndOperationFt;
   QL_TRACE(fprintf(stderr,"--- newAndOperation %p\n",op));
   return op;
}
예제 #11
0
QLOperation* newEqOperation(QLStatement *qs, QLOperand* lo, QLOperand* ro)
{
   QLOperation *op=qsAllocNew(qs,QLOperation);
   op->lhod=lo;
   op->rhod=ro;
   op->opr=QL_EQ;
   op->ft=&qlEqOperationFt;
   QL_TRACE(fprintf(stderr,"--- newEqOperation %p\n",op));
   return op;
}
예제 #12
0
static void relTraverse(QLOperation *op) 
{
   char *str;
   
   QL_TRACE(fprintf(stderr,"- - relTraverse: %d\n",op->opr));
   if (op->lhon) op->lhon->ft->traverse(op->lhon);
   if (op->rhon) op->rhon->ft->traverse(op->rhon);
   str=op->ft->toString(op);
   fprintf(stderr,"%s\n",str);
   free(str);
}
예제 #13
0
QLOperand* newFncQueryOperand(QLStatement *qs, QLFnc fnc, QLOpd argType, void* argVal) 
{
   QLOperand *op=qsAllocNew(qs,QLOperand);
   QL_TRACE(fprintf(stderr,"--- newFncQueryOperand %p\n",argVal));
//   op->propertyName=val;
   op->type=QL_PropertyName;
   op->fnc=fnc;
   op->fncArgType=argType;
   switch (fnc) {
      case QL_FNC_NoFunction:
      case QL_FNC_BadFunction:
         break;
      case QL_FNC_Classname:
      case QL_FNC_Namespacename:
      case QL_FNC_Namespacetype:
      case QL_FNC_Hostport:
      case QL_FNC_Modelpath:
         op->type=QL_Chars;
         if (argType!=QL_Chars && argType!=QL_PropertyName) return NULL; 
         break;
      case QL_FNC_Classpath:
      case QL_FNC_Objectpath:
         op->type=QL_Ref;
         if (argType!=QL_Chars && argType!=QL_PropertyName) return NULL; 
         break;         
      case QL_FNC_InstanceToReference:
         op->type=QL_Ref;
         if (argType!=QL_Inst) return NULL; 
         break;
      case QL_FNC_CurrentDateTime:
      case QL_FNC_DateTime:
      case QL_FNC_MicrosecondsToTimestamp:
      case QL_FNC_MicrosecondsToInterval:
         break;
      default:
         ;   
   }
   op->ft=&qLpropQueryOperandFt;
   return op;
}
예제 #14
0
    inline void Observable::notifyObservers() {
    	// check whether the notifications should be triggered
    	if (!settings_.updatesEnabled())
    	{
    	    // if updates are only deferred, flag this for later notification
    	    // these are held centrally by the settings singleton
            if (settings_.updatesDeferred())
    		settings_.registerDeferredObservers(observers_);

    	    return;
    	}

        if (observers_.size() > 0)
        {
            bool successful = true;
            std::string errMsg;

            QL_TRACE("direct notification of " << observers_.size() << " observers");
            for (iterator i=observers_.begin(); i!=observers_.end(); ++i) {
                try {
                   (*i)->update();
                } catch (std::exception& e) {
                    // quite a dilemma. If we don't catch the exception,
                    // other observers will not receive the notification
                    // and might be left in an incorrect state. If we do
                    // catch it and continue the loop (as we do here) we
                    // lose the exception. The least evil might be to try
                    // and notify all observers, while raising an
                    // exception if something bad happened.
                    successful = false;
                    errMsg = e.what();
                } catch (...) {
                    successful = false;
                }
            }
            QL_ENSURE(successful,
                  "could not notify one or more observers: " << errMsg);
        }
    }
예제 #15
0
    inline void ObservableSettings::unregisterDeferredObserver(Observer* o) {
	QL_TRACE("removing observer " << o << " from the deferred list");
    	deferredObservers_.erase(o);
    }
    void LongstaffSchwartzMultiPathPricer::calibrate() {
        const Size n = paths_.size(); // number of paths
        Array prices(n, 0.0), exercise(n, 0.0);

        const Size basisDimension = payoff_->basisSystemDimension();

        const Size len = paths_[0].pathLength();

        /*
          We try to estimate the lower bound of the continuation value,
          so that only itm paths contribute to the regression.
         */

        for (Size j = 0; j < n; ++j) {
            const Real payoff = paths_[j].payments[len - 1];
            const Real exercise = paths_[j].exercises[len - 1];
            const Array & states = paths_[j].states[len - 1];
            const bool canExercise = !states.empty();

            // at the end the continuation value is 0.0
            if (canExercise && exercise > 0.0)
                prices[j] += exercise;
            prices[j] += payoff;
        }

        lowerBounds_[len - 1] = *std::min_element(prices.begin(), prices.end());

        std::vector<bool> lsExercise(n);

        for (Integer i = len - 2; i >= 0; --i) {
            std::vector<Real>  y;
            std::vector<Array> x;

            // prices are discounted up to time i
            const Real discountRatio = dF_[i + 1] / dF_[i];
            prices *= discountRatio;
            lowerBounds_[i + 1] *= discountRatio;

            //roll back step
            for (Size j = 0; j < n; ++j) {
                exercise[j] = paths_[j].exercises[i];

                // If states is empty, no exercise in this path
                // and the path will not partecipate to the Lesat Square regression

                const Array & states = paths_[j].states[i];
                QL_REQUIRE(states.empty() || states.size() == basisDimension, 
                           "Invalid size of basis system");

                // only paths that could potentially create exercise opportunities
                // partecipate to the regression

                // if exercise is lower than minimum continuation value, no point in considering it
                if (!states.empty() && exercise[j] > lowerBounds_[i + 1]) {
                    x.push_back(states);
                    y.push_back(prices[j]);
                }
            }

            if (v_.size() <=  x.size()) {
                coeff_[i] = LinearLeastSquaresRegression<Array>(x, y, v_)
                                                            .coefficients();
            }
            else {
            // if number of itm paths is smaller then the number of
            // calibration functions -> never exercise
                QL_TRACE("Not enough itm paths: default decision is NEVER");
                coeff_[i] = Array(0);
            }

            /* attempt to avoid static arbitrage given by always or never exercising.

               always is absolute: regardless of the lowerBoundContinuationValue_ (this could be changed)
               but it still honours "canExercise"
             */
            double sumOptimized = 0.0;
            double sumNoExercise = 0.0;
            double sumAlwaysExercise = 0.0; // always, if allowed

            for (Size j = 0, k = 0; j < n; ++j) {
                sumNoExercise += prices[j];
                lsExercise[j] = false;

                const bool canExercise = !paths_[j].states[i].empty();
                if (canExercise) {
                    sumAlwaysExercise += exercise[j];
                    if (!coeff_[i].empty() && exercise[j] > lowerBounds_[i + 1]) {
                        Real continuationValue = 0.0;
                        for (Size l = 0; l < v_.size(); ++l) {
                            continuationValue += coeff_[i][l] * v_[l](x[k]);
                        }
                        
                        if (continuationValue < exercise[j]) {
                            lsExercise[j] = true;
                        }
                        ++k;
                    }
                }
                else {
                    sumAlwaysExercise += prices[j];
                }

                sumOptimized += lsExercise[j] ? exercise[j] : prices[j];
            }

            sumOptimized /= n;
            sumNoExercise /= n;
            sumAlwaysExercise /= n;

            QL_TRACE(   "Time index: " << i 
                     << ", LowerBound: " << lowerBounds_[i + 1] 
                     << ", Optimum: " << sumOptimized 
                     << ", Continuation: " << sumNoExercise 
                     << ", Termination: " << sumAlwaysExercise);

            if (  sumOptimized >= sumNoExercise 
                && sumOptimized >= sumAlwaysExercise) {
                
                QL_TRACE("Accepted LS decision");
                for (Size j = 0; j < n; ++j) {
                    // lsExercise already contains "canExercise"
                    prices[j] = lsExercise[j] ? exercise[j] : prices[j];
                }
            }
            else if (sumAlwaysExercise > sumNoExercise) {
                QL_TRACE("Overridden bad LS decision: ALWAYS");
                for (Size j = 0; j < n; ++j) {
                    const bool canExercise = !paths_[j].states[i].empty();
                    prices[j] = canExercise ? exercise[j] : prices[j];
                }
                // special value to indicate always exercise
                coeff_[i] = Array(v_.size() + 1); 
            }
            else {
                QL_TRACE("Overridden bad LS decision: NEVER");
                // prices already contain the continuation value
                // special value to indicate never exercise
                coeff_[i] = Array(0); 
            }

            // then we add in any case the payment at time t
            // which is made even if cancellation happens at t
            for (Size j = 0; j < n; ++j) {
                const Real payoff = paths_[j].payments[i];
                prices[j] += payoff;
            }

            lowerBounds_[i] = *std::min_element(prices.begin(), prices.end());
        }

        // remove calibration paths
        paths_.clear();
        // entering the calculation phase
        calibrationPhase_ = false;
    }
예제 #17
0
static int evaluate(QLOperation *op, QLPropertySource* source) 
{
   int rc=op->ft->_evaluate(op,source); 
   QL_TRACE(fprintf(stderr,"evaluate(): %d\n",rc));
   return rc;
}
예제 #18
0
static int propCompare(QLOperand* self, QLOperand* op, 
   QLPropertySource* src)
{
   QLOperand *nop=NULL;
   QLOpd type;
   int rc;
   CMPIValue v=getPropValue(self, src, &type);
   char *str;

   switch (type) {
   case QL_Integer: 
      nop=newIntQueryOperand(NULL,v.sint64);
      break;
   case QL_UInteger: 
      nop=newIntQueryOperand(NULL,v.sint64);
      nop->type=QL_UInteger;
      break;
   case QL_Double:
      nop=newDoubleQueryOperand(NULL,v.real64);
      break;
   case QL_Boolean:
      nop=newBooleanQueryOperand(NULL,v.boolean);
      break;
   case QL_Chars:
      nop=newCharsQueryOperand(NULL,v.chars);
      break;
   case QL_Char:
      nop=newCharsQueryOperand(NULL,v.chars);
      nop->type=QL_Char;
      nop->value.char16=v.char16;
      break;
    case QL_Inst:
      nop=newInstQueryOperand(NULL,v.inst);
      nop->type=QL_Char;
      nop->value.char16=v.char16;
      break;
   case QL_PropertyName:
   case QL_Name:
      mlogf(M_ERROR,M_SHOW,"### propCompare(): (QL_PropertyName QL_Name) got a problem\n");
      return -2;
      /*      abort();*/
      break;
   case QL_Invalid:
      mlogf(M_ERROR,M_SHOW,"### propCompare(): got a problem\n");
      return -2;
      /* abort();*/
      break;
   case QL_NotFound:
      str=propToString(self);
      mlogf(M_ERROR,M_SHOW,"### propCompare(): %s not found\n",str);
      free(str);
      return -2;
      /*abort();*/
   default:
      ; // what should we do here ?  
   }
   
   if (nop) {
    rc=nop->ft->compare(nop,op,src);
   } else {
      rc=-2;
      if ((type == QL_Null) && (op->type == QL_PropertyName)) {
         // both are property names
         v=getPropValue(op, src, &type);
         if (type == QL_Null) {
            rc=0; // both are NULL, a match
         }
      } 
   }
   

   QL_TRACE(fprintf(stderr,"propCompare(%s) %d\n",self->propertyName->propName,rc));
   return rc;
}
예제 #19
0
static char *orToString(QLOperation *op) 
{
   QL_TRACE(fprintf(stderr,"--- orToString %p\n",op));
   return opnToChars(op,(op->flag.invert ? "QL_AND" : "QL_OR"),NULL);
}
예제 #20
0
int binEvaluate(QLOperation *op, QLPropertySource* source) 
{
   int rc=op->lhon->ft->evaluate(op->lhon,source);
   QL_TRACE(fprintf(stderr,"binEvaluate(): %d\n",rc));
   return rc;
}
예제 #21
0
int _binEvaluate(QLOperation *op, QLPropertySource* source) 
{
   QL_TRACE(fprintf(stderr,"--- unexpected invocation of _isNotNullEvaluate\n"));
   exit(16);
}