Skip to content

Conversation

@mateodelnorte
Copy link


Note: There's an outstanding issue that needs to be solved before this is merged, located at #9.


I've improved error handling to provide traceback errors for errors occurred during python runtime. They look like:

  1) bondmath BondCalculator calc w/ getHedgeRatio calculates the correct hedge ratio for a bond and its benchmark:
     TypeError: Python Error: TypeError: unsupported operand type(s) for +: 'float' and 'Decimal'

Traceback (most recent call last):
  File "/Users/matt/development/electronifie/scratch/bondmath/bondpy/code/tests/helper.py", line 75, in calc
    bond_rslts['hedgeRatio'] = getHedgeRatio(trade_date, corp, treasury, config)
  File "/Users/matt/development/electronifie/scratch/bondmath/bondpy/code/tests/helper.py", line 88, in getHedgeRatio
    corp_dv01 = corp.calc(trade_date, config['bond'], calcs=['dv01'])['dv01']
  File "/Users/matt/development/electronifie/scratch/bondmath/bondpy/code/bondmodels/bond.py", line 79, in calc
    pv_df_1 = calc_setup(self.cashflows, rslts['yield'] + Decimal('0.0001'), settle_dt)
TypeError: unsupported operand type(s) for +: 'float' and 'Decimal'

      at Object.getHedgeRatio (/Users/matt/development/electronifie/scratch/bondmath/index.js:27:33)
      at Context.<anonymous> (/Users/matt/development/electronifie/scratch/bondmath/test/index.js:31:41)
      at callFn (/Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runnable.js:247:21)
      at Test.Runnable.run (/Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runnable.js:240:7)
      at Runner.runTest (/Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runner.js:373:10)
      at /Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runner.js:451:12
      at next (/Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runner.js:298:14)
      at /Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runner.js:308:7
      at next (/Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runner.js:246:23)
      at Object._onImmediate (/Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runner.js:275:5)
      at processImmediate [as _immediateCallback] (timers.js:336:15)

In V8, an Array is an Object. As a result, there was an ordering problem in the logic for checking to see if a variable is an object and then checking if it was an array. This was causing all arrays to convert to python dictionaries. It's now converting to lists correctly.

I added mocha tests to start adding some stability to the lib. They look like:

  node-python
    eval
      ✓ should return resulting value from python statement executed
      ✓ should return resulting value from python statement executed, converting to string with complex types
    import
      ✓ should return object representing module imported, containing functions from imported module
      ✓ should throw a PythonError when importing a module that does not exist
      ✓ should throw an Error when importing a module that includes bad syntax


  5 passing (28ms)

@mateodelnorte
Copy link
Author

Oh yea. Also added eval() support.

@mateodelnorte
Copy link
Author

added ability to finalize the python environment, guards against executing python code after the environment/interpret have been finalized, and also fixed translation of js->python booleans.

@JeanSebTr JeanSebTr added this to the 0.0.5 milestone Oct 31, 2014
@JeanSebTr JeanSebTr merged commit b32b9ec into JeanSebTr:master Oct 31, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants