Exemplo n.º 1
0
def data_input(filename, i):
    with open(filename) as json_file:
        data = json.load(json_file)
    pv, yy, dd, cc = integration(data[i]['coupon_rate'], data[i]['face_value'],
                                 data[i]['time_start'], data[i]['year'],
                                 data[i]['time_cur'], data[i]['frequency'])
    re = {'Pv': pv, 'Yield': yy, 'Duration': dd, 'Convexity': cc}
    return re
Exemplo n.º 2
0
def integration_determinant_test ( ):

#*****************************************************************************80
#
## INTEGRATION_DETERMINANT_TEST tests INTEGRATION_DETERMINANT.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    16 February 2015
#
#  Author:
#
#    John Burkardt
#
  from integration import integration
  from r8mat_print import r8mat_print
  from r8_uniform_ab import r8_uniform_ab

  print ''
  print 'INTEGRATION_DETERMINANT_TEST'
  print '  INTEGRATION_DETERMINANT computes the determinant of the INTEGRATION matrix.'
  print ''

  m = 4
  n = m

  r8_lo = -5.0
  r8_hi = +5.0
  seed = 123456789
  alpha, seed = r8_uniform_ab ( r8_lo, r8_hi, seed )

  a = integration ( alpha, n )
  r8mat_print ( m, n, a, '  INTEGRATION matrix:' )

  value = integration_determinant ( alpha, n )

  print ''
  print '  Value =  %g' % ( value )

  print ''
  print 'INTEGRATION_DETERMINANT_TEST'
  print '  Normal end of execution.'

  return
Exemplo n.º 3
0
def integration_determinant_test():

    #*****************************************************************************80
    #
    ## INTEGRATION_DETERMINANT_TEST tests INTEGRATION_DETERMINANT.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    16 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from integration import integration
    from r8mat_print import r8mat_print
    from r8_uniform_ab import r8_uniform_ab

    print ''
    print 'INTEGRATION_DETERMINANT_TEST'
    print '  INTEGRATION_DETERMINANT computes the determinant of the INTEGRATION matrix.'
    print ''

    m = 4
    n = m

    r8_lo = -5.0
    r8_hi = +5.0
    seed = 123456789
    alpha, seed = r8_uniform_ab(r8_lo, r8_hi, seed)

    a = integration(alpha, n)
    r8mat_print(m, n, a, '  INTEGRATION matrix:')

    value = integration_determinant(alpha, n)

    print ''
    print '  Value =  %g' % (value)

    print ''
    print 'INTEGRATION_DETERMINANT_TEST'
    print '  Normal end of execution.'

    return
Exemplo n.º 4
0
def main(acceleration, timeInterval):
    velocity = intg.integration(timeInterval, acceleration)
    # plt.plot(velocity[:,[0]],'g',velocity[:,[1]],'r',velocity[:,[2]],'b')
    # plt.plot(velocity[:,[0]],'b')
    normMatrix = l2Norm(acceleration)
    # plt.plot(normMatrix)
    absoluteData = absolute(filt.butterWorthFilter(normMatrix, 0.02, 5, 'low'))
    # plt.plot(absoluteData,'g')
    smoothenedData = filt.butterWorthFilter(absoluteData, 0.01, 5, 'low')
    smoothenedData = smoothenedData - 0.6
    # plt.plot(smoothenedData,'r')
    # count = 0
    # while count < len(acceleration):
    # if
    # print zeroVRegion(smoothenedData)
    basicIntegrate(timeInterval, acceleration, smoothenedData)
Exemplo n.º 5
0
def data_input(filename):
    with open(filename) as json_file:
        data = json.load(json_file)
    cnt = len(data)
    result = []
    for i in range(cnt):
        pv, yy, dd, cc = integration(data[i]['coupon_rate'],
                                     data[i]['face_value'],
                                     data[i]['time_start'], data[i]['year'],
                                     data[i]['time_cur'], data[i]['frequency'])
        re = {'Pv': pv, 'Yield': yy, 'Duration': dd, 'Convexity': cc}
        result.append(re)
        #if(i%1000 == 0):
        #print "PV:%f" % pv
        #print "yield:%f" % yy
        #print "Duration:%f" % dd
        #print "Convexity:%f" % cc
        #print "==============%d============="%i
    with open('result.json', 'w') as json_file:
        json_file.write(json.dumps(result))
Exemplo n.º 6
0
def integration_test ( ):

#*****************************************************************************80
#
## INTEGRATION_TEST tests INTEGRATION.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    16 February 2015
#
#  Author:
#
#    John Burkardt
#
  from r8mat_print import r8mat_print
  from r8_uniform_ab import r8_uniform_ab

  print ''
  print 'INTEGRATION_TEST'
  print '  INTEGRATION computes the INTEGRATION matrix.'

  m = 6
  n = m

  r8_lo = -5.0
  r8_hi = +5.0
  seed = 123456789
  alpha, seed = r8_uniform_ab ( r8_lo, r8_hi, seed )

  a = integration ( alpha, n )
  r8mat_print ( m, n, a, '  INTEGRATION matrix:' )

  print ''
  print 'INTEGRATION_TEST'
  print '  Normal end of execution.'

  return
Exemplo n.º 7
0
def integration_test():

    #*****************************************************************************80
    #
    ## INTEGRATION_TEST tests INTEGRATION.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    16 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from r8mat_print import r8mat_print
    from r8_uniform_ab import r8_uniform_ab

    print ''
    print 'INTEGRATION_TEST'
    print '  INTEGRATION computes the INTEGRATION matrix.'

    m = 6
    n = m

    r8_lo = -5.0
    r8_hi = +5.0
    seed = 123456789
    alpha, seed = r8_uniform_ab(r8_lo, r8_hi, seed)

    a = integration(alpha, n)
    r8mat_print(m, n, a, '  INTEGRATION matrix:')

    print ''
    print 'INTEGRATION_TEST'
    print '  Normal end of execution.'

    return