Example #1
0
 def CreateEnvironment(self, tag, t):
     try:
         MarketServer._environments[tag] = \
            ppf.market.environment(utils.to_ppf_date(t))
         return tag
     except RuntimeError, e:
         utils.raise_com_exception(e)
Example #2
0
 def AddSurface(self, tag, name, expiries, tenors, values):
     try:
         import numpy
         exp, ten = expiries[1:], tenors[1:]
         surface = [x[1:] for x in values[1:]]
         MarketServer.retrieve(tag, 'environments').add_surface(
             str(name), ppf.market.surface(exp, ten, numpy.array(surface)))
     except RuntimeError, e:
         utils.raise_com_exception(e)
Example #3
0
 def AddCurve(self, tag, name, curve, interp):
     try:
         import ppf.math.interpolation
         interp = eval("ppf.math.interpolation." + interp)
         times, factors = [x[1]
                           for x in curve[1:]], [x[2] for x in curve[1:]]
         MarketServer.retrieve(tag, 'environments').add_curve(
             str(name), ppf.market.curve(times, factors, interp))
     except RuntimeError, e:
         utils.raise_com_exception(e)
Example #4
0
 def GenerateExerciseSchedule(self, tag, start, end, period, duration,
                              shift_method):
     try:
         sched = \
           ppf.core.generate_exercise_table(
               start = utils.to_ppf_date(start)
             , end = utils.to_ppf_date(end)
             , period = period
             , duration = eval("ppf.date_time."+duration)
             , shift_method = eval("ppf.date_time.shift_convention."+shift_method))
         TradeServer._exercises[tag] = sched
         return tag
     except RuntimeError, e:
         utils.raise_com_exception(e)
Example #5
0
 def CreateLeg(self, tag, flows, pay_or_receive, adjuvant_table, payoff):
     try:
         adjuvants = None
         if adjuvant_table:
             adjuvants = TradeServer.retrieve(adjuvant_table, 'adjuvants')
         leg = \
             ppf.core.leg(
                TradeServer.retrieve(flows, 'flows')
                , eval("ppf.core."+pay_or_receive)
                , adjuvants
                , eval("ppf.pricer.payoffs."+payoff)())
         TradeServer._legs[tag] = leg
         return tag
     except RuntimeError, e:
         utils.raise_com_exception(e)
Example #6
0
 def CreateTrade(self, tag, legs, exercise_sched, exercise_type):
     try:
         tl = [TradeServer.retrieve(l, 'legs') for l in legs[1:]]
         if exercise_sched:
             exercises = TradeServer.retrieve(exercise_sched, 'exercises')
             if not exercise_type:
                 raise RuntimeError, "missing exercise type"
             call_cancel = eval("ppf.core.exercise_type." + exercise_type)
             trade = ppf.core.trade(tl, (exercises, call_cancel))
         else:
             trade = ppf.core.trade(tl, None)
         TradeServer._trades[tag] = trade
         return tag
     except RuntimeError, e:
         utils.raise_com_exception(e)
Example #7
0
 def GenerateFlows(
     self
     , tag
     , start
     , end
     , period
     , duration
     , pay_currency
     , pay_shift_method
     , accrual_basis
     , observables):
   try:
     flows = ppf.core.generate_flows(
         start=utils.to_ppf_date(start)
         , end=utils.to_ppf_date(end)
         , duration=eval("ppf.date_time."+duration)
         , period=period
         , pay_shift_method=eval(\
             "ppf.date_time.shift_convention."+pay_shift_method)
         , pay_currency=pay_currency
         , accrual_basis=eval("ppf.date_time."+accrual_basis)
         , observables=TradeServer.retrieve(observables, 'observables'))
     TradeServer._flows[tag] = flows
     return tag
   except RuntimeError, e: utils.raise_com_exception(e)
Example #8
0
 def GenerateLiborObservables(
     self
     , tag
     , start
     , end
     , roll_period
     , roll_duration
     , reset_period
     , reset_duration
     , reset_currency
     , reset_basis
     , reset_shift_method):
   try:
     observables = \
       ppf.core.generate_libor_observables(
           start=utils.to_ppf_date(start)
         , end=utils.to_ppf_date(end)
         , roll_period=roll_period
         , roll_duration = eval("ppf.date_time."+roll_duration)
         , reset_period = reset_period
         , reset_duration = eval("ppf.date_time."+reset_duration)
         , tenor_period = reset_period
         , tenor_duration = eval("ppf.date_time."+reset_duration)
         , reset_currency=reset_currency
         , reset_basis = eval("ppf.date_time."+reset_basis)
         , reset_shift_method=eval( \
            "ppf.date_time.shift_convention."+reset_shift_method)
         , reset_lag = 0)
     TradeServer._observables[tag] = observables
     return tag
   except RuntimeError, e: utils.raise_com_exception(e)
Example #9
0
 def GenerateAdjuvantTable(
     self
     , tag
     , items
     , tens
     , vals
     , start
     , roll_period
     , roll_duration
     , shift_method):
   try:
     import numpy
     adjuvants = \
        ppf.core.generate_adjuvant_table(
             items[1:]
           , [int(t) for t in tens[1:]]
           , numpy.array([x[1:len(vals[0])] for x in vals[1:]])
           , utils.to_ppf_date(start)
           , rol_period=roll_period
           , roll_duration=eval("ppf.date_time."+roll_duration)
           , shift_method=eval(\
                "ppf.date_time.shift_convention."+shift_method))
     TradeServer._adjuvants[tag] = adjuvants
     return tag
   except RuntimeError, e: utils.raise_com_exception(e)
Example #10
0
 def AddSurface(self, tag, name, expiries, tenors, values):
   try:
     import numpy
     exp, ten = expiries[1:], tenors[1:]
     surface = [x[1:] for x in values[1:]]
     MarketServer.retrieve(tag,'environments').add_surface(
       str(name), ppf.market.surface(exp, ten, numpy.array(surface)))
   except RuntimeError, e: utils.raise_com_exception(e)
Example #11
0
 def AddCurve(self, tag, name, curve, interp):
   try:
     import ppf.math.interpolation
     interp = eval("ppf.math.interpolation."+interp)
     times, factors = [x[1] for x in curve[1:]],[x[2] for x in curve[1:]]
     MarketServer.retrieve(tag, 'environments').add_curve(
         str(name), ppf.market.curve(times, factors, interp))
   except RuntimeError, e: utils.raise_com_exception(e)
Example #12
0
 def GenerateFlows(self, tag, start, end, period, duration, pay_currency,
                   pay_shift_method, accrual_basis, observables):
     try:
         flows = ppf.core.generate_flows(
             start=utils.to_ppf_date(start)
             , end=utils.to_ppf_date(end)
             , duration=eval("ppf.date_time."+duration)
             , period=period
             , pay_shift_method=eval(\
                 "ppf.date_time.shift_convention."+pay_shift_method)
             , pay_currency=pay_currency
             , accrual_basis=eval("ppf.date_time."+accrual_basis)
             , observables=TradeServer.retrieve(observables, 'observables'))
         TradeServer._flows[tag] = flows
         return tag
     except RuntimeError, e:
         utils.raise_com_exception(e)
Example #13
0
 def GenerateAdjuvantTable(self, tag, items, tens, vals, start, roll_period,
                           roll_duration, shift_method):
     try:
         import numpy
         adjuvants = \
            ppf.core.generate_adjuvant_table(
                 items[1:]
               , [int(t) for t in tens[1:]]
               , numpy.array([x[1:len(vals[0])] for x in vals[1:]])
               , utils.to_ppf_date(start)
               , rol_period=roll_period
               , roll_duration=eval("ppf.date_time."+roll_duration)
               , shift_method=eval(\
                    "ppf.date_time.shift_convention."+shift_method))
         TradeServer._adjuvants[tag] = adjuvants
         return tag
     except RuntimeError, e:
         utils.raise_com_exception(e)
Example #14
0
 def GenerateFixedCouponObservables(self, tag, start, end, roll_period,
                                    roll_duration, reset_currency,
                                    coupon_shift_method, coupon_rate):
     try:
         observables = \
          ppf.core.generate_fixed_coupon_observables(
               start=utils.to_ppf_date(start)
             , end=utils.to_ppf_date(end)
             , roll_period=roll_period
             , roll_duration=eval("ppf.date_time."+roll_duration)
             , reset_currency=reset_currency
             , coupon_shift_method=
                 eval("ppf.date_time.shift_convention."+coupon_shift_method)
             , coupon_rate=coupon_rate)
         TradeServer._observables[tag] = observables
         return tag
     except RuntimeError, e:
         utils.raise_com_exception(e)
Example #15
0
 def GenerateExerciseSchedule(
     self
     , tag
     , start
     , end
     , period
     , duration
     , shift_method):
   try:
     sched = \
       ppf.core.generate_exercise_table(
           start = utils.to_ppf_date(start)
         , end = utils.to_ppf_date(end)
         , period = period
         , duration = eval("ppf.date_time."+duration)
         , shift_method = eval("ppf.date_time.shift_convention."+shift_method))
     TradeServer._exercises[tag] = sched
     return tag
   except RuntimeError, e:
     utils.raise_com_exception(e)
Example #16
0
 def GenerateLiborObservables(self, tag, start, end, roll_period,
                              roll_duration, reset_period, reset_duration,
                              reset_currency, reset_basis,
                              reset_shift_method):
     try:
         observables = \
           ppf.core.generate_libor_observables(
               start=utils.to_ppf_date(start)
             , end=utils.to_ppf_date(end)
             , roll_period=roll_period
             , roll_duration = eval("ppf.date_time."+roll_duration)
             , reset_period = reset_period
             , reset_duration = eval("ppf.date_time."+reset_duration)
             , tenor_period = reset_period
             , tenor_duration = eval("ppf.date_time."+reset_duration)
             , reset_currency=reset_currency
             , reset_basis = eval("ppf.date_time."+reset_basis)
             , reset_shift_method=eval( \
                "ppf.date_time.shift_convention."+reset_shift_method)
             , reset_lag = 0)
         TradeServer._observables[tag] = observables
         return tag
     except RuntimeError, e:
         utils.raise_com_exception(e)
Example #17
0
 def CreateTrade(
   self
   , tag
   , legs
   , exercise_sched
   , exercise_type):
   try:
     tl = [TradeServer.retrieve(l, 'legs') for l in legs[1:]]
     if exercise_sched:
       exercises = TradeServer.retrieve(exercise_sched, 'exercises')
       if not exercise_type:
         raise RuntimeError, "missing exercise type"
       call_cancel = eval("ppf.core.exercise_type."+exercise_type)
       trade = ppf.core.trade(tl, (exercises, call_cancel))
     else:
       trade = ppf.core.trade(tl, None)
     TradeServer._trades[tag] = trade
     return tag
   except RuntimeError, e: utils.raise_com_exception(e)
Example #18
0
 def CreateLeg(
   self
   , tag
   , flows
   , pay_or_receive
   , adjuvant_table
   , payoff):
   try:
     adjuvants = None
     if adjuvant_table:
       adjuvants = TradeServer.retrieve(adjuvant_table, 'adjuvants')
     leg = \
         ppf.core.leg(
            TradeServer.retrieve(flows, 'flows')
            , eval("ppf.core."+pay_or_receive)
            , adjuvants
            , eval("ppf.pricer.payoffs."+payoff)())
     TradeServer._legs[tag] = leg
     return tag
   except RuntimeError, e: utils.raise_com_exception(e)
Example #19
0
 def GenerateFixedCouponObservables(
     self
     , tag
     , start
     , end
     , roll_period
     , roll_duration
     , reset_currency
     , coupon_shift_method
     , coupon_rate):
   try:
     observables = \
      ppf.core.generate_fixed_coupon_observables(
           start=utils.to_ppf_date(start)
         , end=utils.to_ppf_date(end)
         , roll_period=roll_period
         , roll_duration=eval("ppf.date_time."+roll_duration)
         , reset_currency=reset_currency
         , coupon_shift_method=
             eval("ppf.date_time.shift_convention."+coupon_shift_method)
         , coupon_rate=coupon_rate)
     TradeServer._observables[tag] = observables
     return tag
   except RuntimeError, e: utils.raise_com_exception(e)
Example #20
0
 def CreateEnvironment(self, tag, t):
    try:
      MarketServer._environments[tag] = \
         ppf.market.environment(utils.to_ppf_date(t))
      return tag
    except RuntimeError, e: utils.raise_com_exception(e)
Example #21
0
 def AddConstant(self, tag, name, value):
   try:
     MarketServer.retrieve(tag, 'environments').add_constant(
       str(name), value)
   except RuntimeError, e: utils.raise_com_exception(e)
Example #22
0
 def InvokePricer(self, tag):
     try:
         return PricerServer.retrieve(tag, 'pricers').__call__()
     except RuntimeError, e:
         utils.raise_com_exception(e)
Example #23
0
 def InvokePricer(self, tag):
   try:
     return PricerServer.retrieve(tag, 'pricers').__call__()
   except RuntimeError, e: utils.raise_com_exception(e)
Example #24
0
 def AddConstant(self, tag, name, value):
     try:
         MarketServer.retrieve(tag, 'environments').add_constant(
             str(name), value)
     except RuntimeError, e:
         utils.raise_com_exception(e)