Finance With Python - Tpq.io

3y ago
99 Views
22 Downloads
360.30 KB
19 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Joao Adcock
Transcription

Finance with PythonThe Python Quants GmbH training@tpq.io

Table of ContentsCopyrightPrefaceWhy this Course?Target AudienceOverview of the CourseBibliography1. Finance and Python1.1. Introduction1.2. A Brief History of Finance1.3. A Four Languages World1.4. The Approach of this Course1.5. Getting Started with Python1.6. Conclusions1.7. Further Resources2. Two State Economy2.1. Introduction2.2. Economy2.3. Real Assets2.4. Agents2.5. Time2.6. Money2.7. Cash Flow2.8. Return2.9. Interest2.10. Present Value2.11. Net Present Value2.12. Uncertainty2.13. Financial Assets2.14. Probability2.15. Expectation2.16. Expected Return2.17. Volatility2.18. Contingent Claims2.19. Replication

2.19. Replication2.20. Arbitrage Pricing2.21. Market Completeness2.22. Arrow-Debreu Securities2.23. Martingale Measure2.24. First Fundamental Theorem of Asset Pricing2.25. Martingale Pricing2.26. Second Fundamental Theorem of Asset Pricing2.27. Mean-Variance Portfolios2.28. Conclusions2.29. Further Resources3. Three State Economy3.1. Introduction3.2. Uncertainty3.3. Financial Assets3.4. Attainable Contingent Claims3.5. Martingale Measures3.6. Arbitrage and Martingale Pricing3.7. Super-Replication3.8. Approximative Replication3.9. Capital Market Line3.10. Capital Asset Pricing Model3.11. Conclusions3.12. Further Resources4. Optimality and Equilibrium4.1. Introduction4.2. Utility Maximization4.3. Graphical Solution4.4. Appropriate Utility Functions4.5. Logarithmic Function4.6. Time-Additive Utility4.7. Expected Utility4.8. Optimal Investment Portfolio4.9. Time-Additive Expected Utility4.10. Pricing in Complete Markets4.11. Arbitrage Pricing

4.11. Arbitrage Pricing4.12. Martingale Pricing4.13. Risk-Less Interest Rate4.14. A Numerical Example I4.15. Pricing in Incomplete Markets4.16. Martingale Measures in Incomplete Markets4.17. Equilibrium Pricing of Contingent Claims4.18. A Numerical Example II4.19. Conclusions4.20. Further Resources5. Static Economy5.1. Introduction5.2. Probability Space5.3. Random Variables5.4. Numerical Examples5.5. Financial Assets5.6. Contingent Claims5.7. Market Completeness5.8. Fundamental Theorems of Asset Pricing5.9. Black-Scholes-Merton Option Pricing5.10. Completeness of Black-Scholes-Merton5.11. Merton Jump-Di usion Option Pricing5.12. Representative Agent Pricing5.13. Conclusions5.14. Further Resources6. Dynamic Economy6.1. Introduction6.2. Binomial Option Pricing6.3. Black-Scholes-Merton Option Pricing6.4. Conclusions6.5. Further ResourcesAuthor Biography

CopyrightThis document as well as all related codes, Jupyter Notebooks and other materials onthe Quant Platform (http://pqp.io) are copyrighted and only intended for personal usein the context of a single user license for the Finance with Python Course(http://finpy.tpq.io). Any kind of sharing, distribution, duplication, etc. without writtenpermission by the The Python Quants GmbH is prohibited.The contents, Python codes, Jupyter Notebooks and other materials of this coursecome without warranties or representations, to the extent permitted by applicablelaw.Notice that this document is still work in progress and that substantial additions,changes, updates, etc. will take place over time. It is advised to regularly check fornew versions of the document.(c) Dr. Yves J. Hilpisch, March 2017

Preface“The financial industry has adopted Python at a tremendous raterecently, with some of the largest investment banks and hedge fundsusing it to build core trading and risk management systems.— Python for Finance (O'Reilly)Why this Course?Technological trends like online trading platforms, open source software and openfinancial data have significantly lowered or even completely removed the barriers ofentry to the global financial markets. Individuals with only limited amounts of cash attheir free disposal can get started, for example, with algorithmic trading within hours.Students and academics in financial disciplines with a little bit of backgroundknowledge in programming can easily apply cutting edge innovations in machine anddeep learning to financial data — on the notebooks they bring to their finance classes.On the hardware side, cloud providers offer professional compute and dataprocessing capabilities starting at 5 USD per month, billed by the hour and withalmost unlimited scalability. So far, academic and professional finance education hasonly partly reacted to these trends.The Finance with Python course teaches both finance and the Python (http://python.org)programming language from ground up. It presents all relevant foundations — frommathematics, finance and programming — in an integrated but not too technicalfashion. Traditionally, theoretical finance and computational finance have been moreor less separate disciplines. This has changed somewhat recently in that programmingclasses (e.g. in C ) have become an integral part of Master of Financial Engineeringand similar university programs.However, mathematical foundations, theoretical finance and basic programmingtechniques are still quite often taught independent from each other and only later oncombined to computational finance. This course takes a different approach in that themathematical concepts — for example, from linear algebra and probability theory —provide the common background against which financial ideas and programmingtechniques alike are introduced. Abstract mathematical concepts are therebymotivated from two different angles: finance and programming. In addition, this

approach allows for a new learning experience since both mathematical and financialconcepts can directly be translated into executable code that can then be exploredinteractively.Target AudienceThe Python Quants offer a number of live and online training classes in Python forFinance. Most of these expect the participants to have already some decentbackground knowledge in both finance and Python programming or a similarlanguage.This course starts completely from scratch, just expecting some basic knowledge inmathematics, in particular from calculus, linear algebra and probability theory.Although the course material is almost self-contained with regard to the mathematicalconcepts introduced, it is recommended to use an introductory mathematics book likethe one by Pemberton and Rau (2007) for references if needed.Given this approach, the course targets students, academics and professionals alikethat want to learn (more) about financial theory, data analysis and the use of Pythonfor computational finance. It is a perfect introduction to the field on which to buildthrough more advanced training classes offered by The Python Quants.Overview of the CourseCurrently, the course material is still under fast-paced development. Therefore, thefollowing gives a preliminary overview of the chapters as available already orplanned so far.Two State EconomyThe chapter covers the most simple model economy in which the analysis offinance under uncertainty is possible: there are only two relevant dates and twouncertain future states possible. One sometimes speaks of a static two stateeconomy. Despite its simplicity, the framework allows to introduce such basicnotions of finance as net present value, expected return, volatility, contingentclaims, option replication, arbitrage pricing, martingale measure, marketcompleteness, risk-neutral pricing and mean-variance portfolios.Three State Economy

This chapter introduces a third uncertain future state to the model, analyzing astatic three state economy. This allows to analyze such notions as marketincompleteness, indeterminacy of martingale measures, super-replication ofcontingent claims and approximative replication of contingent claims. It alsointroduces the Capital Asset Pricing Model as an equilibrium pricing approach forfinancial assets.Optimality and EquilibriumIn this chapter, agents with their individual decision problems are introduced. Theanalysis in this chapter mainly rests on the dominating paradigm in finance fordecision making under uncertainty: expected utility maximization. Based on a socalled representative agent equilibrium notions are introduced and the connectionbetween optimality and equilibrium on the one hand and martingale measures andrisk-neutral pricing on the other hand are illustrated. The representative agent isalso one way of overcoming the difficulties that arise in economies with incompletemarkets.Static EconomyThis chapter generalizes the previous notions and results to a setting with a finite,but possibly large, number of uncertain future states. It requires a bit moremathematical formalism to analyze this general static economy.Dynamic EconomyBuilding on the analysis of the general static economy, this chapter introducesdynamics to the financial modeling arsenal — to analyze two special cases of adynmic economy in discrete time. The basic insight is that uncertainty about futurestates of an economy in general resolves gradually over time. This can be modeledby the use of stochastic processes, an example of which is the binomial process thatcan be represented visually by a binomial tree.BibliographyThe following provides an overview of published works used for and referenced inthis course. The overview is not yet complete and will be updated over time as thewriting progresses. The single chapters have their own references section as well.Market Risk Analysis book collection:

Alexander, Carol (2008): Market Risk Analysis I — Quantitative Methods in Finance.John Wiley & Sons, Chicester.Alexander, Carol (2008): Market Risk Analysis II — Practical FinancialEconometrics. John Wiley & Sons, Chicester.Alexander, Carol (2008): Market Risk Analysis III — Pricing, Hedging and TradingFinancial Instruments. John Wiley & Sons, Chicester.Alexander, Carol (2008): Market Risk Analysis IV — Value-at-Risk Models. JohnWiley & Sons, Chicester.Mathematical books:Aleskerov, Fuad, Hasan Ersel and Dmitri Piontkovski (2011): Linear Algebra forEconomists. Springer, Heidelberg et al.Bhattacharya, Rabi and Edward Waymire (2007): A Basic Course in ProbabilityTheory. Springer Verlag, New York.Jacod, Jean and Philip Protter (2004): Probability Essentials. Springer, Berlin andHeidelberg.Pemberton, Malcolm and Nicholas Rau (2007): Mathematics for Economists — AnIntroductory Textbook. 2nd ed., Manchester University Press, Manchester and NewYork.Rudin,Walter (1987): Real and Complex Analysis. 3rd ed., McGraw-Hill, London.Schneider, Hans and George Barker (1973): Matrices and Linear Algebra. Reprint1989, Dover Publications, New York.Sundaram, Rangarajan (1996): A First Course in Optimization Theory. CambridgeUniversity Press, Cambridge.Williams, David (1991): Probability with Martingales. Reprint 2001, CambridgeUniversity Press, Cambridge.Basic Python books:McKinney, Wes (2017): Python for Data Analysis. 2nd ed., O’Reilly, Beijing et al.Ramalho, Luciano (2016): Fluent Python. O’Reilly, Beijing et al.

Ravenscroft, Anna, Steve Holden, Alex Martelli (2017): Python in a Nutshell. 3rd ed.,O’Reilly, Beijing et al.VanderPlas, Jake (2016): Python Data Science Handbook. O’Reilly, Beijing et al.Python for finance books:Hilpisch, Yves (2014): Python for Finance. O’Reilly, Beijing et al.Hilpisch, Yves (2015): Derivatives Analytics with Python. Wiley Finance.Finance papers:Black, Fischer and Myron Scholes (1973): “The Pricing of Options and CorporateLiabilities.” Journal of Political Economy, Vol. 81, No. 3, 638–659.Boyle, Phelim (1977): “Options: A Monte Carlo Approach.” Journal of FinancialEconomics, Vol. 4, No. 4, 322–338.Cox, John and Stephen Ross (1976): “The Valuation of Options for AlternativeStochastic Processes.” Journal of Financial Economics, Vol. 3, 145-166.Cox, John, Jonathan Ingersoll and Stephen Ross (1985): “A Theory of the TermStructure of Interest Rates.” Econometrica, Vol. 53, No. 2, 385–407.Cox, John, Stephen Ross and Mark Rubinstein (1979): “Option Pricing: A SimplifiedApproach.” Journal of Financial Economics, Vol. 7, No. 3, 229–263.Harrison, Michael and David Kreps (1979): “Martingales and Arbitrage inMultiperiod Securities Markets.” Journal of Economic Theory, Vol. 20, 381–408.Harrison, Michael and Stanley Pliska (1981): “Martingales and Stochastic Integralsin the Theory of Continuous Trading.” Stochastic Processes and their Applications,Vol. 11, 215–260.Heston, Steven (1993): “A Closed-Form Solution for Options with StochasticVolatility with Applications to Bond and Currency Options.” The Review ofFinancial Studies, Vol. 6, No. 2, 327–343.Longstaff, Francis and Eduardo Schwartz (2001): “Valuing American Options bySimulation: A Simple Least Squares Approach.” Review of Financial Studies, Vol. 14,No. 1, 113–147.Markowitz, Harry (1952): “Portfolio Selection.” Journal of Finance, Vol. 7, No. 1, 7791.

Merton, Robert (1976): “Option Pricing when the Underlying Stock Returns areDiscontinuous.” Journal of Financial Economics, No. 3, Vol. 3, 125-144.Perold, André (2004): “The Capital Asset Pricing Model.” Journal of EconomicPerspectives, Vol. 18, No. 3, 3-24Protter, Philip (2001): “A Partial Introduction to Financial Asset Pricing Theory.”Stochastic Processes and their Applications, Vol. 91, 169–203.Sharpe, William (1964): “Capital Asset Prices: A Theory of Market Equilibriumunder Conditions of Risk.” The Journal of Finance, Vol. 19, No. 3, 425-442.Basic finance and economics books:Copeland, Thomas, Fred Weston and Kuldepp Shastri (2005): Financial Theory andCorporate Policy. 4th ed., Addison Wesley, Boston et al.Eichberger, Jürgen and Ian Harper (1997): Financial Economics. Oxford UniversityPress, New York.Milne, Frank (1995): Finance Theory and Asset Pricing. Oxford University Press,New York.Markowitz, Harry (1959): Portfolio Selection — Efficient Diversification ofInvestments. John Wiley & Sons, New York et al.Pliska, Stanley (1997): Introduction to Mathematical Finance. Blackwell Publishers,Malden and Oxford.Rubinstein, Mark (2006): A History of the Theory of Investments. Wiley Finance,Hoboken.Varian, Hal (1992): Microeconomic Analysis. 3rd ed., W.W. Norton & Company, NewYork and London.Advanced finance books:Baxter, Martin and Andrew Rennie (1996): Financial Calculus — An Introduction toDerivative Pricing. Cambridge University Press, Cambridge.Björk, Tomas (2004): Arbitrage Theory in Continuous Time. 2nd ed., OxfordUniversity Press, Oxford.Delbaen, Freddy and Walter Schachermayer (2004): The Mathematics of Arbitrage.Springer Verlag, Berlin.

Duffie, Darrell (1988): Security Markets — Stochastic Model. Academic Press, SanDiego et al.Elliot, Robert and Ekkehard Kopp (2005): Mathematics of Financial Markets. 2nded., Springer Verlag, New York.Glasserman, Paul (2004): Monte Carlo Methods in Financial Engineering. SpringerVerlag, New York.

1. Finance and Python“Python is now wide-spread across investment banking and hedgefunds. Banks use Python for pricing, risk management and trademanagement platforms. More recently, they’ve been reprogrammingtheir trading systems to run off Python rather than other, clunkierlanguages.— efinancialcareers (2016)1.1. IntroductionThis chapter gives a concise overview of topics relevant for the course Finance withPython. It is intended to provide both the financial and technological framework forthe chapters to follow.1.2. A Brief History of FinanceThe history of finance as a scientific field can be divided roughly into three periodsaccording to Rubinstein (2006):the ancient period: pre-1950 — a period mainly characterized by informalreasoning, rules of thumb and experience of market practitionersthe classical period: 1950-1980 — a period characterized by the introduction offormal reasoning and mathematics to the field; specialized models (e.g. Black andScholes (1973) option pricing model) as well as general frameworks (e.g. Harrisonand Kreps (1979) risk-neutral pricing approach) have been developed during thisperiodthe modern period: post-1980 — this period has generated many advances inspecific sub-fields of finance (e.g. computational finance) and has tackled, amongothers, important empirical phenomena in the financial markets, such asstochastic interest rates (e.g. Cox, Ingersoll and Ross (1985)) or stochastic volatility(eg. Heston (1993))One might add a fourth one today:

the computational period: post-2000 — this current period sees a shift from atheoretical focus in finance towards a computational one, driven by advances inboth hardware and software used in finance; the paper by Longstaff and Schwartz(2001) — providing an efficient numerical algorithm to value American options byMonte Carlo simulation — illustrates this paradigm shift quite well; their algorithmis computationally demanding in that 100,000s of simulations and multipleordinary least-squares regressions are required in general to value a single optiononlyThe evolution of finance over time is characterized by three major trends:mathematics: starting in the 1950s with the classical period, finance has become amore and more formalized discipline making systematic use of different fields inmathematics, like linear algebra or stochastic calculus; the mean-varianceportfolio (MVP) theory by Markowitz (1952) can be considered a majorbreakthrough in quantitative finance if not its starting point itself — leaving theancient period characterized mainly by informal reasoning behindtechnology: the wide-spread availability and use of personal computers, workstations and servers, starting mainly in the 1980s, brought more and moretechnology to the field; while compute power and capacity in the beginnings wererather limited, they have reached levels as of today that allow to attack even themost complex problems in finance by sheer brute force, rendering the search forrather specialized, efficient models and methods — that characterized the classicaland modern periods — often obsolete; the credo has become: “Scale yourhardware and use modern software in combination with appropriate numericalmethods.”; on the other hand, modern hardware found in most dorm and livingrooms is already that powerful that even high performance approaches, likeparallel processing, can generally be used on such commodity hardware —lowering the barriers of entry to computational finance tremendouslydata: while researchers and practitioners alike mainly relied on printed financialinformation and data in the ancient and classical periods (think of the Wall StreetJournal or the Financial Times), electronic financial data sets have become morewidely available starting in the modern period; however, the computationalperiod has seen an explosion in the availability of financial data; high-frequencyintraday data sets have become the norm and have replaced end-of-day closingprices as the major basis for empirical research; a single stock might generateintraday data sets with well over 10,000 data points every trading day — this

number is roughly the equivalent of 40 years worth of end-of-day closing prices forthe same stock (252 trading days per year times 40 years); even more recently, aproliferation in open or free data sets has been observed which also significantlylowers the barriers of entry to computational finance, algorithmic trading orfinancial econometrics1.3. A Four Languages WorldAgainst this background, finance has become a world of four languages:natural language: the English language is today the only relevant language in thefield when it comes to published research, books, articles or newsfinancial language: like every other field, finance has technical terms, notions andexpressions that describe certain phenomena or ideas probably not seen in manyother aresmathematical language: mathematics is the tool and language of choice when itcomes to formalizing the notions and concepts of financeprogramming language: as the quote at the beginning of this chapter points out,Python (http://python.org) as a programming language has become the language ofchoice in many corners of the financ

VanderPlas, Jake (2016): Python Data Science Handbook. O’Reilly, Beijing et al. Python for finance books: Hilpisch, Yves (2014): Python for Finance. O’Reilly, Beijing et al. Hilpisch, Yves (2015): Derivatives Analytics with Python. Wiley Finance. Finance papers: Black, Fischer and Myron Scholes (1973): “The Pricing of Options and Corporate

Related Documents:

Python Programming for the Absolute Beginner Second Edition. CONTENTS CHAPTER 1 GETTING STARTED: THE GAME OVER PROGRAM 1 Examining the Game Over Program 2 Introducing Python 3 Python Is Easy to Use 3 Python Is Powerful 3 Python Is Object Oriented 4 Python Is a "Glue" Language 4 Python Runs Everywhere 4 Python Has a Strong Community 4 Python Is Free and Open Source 5 Setting Up Python on .

Python 2 versus Python 3 - the great debate Installing Python Setting up the Python interpreter About virtualenv Your first virtual environment Your friend, the console How you can run a Python program Running Python scripts Running the Python interactive shell Running Python as a service Running Python as a GUI application How is Python code .

Merritt Island Patrick Air Force Base Grand mama Island San Salvador Island Grand Turk Island Antiqua Bermuda Grand Canary Island Ascension Island Pretoria, South Africa Carnarvon, Australia Woomera, Australia Kauai, Hawaii Point Arguello California White Sands Eglin Air Force Base 'Radar Tme FPS-16 TPQ-15 FPQ-6 FPS-16 TPQ-1f FPS-16 TPQ-1f FPQ-6

Python is readable 5 Python is complete—"batteries included" 6 Python is cross-platform 6 Python is free 6 1.3 What Python doesn't do as well 7 Python is not the fastest language 7 Python doesn't have the most libraries 8 Python doesn't check variable types at compile time 8 1.4 Why learn Python 3? 8 1.5 Summary 9

site "Python 2.x is legacy, Python 3.x is the present and future of the language". In addition, "Python 3 eliminates many quirks that can unnecessarily trip up beginning programmers". However, note that Python 2 is currently still rather widely used. Python 2 and 3 are about 90% similar. Hence if you learn Python 3, you will likely

There are currently two versions of Python in use; Python 2 and Python 3. Python 3 is not backward compatible with Python 2. A lot of the imported modules were only available in Python 2 for quite some time, leading to a slow adoption of Python 3. However, this not really an issue anymore. Support for Python 2 will end in 2020.

A Python Book A Python Book: Beginning Python, Advanced Python, and Python Exercises Author: Dave Kuhlman Contact: dkuhlman@davekuhlman.org

3rd Grade – Persuasive Essay . Teachers may want to invest time in reading Kindergarten-Second Grade MAISA Writing Units of study or talk to previous grade level teachers before beginning this unit. If students have not had previous experience in a writing workshop or with aligned units of study, teachers may want to include lessons from previous grade levels as support and build towards .