Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #94730 > unrolled thread

How to Calculate NPV?

Started byryguy7272 <ryanshuell@gmail.com>
First post2015-07-29 06:58 -0700
Last post2015-07-30 15:18 +0100
Articles 7 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  How to Calculate NPV? ryguy7272 <ryanshuell@gmail.com> - 2015-07-29 06:58 -0700
    Re: How to Calculate NPV? Saber Ayoub Chelaghma <saber.chelaghma@gmail.com> - 2015-07-29 07:09 -0700
    Re: How to Calculate NPV? ryguy7272 <ryanshuell@gmail.com> - 2015-07-29 07:21 -0700
      Re: How to Calculate NPV? ryguy7272 <ryanshuell@gmail.com> - 2015-07-29 07:27 -0700
        Re: How to Calculate NPV? duncan smith <buzzard@invalid.invalid> - 2015-07-29 17:14 +0100
      Re: How to Calculate NPV? Terry Reedy <tjreedy@udel.edu> - 2015-07-29 15:08 -0400
      Re: How to Calculate NPV? Dave Farrance <df@see.replyto.invalid> - 2015-07-30 15:18 +0100

#94730 — How to Calculate NPV?

Fromryguy7272 <ryanshuell@gmail.com>
Date2015-07-29 06:58 -0700
SubjectHow to Calculate NPV?
Message-ID<249a5b7e-0364-4b74-94f4-c8bbfbba2479@googlegroups.com>
I am using Spyder Python 2.7.  I'm running this sample code.

import scipy as sp
cashflows=[50,40,20,10,50]
npv=sp.npv(0.1,cashflows)
round(npv,2)


Now, I'm trying to get the NPV, and I don't see any obvious way to get it.  
The author of the book that I'm reading gets 144.56.  I think that's wrong, but I don't know for sure, as Python won't do any calculation at all.  It's easy to enter code and run it, but I can't tell how to get Python to actually DO the calculation.

Any idea what I'm doing wrong?

[toc] | [next] | [standalone]


#94731

FromSaber Ayoub Chelaghma <saber.chelaghma@gmail.com>
Date2015-07-29 07:09 -0700
Message-ID<b6084854-368a-4c29-832b-5cd8b44786aa@googlegroups.com>
In reply to#94730
On Wednesday, July 29, 2015 at 3:59:10 PM UTC+2, ryguy7272 wrote:
> I am using Spyder Python 2.7.  I'm running this sample code.
> 
> import scipy as sp
> cashflows=[50,40,20,10,50]
> npv=sp.npv(0.1,cashflows)
> round(npv,2)
> 
> 
> Now, I'm trying to get the NPV, and I don't see any obvious way to get it.  
> The author of the book that I'm reading gets 144.56.  I think that's wrong, but I don't know for sure, as Python won't do any calculation at all.  It's easy to enter code and run it, but I can't tell how to get Python to actually DO the calculation.
> 
> Any idea what I'm doing wrong?


Hi,
Just do at the end of your scrip:
print(npv)

Regards

[toc] | [prev] | [next] | [standalone]


#94732

Fromryguy7272 <ryanshuell@gmail.com>
Date2015-07-29 07:21 -0700
Message-ID<757d1a56-fc27-4996-acff-8bb7e07204d6@googlegroups.com>
In reply to#94730
On Wednesday, July 29, 2015 at 9:59:10 AM UTC-4, ryguy7272 wrote:
> I am using Spyder Python 2.7.  I'm running this sample code.
> 
> import scipy as sp
> cashflows=[50,40,20,10,50]
> npv=sp.npv(0.1,cashflows)
> round(npv,2)
> 
> 
> Now, I'm trying to get the NPV, and I don't see any obvious way to get it.  
> The author of the book that I'm reading gets 144.56.  I think that's wrong, but I don't know for sure, as Python won't do any calculation at all.  It's easy to enter code and run it, but I can't tell how to get Python to actually DO the calculation.
> 
> Any idea what I'm doing wrong?
 
PERFECT!!  SO SIMPLE!!
I don't know why the author didn't do that in the book.

Thanks!

[toc] | [prev] | [next] | [standalone]


#94735

Fromryguy7272 <ryanshuell@gmail.com>
Date2015-07-29 07:27 -0700
Message-ID<9f04969b-6b6b-4773-a1f1-37e23706aecf@googlegroups.com>
In reply to#94732
On Wednesday, July 29, 2015 at 10:21:35 AM UTC-4, ryguy7272 wrote:
> On Wednesday, July 29, 2015 at 9:59:10 AM UTC-4, ryguy7272 wrote:
> > I am using Spyder Python 2.7.  I'm running this sample code.
> > 
> > import scipy as sp
> > cashflows=[50,40,20,10,50]
> > npv=sp.npv(0.1,cashflows)
> > round(npv,2)
> > 
> > 
> > Now, I'm trying to get the NPV, and I don't see any obvious way to get it.  
> > The author of the book that I'm reading gets 144.56.  I think that's wrong, but I don't know for sure, as Python won't do any calculation at all.  It's easy to enter code and run it, but I can't tell how to get Python to actually DO the calculation.
> > 
> > Any idea what I'm doing wrong?
>  
> PERFECT!!  SO SIMPLE!!
> I don't know why the author didn't do that in the book.
> 
> Thanks!

One last thing, for Excel users, leave out the initial CF.  Do the NPV on the other CFs, and then add in the initial CF at the end of the NPV function.  It's almost like a PV + 1stCF.  I don't know why Excel does it like that...

[toc] | [prev] | [next] | [standalone]


#94741

Fromduncan smith <buzzard@invalid.invalid>
Date2015-07-29 17:14 +0100
Message-ID<55b8fbf1$0$10731$862e30e2@ngroups.net>
In reply to#94735
On 29/07/15 15:27, ryguy7272 wrote:
> On Wednesday, July 29, 2015 at 10:21:35 AM UTC-4, ryguy7272 wrote:
>> On Wednesday, July 29, 2015 at 9:59:10 AM UTC-4, ryguy7272 wrote:
>>> I am using Spyder Python 2.7.  I'm running this sample code.
>>>
>>> import scipy as sp
>>> cashflows=[50,40,20,10,50]
>>> npv=sp.npv(0.1,cashflows)
>>> round(npv,2)
>>>
>>>
>>> Now, I'm trying to get the NPV, and I don't see any obvious way to get it.  
>>> The author of the book that I'm reading gets 144.56.  I think that's wrong, but I don't know for sure, as Python won't do any calculation at all.  It's easy to enter code and run it, but I can't tell how to get Python to actually DO the calculation.
>>>
>>> Any idea what I'm doing wrong?
>>  
>> PERFECT!!  SO SIMPLE!!
>> I don't know why the author didn't do that in the book.
>>
>> Thanks!
> 
> One last thing, for Excel users, leave out the initial CF.  Do the NPV on the other CFs, and then add in the initial CF at the end of the NPV function.  It's almost like a PV + 1stCF.  I don't know why Excel does it like that...
> 

I don't know what Excel does, but the first value shouldn't require any
special treatment, 1.1**0 = 1.

>>> sum([x/(1.1)**i for i, x in enumerate([50,40,20,10,50])])
144.55638276074038
>>>

Duncan

[toc] | [prev] | [next] | [standalone]


#94750

FromTerry Reedy <tjreedy@udel.edu>
Date2015-07-29 15:08 -0400
Message-ID<mailman.1079.1438196929.3674.python-list@python.org>
In reply to#94732
On 7/29/2015 10:21 AM, ryguy7272 wrote:
> On Wednesday, July 29, 2015 at 9:59:10 AM UTC-4, ryguy7272 wrote:
>> I am using Spyder Python 2.7.  I'm running this sample code.
>>
>> import scipy as sp
>> cashflows=[50,40,20,10,50]
>> npv=sp.npv(0.1,cashflows)
>> round(npv,2)
>>
>>
>> Now, I'm trying to get the NPV, and I don't see any obvious way to get it.
>> The author of the book that I'm reading gets 144.56.  I think that's wrong, but I don't know for sure, as Python won't do any calculation at all.  It's easy to enter code and run it, but I can't tell how to get Python to actually DO the calculation.
>>
>> Any idea what I'm doing wrong?
>
> PERFECT!!  SO SIMPLE!!
> I don't know why the author didn't do that in the book.

The book show you how to calculate things.  It is up to you to display, 
output to a file, or use in further calculation.  I do admit, though, 
that snippets that show how to use an existing function, rather than 
define a new function, might benefit from adding print(xxxx).

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#94775

FromDave Farrance <df@see.replyto.invalid>
Date2015-07-30 15:18 +0100
Message-ID<2hbkrat6h80cafs23roj46ojh9tbi4t12j@4ax.com>
In reply to#94732
ryguy7272 <ryanshuell@gmail.com> wrote:

>PERFECT!!  SO SIMPLE!!
>I don't know why the author didn't do that in the book.

The book is evidently giving you code snippets to enter into Python's
own interactive interpreter, i.e., you enter "python" at the command
line, then you manually type each command which immediately displays any
returned value.  I assume that the book shows each command with three
chevrons ">>>" in front of them.  If you're using Spyder then you need
to enter the commands into its interactive interpreter (which I think is
bottom right). It sounds, instead, as though you're using Spyder's text
editor to create a file containing the commands, and then using the
"run" icon to run the file -- which is maybe skipping ahead because the
book hasn't told you how to do that yet (?). If you do skip ahead, the
book probably has a forthcoming chapter called "writing programs with a
text editor" or something.  I'd guess from the code snippets that you've
shown us that the book is finance oriented, and the author seems to be
more interested in introducing the features useful for finance than
teaching the basics of Python.  Maybe you should search out a simple
Python primer on the web, work through that, and only then return to
your book.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web