--- title: 20220923 Python tags: lab --- # Python :::info Written by Ian Lee and Huei-Wen Teng. Last update on 2022/9/23. ::: ### Download [Anaconda](https://www.anaconda.com/) Ananconda is leading open data science platform powered by Python 1. spyder: similar to Matlab 2. jupyter: useful for demonstration ![](https://i.imgur.com/jz4D33B.png) --- ### Basics of Python 1. Index starts from 0. 2. Types of variables: String, int, float, bool. 3. Types of data structure: | Type | Done| | --- | -----| | tuple | x= ('a', 'b'):heart: | | list | x= ['a', 'b'] | dictionary | x = {'one': 123, 'two': 345} | numpy array| |pandas: series, dataframe | 4. If, for, while 5. function and class --- ### [Scipy](https://scipy-lectures.org/) SciPy (pronounced “Sigh Pie”) is a Python-based ecosystem of open-source software for mathematics, science, and engineering. ![](https://i.imgur.com/tp6SfrD.png) --- ### [NumPy: Numerical Python](https://numpy.org/devdocs/user/quickstart.html#quickstart-tutorial) NumPy is the fundamental package for scientific computing with Python. It contains among other things: 1. a powerful N-dimensional array object 2. sophisticated (broadcasting) functions 3. tools for integrating C/C++ and Fortran code 4. useful linear algebra, Fourier transform, and random number capabilities --- ### Pandas Pandas stands for "Python Data Analysis Library". The name is derived from the term "panel data", an econometrics term for multidimensional structured data sets. 1. Pandas is for data munging 2. It proides Series and DataFrame data strucutre 3. It helps to retreive different formats of data ![](https://i.imgur.com/ZFHQyC6.png) --- ### Matplotlib Matplotlib is a Python 2D plotting library.  ![](https://i.imgur.com/kZ9L7wZ.png) ### 推薦書單 - [Python新手推薦](https://www.pttcc.org/bbs/Book/M.1584231070.A.A23) | No | 書名 | 網路(中文) | 網路(英文) | 華通(中文) |華通(英文) | 麗文(中) |麗文(英)| | --- | --- | --- | --- | ---| ---|---|---| | 1|精通 Python:運用簡單的套件進行現代運算 <br> Introducing Python: Modern Computing in Simple Packages, 2/e | 697 | | 695 | 1600 | 748 | |2|Python 自動化的樂趣:搞定重複瑣碎&單調無聊的工作 <br> Automate the Boring Stuff with Python: Practical Programming for Total Beginner| 485 | | 537 | NA | 578 | |3|Python錦囊妙計 第三版 <br> Python cookbook 3/e|[695](https://www.tenlong.com.tw/products/9789863470687)| | NA | 1580 | 704 | |4| Python專家實踐指南:搭乘專業開發者的學習便車 <br> The Hitchhiker's Guide to Python: Best Practices for Development|[458](https://www.tenlong.com.tw/products/9789864762859)| |470| NA | 784 | |5|流暢的 Python:清晰、簡潔、有效的程式設計 <br> Fluent Python|[774](https://www.books.com.tw/products/0010706172)| | NA | NA | 464 | |6| Python最強入門邁向頂尖高手之路:王者歸來 | 735 | | 910 | NA | 918 <!-- ## Hw 2 *Financial Options* 標的物: underlying asset 中華電 Let $S_t$ denote the stock price at time $t$. Let $T$ denote the maturity time. Let $S_0=106$, $r=0.05$, $T=1/12$, $\sigma=0.25$, strike = 105. A European call option has a payoff function $$\max(S_T-K, 0).$$ The European call option has a price $$c= e^{-rT}E[\max(S_T-K, 0)]=S_0 N(d_1)-Ke^{-rT}N(d_2),$$ $$d_1=\frac{\log\frac{S_0}{K}+(r+\frac{\sigma^2}{2})T}{\sigma\sqrt{T}}, \quad d_2 = d_1-\sigma\sqrt{T}.$$ 1. Calculate the European call option price using the Black-Scholes formula. --- ### A question on the Black-Scholes formula: If $Z\sim N(0, \sigma^2)$. Then $$E[e^{Z}]=e^{-\sigma^2/2}.$$ !-->