2014년 8월 23일 토요일

python Quantlib tutorial - Part2

이전 포스트에 이어서..

QuantLib을 빌드를 끝냈으면 다음으로 할일은 환경변수를 설정하는 일입니다.

환경변수에 다음을 추가 합니다.
QL_DIR 
    -quantlib이 설치된 경로를 지정합니다.
    -ex)  D:\QuantLib-1.2.1
INCLUDE
    - boost가 설치되어 있는 include 경로를 지정합니다.
    - ex) D:\boost_1_52_0


setup을 합니다.

QuantLib-SWIG\Python\setup.py  파일이 있는 경로에 가서 

$>python setup.py build

$>python setup.py test

$>python setup.py install

설치가 왼료되었습니다.

사실 swig Quantlib을 해보면서 빌드를 설치할때 까지 오래 걸린거 같습니다. 오프소스라는것이 본인이 스스로 설정을 해야 하는 부분이 많기 때문인것 같기도 하고 .. 환경변수를 설정하는것 또한 쉽지는 않더라구요 .. 



Very Easy: Find Yield to Maturity of a Bond from its Price[edit]

from QuantLib import *

effectiveDate = Date(30, 1, 1990)
terminationDate = Date(30, 1, 2000)

# The Schedule object determines the dates on which transactions occur.
s = Schedule( 
   effectiveDate, 
   terminationDate, 
   Period(Semiannual), 
   UnitedStates(UnitedStates.GovernmentBond), 
   ModifiedFollowing,
   ModifiedFollowing,
   DateGeneration.Backward,
   False
)

# FixedRateBond object's parameters
settlementDays = 3
faceAmount = 97.54
rate = 0.04 # this means 4%
redemption = 100.0 # this means 100% of the initial value.
todayDate = Date(24, 9, 1995) 

# Construct the object 
f = FixedRateBond( 
   settlementDays,
   faceAmount,
   s, # Schedule object
   ( rate, ), 
   ActualActual(), 
   Following, 
   redemption,
   todayDate
)

# The Bond's Yield to Maturity
f.bondYield( ActualActual(), Annual, Semiannual )


댓글 없음:

댓글 쓰기