Hi all,
I am presently learning Option trading strategies basic. My query relates to Section 1, unit 10. I just copied the code in my Jupyter and tried to run it on my own. When put_payoff is defined in the previus cell (I saved it but not getting the number 1 there), I am getting following error message. Is there any omission in what I did?
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_8044/63836793.py in <module>
----> 1 payoff_long_put = put_payoff(sT, strike_price, premium)
2 # Plot the graph
3 fig, ax = plt.subplots(figsize=(8,5))
4 ax.spines['bottom'].set_position('zero')
5 ax.plot(sT,payoff_long_put,label='Put option buyer payoff')
NameError: name 'put_payoff' is not defined
Hi Ramamurthy,
It looks like you didn't run the cell where you pasted the "put_payoff" function. You should run the cell in which the function is defined before running the cell in which the function is called.
Also if you want to run these jupyter notebooks in your own local machines. I recommend you to download the zip fine in the last section of the course. You will find all the jupyter notebooks included in the notebook here. You will need to set up a python environment before running these notebooks in your local machine. If you need help doing that you can follow this link.
Thanks Danishbhai for replying. I have a basic question. When I saved the file, I think it is one sequential set of code and the previous cell should too run is my assumption. Or I should keep the cursor in the first cell of code to run the entie file ?
Mr Danishbhai
I tried running the file keeping the cursor in first line of code and it ran. But I find that when I click run option the file runs one cell at a time. When the whole file will run at one step ? Is there any other step ?
Hello Mr Ramamurthy,
In a jupyter notebook, you have to run every cell individually. If you run the last cell of the notebook it won't automatically run all the cells above and similarly, if you run the first cell, it won't run all the following cells. You can think of each cell as an individual python file that needs to run individually.
If you want to run all the cells at once, there's a button for that. You can find this button 2 buttons right of the run button. This button has a double play icon. It's called Restart and run all. This button will restart the kernel and run all the cells in the same order they are in your notebook. For example, the first cell of your notebook will run first and then the second one and so on.
Some useful links:
How to Use Jupyter Notebook (Basics for Beginners + Best Practices)
How To Use Jupyter Notebooks | Codecademy