Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

asset.cpp

Go to the documentation of this file.
00001 #include ".\asset.h"
00002 
00003 
00004 /*------------------------------------------------------*/
00005 /*                 Flow Natural Implementation           */
00006 /*------------------------------------------------------*/
00007 
00008 flowSchedule::flowSchedule(void) 
00009 {
00010         _dateOfFlowPayment=Date();
00011         _FlowAmountInPercent=0;
00012         _businessDayConventionOnPaymentDate=Unadjusted;
00013 }
00014 
00015 flowSchedule::flowSchedule(Date date,Real percent,BusinessDayConvention bd)
00016 {
00017         _dateOfFlowPayment=date;
00018         _FlowAmountInPercent=percent;
00019         _businessDayConventionOnPaymentDate=bd;                           
00020 }
00021 
00022 flowSchedule::~flowSchedule(void)
00023 {
00024 };
00025 
00026 
00027 /*------------------------------------------------------*/
00028 /*                 Asset Natural Implementation           */
00029 /*------------------------------------------------------*/
00030 
00031 
00032 asset::asset(void)
00033 {
00034         _currentPrice=0.0;
00035         _yc=yieldCurve();
00036         _areDividendsAsGrowingRate=false;
00037         _dividendGrowingRate=0.0;
00038         _announcedDividendFlows=valarray<flowSchedule>();
00039         _denomCur=USD;
00040         _volatility=ASSET_DEFAULT_VOL;
00041 }
00042 
00043 asset::asset(Real price,yieldCurve yc,bool areDividendsAsRate,Real divRate,valarray<flowSchedule> flowsc,Currency ccy, Real volatility)
00044 {
00045         _currentPrice=price;
00046         _yc=yc;
00047         _areDividendsAsGrowingRate=areDividendsAsRate;
00048         _dividendGrowingRate=divRate;
00049         _announcedDividendFlows=flowsc;
00050         _denomCur=ccy;
00051         _volatility=volatility;
00052 }
00053 
00054 asset::asset(Real price, Real volatility)
00055 {
00056         _currentPrice=price;
00057         _volatility=volatility;
00058 
00059         // defaults
00060         _yc=yieldCurve();
00061         _areDividendsAsGrowingRate=false;
00062         _dividendGrowingRate=0.0;
00063         _announcedDividendFlows=valarray<flowSchedule>();
00064         _denomCur=USD;
00065 }
00066 
00067 Real asset::getRho(Real T){
00068         Real pu,pd;
00069         yieldCurve old=_yc,up=_yc.shiftZCBRateCurve(+0.001),down=_yc.shiftZCBRateCurve(-0.001);
00070         _yc=up;
00071         pu=forwardPrice(T);
00072         _yc=down;
00073         pd=forwardPrice(T);
00074         _yc=old;
00075         return (pu-pd)/0.002;
00076 }
00077 
00078 Real asset::forwardPrice(Real T){
00079         Date start;
00080         start.setDateToToday ();
00081         return forwardPrice (start.plusDays((Natural)(365*T)));
00082 }
00083 
00084 void asset::setDivAsRate(Real rate)
00085 {
00086         _areDividendsAsGrowingRate=true;
00087         _dividendGrowingRate =rate;
00088 }
00089 
00090 Real asset::Price()
00091 {
00092         return _currentPrice;
00093 }
00094 
00095 
00096 
00097 Real asset::forwardPrice(Date maturityDate){
00098         if(_areDividendsAsGrowingRate){
00099                 Date today=Date();
00100                 today.setDateToToday();
00101                 Real timetomaturity=today.dayCount(maturityDate,Day30_360);             
00102                 return _currentPrice*exp(-timetomaturity*_dividendGrowingRate);
00103         }
00104         else{
00105                 Real sum=0;
00106                 Natural i = 0;
00107                 while (i<_announcedDividendFlows.size() && _announcedDividendFlows[i].getDate()<=maturityDate){
00108                         sum+=_announcedDividendFlows[i].getAmount()*_yc.discountFactor(_announcedDividendFlows[i].getDate());
00109                         i++;
00110                 }
00111                 return _currentPrice*(1-sum);
00112         }
00113 }
00114 
00115 asset::~asset(void)
00116 {
00117 }

Note: Generated nightly - reload for latest version
Generated on Thu Dec 22 23:12:35 2005 for terreneuve by doxygen 1.3.6