Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / March 2007

Tip: Looking for answers? Try searching our database.

Do I need to use VBA for the following control structure?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cfman - 01 Mar 2007 07:11 GMT
Hi all,

I have the following control structure from Matlab, do you think I need VBA
to handle it, or I can just rely on Excel?

Thanks a lot!

-----------------------------------------

   for t=1:5;
       CumLoss=CumLoss+sum(DefaultTime(:, t));

       if (CumLoss>TotalNotional*Deattachment)
           break;
       else
           PV=PV+y*(TotalNotional-CumLoss)/(1+r)^t;
           if t==5
               PV=PV+(TotalNotional-CumLoss)/(1+r)^t;
           end;
       end;
   end;
John Coleman - 01 Mar 2007 11:35 GMT
You can just rely on Excel:

In row 1 put the labels t,DefaultTime,
CumLoss,PV,TotalNotional,Deattachment,r,y respectively in columns A -
H
Leave A2,B2 blank. In C2,D2 put in initial values of CumLoss and PV
(perhaps 0) and in cells E2:H2 put in the values of the parameters
TotalNotional to y

Select E1:H2 and goto Insert/Names/Create and click ok on the default
"create in top row"

in cells A3:A7 put in the numbers 1 to 5 and in cells B3:B7 put in the
values of DefaultTime.
In cell C3 put in the formula =C2+SUM($B$3:B3)  (which should
correspond to CumLoss=CumLoss+sum(DefaultTime(:, t)); - but I don't
know matab and am just guessing what (:,t) means - is the implied
lower bound 1, or is there a 0 you haven't mentioned. If
DefaultTime(0) exists - put it in cell B2 and replace the sum by SUM($B
$2:B3)) and copy it down through C7

In cell D3 put the formula

=IF(C3>TotalNotional*Deattachment,D2,IF(A3<5,D2+y*(TotalNotional-C3)/
(1+r_)^A3,D2+(TotalNotional-C3)/(1+r_)^A3))

(with no line breaks - I hope Google doesn't mangle it). Note that for
some reason "r" is a reserved name in Excel (hence the underscore
automatically added on creation) but "y" isn't. Strange

and copy it through D7. The formula assumes that the numbers in
DefaultTime are non-negative (a connotation from the word
"cummulative"). If this assumption is false and you don't want PV to
change if CumLoss drops back below TotalNotional*Deattachment, the
formula would have to be adjusted a bit.

VBA of course *could* handle this and might give you more flexibility.

The moral of the story: In Excel

1) Names can be given to represent named parameters
2) Iteration is acheived by dragging a formula down a range
3) relatively complicated conditional logic can be acheived with built
in logical functions

The chief disadvantage is that the number of iterations needs to be
fixed (or at least given a fixed upper bound) at design time.

Hope that helps

-John Coleman

> Hi all,
>
[quoted text clipped - 17 lines]
>         end;
>     end;
Joel - 01 Mar 2007 11:42 GMT
It depends if you want the answer as a single response or you want the answer
in multple cells

I would make a column with t in the first column and number the rows from 0
to 5.  the use excel functions to put the answerr in a second column.

> Hi all,
>
[quoted text clipped - 17 lines]
>         end;
>     end;
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.