Statistics
1
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2026-03-25

AuthorStefan Papp

Maximize your portfolio, analyze markets, and make data-driven investment decisions using Python and generative AI. Investing for Programmers shows you how you can turn your existing skills as a programmer into a knack for making sharper investment choices. You’ll learn how to use the Python ecosystem, modern analytic methods, and cutting-edge AI tools to make better decisions and improve the odds of long-term financial success. In Investing for Programmers you’ll learn how to: Build stock analysis tools and predictive models Identify market-beating investment opportunities Design and evaluate algorithmic trading strategies Use AI to automate investment research Analyze market sentiments with media data mining In Investing for Programmers you'll learn the basics of financial investment as you conduct real market analysis, connect with trading APIs to automate buy-sell, and develop a systematic approach to risk management. Don’t worry—there’s no dodgy financial advice or flimsy get-rich-quick schemes. Real-life examples help you build your own intuition about financial markets, and make better decisions for retirement, financial independence, and getting more from your hard-earned money.

Tags
No tags
ISBN: 1633435806
Publish Year: 2026
Language: 英文
Pages: 370
File Format: PDF
File Size: 4.3 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

M A N N I N G Stefan Papp
Survey of the Tools and Techniques Covered in This Book Nonfinancial data Equity Crypto AI Agent Asset monitor Inference Charts Shares Private Debt Bonds Derivatives RAG DB Forex Crypto Currency Application Funds (ETF, Mutual, Hedge, Venture) As a collection of assets Financial data FundamentalsTechnical Sentiments ESG ratings Algorithmic trading Strategy / investment thesis Model context protocol (MCP) Income portfolio Value portfolio Growth portfolio Buy Sell Hold Net worth Profit/loss Moving averages Bollinger Bands Ichimoku loudC Chapter 2 Chapter 3 Chapters 4+5 Chapter 11Chapter 6 Chapter 8 Chapter 9 Chapter 10 Chapters 1+12 Risk management Hedging Stress tests Human factor Nonfinancial risk Portfolio optimization Chapter 7 Big data (earnings call reports, transcripts, web data,...) Financial platforms (Yahoo Finance, Finviz,...) Nonfinancial data platforms ML model LLM Securities Data Platforms Machine Learning API API API Decision-Making GenAI
Investing for Programmers STEFAN PAPP MANN I NG SHELTER ISLAND
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: orders@manning.com ©2026 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. The authors and publisher have made every effort to ensure that the information in this book was correct at press time. The authors and publisher do not assume and hereby disclaim any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from negligence, accident, or any other cause, or from any usage of the information herein. Manning Publications Co. Development editor: Connor O’Brien 20 Baldwin Road Technical editor: Anirudha Singh Bhadoriya PO Box 761 Review editor: Angelina Lazukić Shelter Island, NY 11964 Production editor: Kathy Rossland Copy editor: Julie McNamee Proofreader: Jason Everett Technical proofreader: Ignacio Beltran Torres Typesetter: Dennis Dalinnik Cover designer: Marija Tudor ISBN: 9781633435803 Printed in the United States of America
To all the entrepreneurs and innovators who dare to make a difference!
(This page has no text content)
brief contents 1 ■ The analytical investor 1 2 ■ Investment essentials 19 3 ■ Collecting data 52 4 ■ Growth portfolios 78 5 ■ Income portfolios 105 6 ■ Building an asset monitor 123 7 ■ Risk management 143 8 ■ AI for financial research 181 9 ■ AI agents 216 10 ■ Charts and technical analysis 239 11 ■ Algorithmic trading 273 12 ■ Private equity: Investing in start-ups 297 13 ■ The road goes ever on and on 321 appendix ■ Setting up the environment 330v
(This page has no text content)
contents preface xiii acknowledgments xv about this book xvii about the author xx about the cover illustration xxi 1 The analytical investor 1 1.1 Your investment journey 2 1.2 Assets 2 Stocks 3 ■ Bonds 4 ■ Exchange-traded funds 4 Other funds 5 ■ Foreign exchange market 5 ■ Crypto 5 Derivatives 6 ■ Private equity 6 ■ Other assets 7 Choosing assets 8 1.3 Investment approaches 8 Quantitative research 10 ■ Qualitative research 11 Algorithmic trading and asset monitors 12 ■ Portfolios and investing strategies 13 1.4 Risks and rewards 15 1.5 A programmer’s unfair advantage 16 You think in systems and data 16 ■ Your mindset is built for the market 16 ■ Define your parameters 17vii
CONTENTSviii2 Investment essentials 19 2.1 Accounting in a nutshell 20 Income statement 21 ■ Balance sheet 25 ■ Free cash flow 26 2.2 Industry classification 28 Influences on GICS sectors 28 ■ Sectors and economic cycles 30 2.3 Capitalization 32 2.4 Metrics and ratios 33 Liquidity 34 ■ Debt 36 ■ Earnings 36 ■ Valuation 37 Profitability 40 ■ Dividends 40 ■ Ownership 44 Sustainability 45 2.5 External assessments 46 Ratings 47 ■ Target prices 48 3 Collecting data 52 3.1 Financial data 53 3.2 Financial analysis platforms 54 3.3 Data science notebooks 57 3.4 yfinance 57 Fundamental analysis 58 ■ Technical analysis 61 Limitations of yfinance 66 3.5 Commercial libraries 67 Finviz 69 ■ EODHD 71 ■ Alpha Vantage 73 OpenBB 75 3.6 Other libraries 76 4 Growth portfolios 78 4.1 Investment thesis 79 Starting with an idea 79 ■ Challenging the idea 81 Your investment thesis 84 4.2 LiDAR market 85 Picking candidates 86 ■ Price development 88 ■ Debt 91 Management 92 ■ Technology and partnership 92 Projected earnings 94 4.3 Risks 95 Falling into obsolescence 96 ■ Squashed by industry giants 96 Globalization and conflicts 97
CONTENTS ix4.4 Ongoing analysis 97 Media 97 ■ Trend analysis 98 ■ News sentiment analysis 100 ■ Measuring success 101 4.5 What is next 101 5 Income portfolios 105 5.1 Dividends 106 5.2 Bonds 112 5.3 Crypto staking 117 Ledgers and exchanges 117 ■ Mining and staking 118 Affordable staking options 119 5.4 Early retirement 120 6 Building an asset monitor 123 6.1 Architecture 124 6.2 The spreadsheet 126 6.3 Extracting data 127 Alpaca: A developer-first broker 128 ■ Interactive Brokers: A legacy powerhouse with a modern twist 129 6.4 Enriching data 130 6.5 Processing assets 131 Stocks 131 ■ Exchange-traded funds 135 ■ Bonds 137 Cryptocurrencies 138 6.6 Outlook 141 7 Risk management 143 7.1 Ukemi 144 Stop-loss 144 ■ Risk classification 146 ■ Risk measurement 148 7.2 Generating risk profiles for individual stocks 150 Value at risk (VaR) 150 ■ Correlation 153 7.3 The human factor 156 Negligence 157 ■ Risk avoidance 157 ■ Resilience 159 7.4 Hedging 160 Derivatives 160 ■ Diversification 163 ■ Pair trading 163 Risk pairing 164
CONTENTSx7.5 Nonfinancial risk 165 Markets 166 ■ Economic data 166 ■ Assessing nonfinancial risk 168 7.6 Portfolio optimization 169 Markowitz-efficient portfolio 169 ■ Shiller P/E ratio 174 Rebalancing 176 8 AI for financial research 181 8.1 From code to machine learning 182 Unsupervised learning example 184 ■ Supervised learning example 187 ■ Market challenges 192 ■ Technical challenges 195 ■ Narrowing the scope 197 8.2 From machine learning to generative AI 198 Comparing LLMs 199 ■ Complementing ML with GenAI 200 ■ Challenges 200 ■ Final judgement on ML and GenAI 200 8.3 Practical use of GenAI 201 Using LLMs as research assistants 201 ■ Integrating LLMs into code 203 8.4 Prompt engineering 208 An investor’s profile 208 ■ Using prompts to find companies to invest in 211 9 AI agents 216 9.1 Requirements 217 Successful communication 217 ■ Agentic design patterns 218 9.2 Agentic workflows without frameworks 222 Prompt repository 222 ■ Export results 224 9.3 Framework for AI agents 228 From one-shot prompting to agents 229 ■ Retrieval-augmented generation 231 10 Charts and technical analysis 239 10.1 Charts 240 Reading charts 246 ■ Patterns 247 ■ Interpreting a chart 249 ■ Alternative chart types 250
CONTENTS xi10.2 Using charts to interpret price changes 253 Candlesticks 254 ■ Charts based on averages 257 Ichimoku Cloud 264 10.3 Visualization with Streamlit 267 11 Algorithmic trading 273 11.1 Nonfinancial data 274 Big data by example 276 11.2 Catalysts 278 Mergers and acquisitions 278 ■ Companies in distress 279 Earnings calls 280 ■ Disasters 281 ■ Interest rate changes 282 11.3 Trading algorithms 282 Backtesting 283 ■ Complex trading signals 287 11.4 Orders 289 Exchanges vs. brokers 289 ■ Order modifiers 291 Executing orders 292 12 Private equity: Investing in start-ups 297 12.1 From idea to initial public offering 298 The first minimum viable product (pre-seed) 298 ■ Validating the business model (seed) 301 ■ Scaling a start-up: The shift to institutional investment 303 ■ Exits: The final transition 304 12.2 Investment vehicles 306 Venture capital 308 ■ Angel networks 309 ■ Sovereign wealth funds 311 12.3 Assessing start-ups 312 Valuation 312 ■ Dilution 314 ■ Scoring 316 13 The road goes ever on and on 321 13.1 Getting advice 322 13.2 Stay curious 323 13.3 Alpha hunter 323 13.4 Nomadism 324 13.5 Activist investing 325
CONTENTSxii13.6 Measures of control 326 Checks and balances 326 ■ Gain distance 327 ■ Programmer’s journey 327 ■ Playing it safe 328 appendix Setting up the environment 330 index 339
preface Imagine this: a 50-year-old is approached by a genie with an intriguing offer. They can receive staggering wealth to never work again or be rejuvenated to age 20. The allure of reliving life with youth and wisdom is strong. But from a purely financial stand- point, which is the wiser choice? I grew up believing everyone must work until their mid-60s to retire. Stopping work at 50 seemed like pure luck. Over time, investing became my passion. I’ve learned that starting early and making informed investment decisions can make finan- cial independence by 50 achievable, especially if you know how to code. Programming sharpens the skills needed for better investment choices. I’ve always believed that work should serve a higher purpose, but meaningful work is often not the highest-paid. I wrote the book I wish I had at 20—to acceler- ate my path to financial freedom and independence from a paycheck. After read- ing it, all you’ll need is to find a genie who could send you back to age 20—armed with the knowledge to retire early. But even without the genie, what you learn here can transform how you invest, helping you move toward financial freedom with pur- pose and precision. I also want to convince you that investing can be fun. I love using programming to analyze companies and form data-backed investment theses. There’s nothing quite like seeing a company you believed in multiply in value fivefold or more. Of course, no path to wealth is guaranteed. You can pick the wrong horse. Picture the late 1990s: a friend tells you about a failing tech company whose ousted founder just returned and about a thriving American energy company riding the wave ofxiii
PREFACExivderegulation. If you chose the second, you picked Enron over Apple, and lost your investment. Diversification helps mitigate such risks, but the larger lesson is this: hubris and impatience are dangerous. Mindset matters most. In the early 2010s, I pivoted to big data. It wasn’t just about using more data but transforming entire businesses. I noticed some companies outsmarted others. If I invested in the smarter ones, I could ride their success. It was a natural progression: from using data to understand customer behavior to using data to predict which com- panies would thrive. Through this journey, I’ve found four key traits for investment success: critical thinking, patience, dedication, and curiosity. Programmers excel at these, and I believe they can shine as investors. Happy reading and coding! I wish you sharp insights and smarter investing.
acknowledgments I want to thank the following individuals, in chronological order, for their invaluable contributions to this book. When I first approached acquisition editor Jonathan Gennick with a proposal for a book that didn’t fit the typical mold at Manning, I knew approval wouldn’t come eas- ily. However, Jonathan believed in the project, and I’m convinced this book would have been impossible without his advocacy. I am also profoundly grateful to Connor O’Brien, an exceptional development edi- tor. His unwavering support and insightful feedback were instrumental in shaping the quality of this work. Technical editor Anirudha Bhadoriya provided an excellent review of the manu- script. His thoughtful questions and genuine engagement added valuable perspec- tives to the book. Anirudha is a staff software engineer specializing in distributed systems at Snowflake. He has been actively investing his own money in the equity mar- kets for more than 20 years, combining deep technical expertise with personal finan- cial acumen. Many thanks to Julie McNamee for copy editing and Azra Dedic for the support with the visualizations. Their input significantly improved the fine details of this book To all the reviewers—Amarjit Bhandal, Arun Kumar Rajamandrapu, Bin Li, Charles Lam, Chris Heneghan, Gary Bake, Ian Long, James Carella, Jeremy Chen, Juan Pablo Duque, Kevin Orr, Koushik Sundar, Marco Seguri, Nikhil Kassetty, Oscar Cao, Patrick Grütter, Pierre Boutquin, Piti Champeethong, Prateek Punj, Raghuram Katakam, Sahithi Donkina, Saketh Patibandla, Sneha Thangaraja, Sofiia Shvets,xv
ACKNOWLEDGMENTSxviThomas Heiman, Vijay Pahuja, Vinicios Wentz, and William Dealtry—your sugges- tions helped make this a better book. I want to thank all contributors through the Manning liveBook who provided feed- back on the book. I incorporated every piece of advice I received up to the production release, and I’ll also look at comments after the production release for new editions. Finally, a special thanks to Warren Buffett. Though he does not know me, he has served as an enduring role model for the kind of investor I strive to become.
about this book Investing for Programmers introduces tools and techniques for analyzing investment opportunities using Python and modern analytical methods. This book does not offer financial advice but shows you how to explore financial assets and make more informed investment decisions. After reading this book, you’ll be able to analyze financial assets with Python, build AI agents, and use LLMs to gain deeper insights into your investment options. Keep in mind that there are no guaranteed paths to wealth. This book may help you improve your odds of long-term financial success and increase your skills to gain insights for better decision-making. Be skeptical of anyone claiming risk-free riches. Who should read this book You should have basic programming skills. However, if you have only minimal experi- ence, you can still benefit from using large language models (LLMs) to help set up the environment and fill in any gaps in your Python knowledge. How this book is organized: A road map This book has 13 chapters. The book begins by teaching the basics, including inter- preting financial ratios and collecting data. As you progress, the topics become increasingly complex. You can always jump to later chapters if you’re experienced with the basics.  Chapter 1 introduces you to the investment domain and how programmers can excel.xvii
ABOUT THIS BOOKxviii Chapter 2 teaches financial basics and introduces you to key metrics for exploration.  Chapter 3 demonstrates collecting financial data using Python libraries, includ- ing Yahoo Finance and alternative libraries.  Chapter 4 teaches you how to create an investment thesis to look for growth portfolios.  Chapter 5 explains how to look for portfolios to create passive income.  Chapter 6 demonstrates how to collect data from brokers and exchanges, cen- tralize all holdings in one place, and facilitate their analysis.  Chapter 7 explains how to investigate risks and learn ways to hedge them. We look at Sharpe ratios and other methods.  Chapter 8 introduces AI for investment analysis. We introduce machine learning use cases and explore the application of generative AI in investment research.  Chapter 9 demonstrates how to use AI agents for more advanced use cases, enabling data exploration and the integration of additional data sources.  Chapter 10 shows how to display charts and technical analysis. You learn how to create charts using Bollinger Bands and other frameworks.  Chapter 11 explores algorithmic trading and the application of nonfinancial data in financial analysis.  Chapter 12 explores private equity as a form of ownership in startups and how to make informed investment decisions.  Chapter 13 summarizes what you learned and provides some final thoughts for the path ahead. About the code This book heavily uses source code, primarily in numbered listings throughout the chapters. The source code is formatted in a fixed-width font like this to distin- guish it from ordinary text. Sometimes, code is also bold to highlight changes from previous steps in the chapter, such as when a new feature is added to an existing line of code. In many cases, the source code has been reformatted, with line breaks and reworked indentation added to accommodate the available page space in the book. Additionally, comments in the source code have often been removed from the listing when the code is described in the text. Code annotations accompany many of the listings, high- lighting important concepts. You can get executable code snippets from this book’s liveBook (online) version at https://livebook.manning.com/book/investing-for-programmers. The source code for the examples in this book is available for download on the publisher’s website at www.manning.com/books/investing-for-programmers. The code is also available on GitHub at https://github.com/StefanPapp/investing-for-programmers.