This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Error unsupported operand type(s) for /: 'int' and 'str'  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have this code snipe:

where calc_lib is another file with the function:

Now I get the error:


d1 =  (np.log(S0/K) + (r + sigma**2 / 2) * T)/(sigma * np.sqrt(T))
TypeError: unsupported operand type(s) for /: 'int' and 'str'


which I just don't understand because i forced my inputs to be a float and therefor this shouldn't give me an error.
Can somebody help me here out?
The function does work if I define values instead of reading them from the bash.
 
Sheriff
Posts: 21747
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is in line 4:
You convert strike to a float, but you ignore the result of the conversion. strike isn't assigned a new value, so it remains the original string. Likewise for line 7.
 
Hans Peterson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help, that worked out for me. Unfortunately I now get the error:


TypeError: 'numpy.float64' object is not callable


in

I'm still wondering why it worked out fine when I didn't tried to read the values from the bash.
 
Hans Peterson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It now works out fine. In

I made brackets at d1,d2 because I had defined them as a function first.
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!