Trader to Trader - Chen Meng

By Chen Meng

This content is for educational and informational purposes only and should not be construed as investment advice, a recommendation, or an offer to buy or sell any security. Any strategies discussed are illustrative only and may not be suitable for all investors. This article reflects the experience of an individual user, is not representative of all customers, and should not be considered an endorsement or guarantee of future performance. The views and opinions expressed are those of the author and do not reflect or represent the views and opinions of Alpaca. Alpaca does not recommend any specific securities or investment strategies. The author was not compensated for this content but did receive nominal promotional items from Alpaca.

From Software Engineering to Quant Trading Research: How a Book Changed My Approach to the Market

I moved to New York four years ago as a software engineer. At the time, my approach to the stock market was simple: I invested heavily in the tech sector because it was the industry I knew best.

That changed when I started meeting friends in New York who worked at quantitative trading firms. They introduced me to the world of quant trading, and my curiosity was sparked.

Wanting to learn more, I kept seeing one specific recommendation pop up across videos and online discussions: Ernest P. Chan’s book, Quantitative Trading: How to Build Your Own Algorithmic Trading Business. I decided to pick up a copy.

Reading it opened up a completely new perspective for me. For the first time, I began exploring whether historical price data exhibited mathematical and statistical relationships. 

While the math was exciting, the real turning point was something surprisingly simple. Dr. Chan explained that an individual could set up a quantitative trading operation using basic tools like Excel spreadsheets. You didn't need millions of dollars, complex infrastructure, or servers placed right next to stock exchange centers. Quantitative trading wasn't reserved exclusively for massive Wall Street firms; it was something a single developer could do from home.

As a software engineer, that was my lightbulb moment: If people can study automated trading systems with spreadsheets, I could use modern code to build and test a more detailed research workflow. That realization was the spark that started my journey toward building my own automated trading system.

Finding the Right Bridge to the Market: Discovering Alpaca

Once I decided to build my own trading system, I needed a way for my code to interact with the stock market. I started searching Google and Reddit for "APIs for stock market," which is how I found Alpaca.

What immediately caught my attention was how developer-friendly it was. For every feature, their documentation provided a quick-start example that required zero setup. I could simply copy a command, run it in my computer's terminal, and instantly see a trade executed in real time. It was an easy and direct way to connect code to the financial markets.

Another benefit was the low barrier to entry. Alpaca allowed me to start testing without upfront costs, subscription fees, or commission hurdles. When you're experimenting with new ideas taking financial friction out of the equation makes it much easier to dive in and start learning.

Sequence diagram for the research workflow

Understanding the Strategy: A Simple Approach to Mean-Reversion

There are many ways to trade algorithmically, but I chose a strategy called mean-reversion.

The concept behind mean-reversion is that certain securities may historically exhibit related price behavior. A researcher may test whether deviations from a modeled relationship have previously reverted toward a historical average. These relationships can change or disappear, and a strategy based on them may produce losses.

To turn this concept into a working system, I follow a straightforward three-step process:

  1. Forming a Hypothesis: I look for assets that share a natural real-world relationship. This could be direct competitors in the same industry, an ETF and its underlying stocks, or companies tied to the same supply chain.
  2. Testing with Data: Once I have a pair or group of stocks in mind, I look at historical price data to test whether their prices historically exhibited a statistical relationship - —a statistical property known as cointegration. I use standard statistical checks (like the Augmented Dickey Fuller Test) to evaluate  the historical data. Statistical results depend on the selected data and methodology and do not confirm future behavior.
  3. Validating Before Live Capital: If the data supports the pattern, I move the model into backtesting (testing against past data) and paper trading (simulating live market conditions without real money). Once it proves consistent, it gets approved to execute real trades.
Sample research report by the agent, for informational purposes only, not a suggestion for investment, as clearly indicated by the agent to abandon this model

*Please note that any securities seen above are shown solely for illustrative purposes and are not a recommendation to buy, sell, or hold any security.

Maintaining The Strategy: Continuous Validation and Adaptation

No trading strategy works forever without maintenance. Financial markets are constantly evolving, consumer habits change, new regulations emerge, and macroeconomic conditions shift. A pattern that generated steady profits last year might gradually fade away or stop working altogether.

Because of this natural decay, I don't let my models run on autopilot with static rules. Instead, I continuously re-validate and adapt them over time.

To keep the models aligned with current market conditions, I use a simple "sliding window" update process:

  1. Drop the Old: Every month, I discard the oldest month of historical price data from the dataset.
  2. Add the New: I incorporate the newest month of live market data.
  3. Rebuild & Retrain: I recalculate the statistical relationships and rebuild the model using this updated timeframe.

By constantly rolling the dataset forward, the trading agent stays tuned to recent market behavior while shedding outdated patterns that no longer reflect reality.

My Workflow: Combining Alpaca’s API, Alpaca’s MCP, and AI Automation

System architecture for research, trade execution, and reporting

Building a complete trading setup involves multiple data, research, execution, and monitoring components. For this project, I paired Alpaca’s Trading API with AI-assisted tools to support tasks from pre-market setup to order execution and a dashboard view.

1. Smart Trade Execution with Alpaca’s API

I rely on a few key actions from Alpaca’s Trading API to keep the system running smoothly:

  • Pre-Market Account Check: Before the market opens, the agent checks my current portfolio and account balances to apply my predefined allocation rules across different strategies.
  • Live Price Tracking: The system continuously monitors real-time market data to calculate price signals on the fly.
  • Immediate-or-Cancel Order Handling: An IOC instruction requires all or part of an order to execute immediately and cancels any unfilled portion. It does not guarantee execution, a favorable price, or protection from slippage. Results depend on the order type, available liquidity, and market conditions.

2. The Power of Alpaca’s MCP Server

One of the biggest productivity boosters in my setup is using Alpaca’s Model Context Protocol (MCP) server. MCP acts as an intelligent bridge between the AI agent and the trading platform:

  • Structured API Context: The MCP server can provide the AI system with information about available API capabilities and data formats. It may reduce certain errors, but it does not eliminate inaccurate, fabricated, incomplete, or outdated AI outputs. Users should independently verify generated responses and code.
  • Instant Documentation Retrieval: Instead of reading through long API manuals or parsing massive raw data files myself, I can simply ask the AI questions about documentation through the MCP server and get precise, instant answers.

3. Building Custom Dashboards

Combining Alpaca's API with MCP and AI-assisted coding helped me prototype a custom tool effortlessly. For example, when I needed a custom visualization dashboard, I didn't code it from scratch. I simply told the AI: "I want a line chart showing my cumulative daily profits and losses over time."

The AI queried the MCP server for the right data, built the dashboard, and had it turning what used to take days of frontend development into a simple conversational prompt.

Cursor IDE connected to Alpaca’s MCP Server

Finding the Right Balance: Combining AI and Programmatic Automation

When building an automated trading system, it’s tempting to imagine letting an AI agent trade completely on its own making every split-second decision autonomously. While that idea sounds exciting, real-money execution requires a far more pragmatic approach.

In my system, I divide responsibilities between AI and deterministic code execution:

  • What the AI Handles: Researching hypotheses, calculating model outputs, generating dashboard visualizations, performing strategy analysis, and writing test code.
  • What Code Automation Handles: Checking account balances, monitoring order statuses, running continuous price checks, and executing trades.
  • Why I Don't Let AI Place Trades Directly: While AI is incredible for analysis and code generation, I rely strictly on programmatic code for trade execution due to three key trade-offs:
    • Cost Considerations: AI models may incur usage-based costs. Programmatic code may reduce the need for repeated model queries, although hosting, data, infrastructure, and other costs may still apply.
    • Execution Speed: Programmatic code can generally evaluate predefined instructions faster than waiting for language-model output. However, latency, slippage, connectivity issues, and other execution risks remain.
    • Consistency and Controls: Deterministic code can apply predefined instructions consistently under expected conditions, but it may still fail because of coding errors, inaccurate data, connectivity problems, or unexpected market conditions.

In my workflow, AI supports research and development, while predefined programmatic code handles order execution.

Lessons Learned from Live Trading: Building Trust in Your System

The hardest part of quantitative trading isn't writing code or pulling API data, it's building trust in your agent. 

Without that trust, every normal market variation will trigger anxiety:

  • When your agent makes zero trades for days, you should verify whether the absence of trades resulted from the strategy’s conditions or a technical problem.
  • When your agent experiences consecutive losing days, you should evaluate whether the losses are consistent with the model’s assumptions and risk limits rather than assuming they are temporary.

What I Would Do Differently Today

If I were starting over, I would place greater emphasis on backtesting, paper trading, failure-scenario testing, monitoring, and documented risk controls before considering live deployment.

Paper trading can help identify coding and workflow issues without risking real money, but simulated results may differ significantly from live trading. 

Read Alpaca’s blog about the differences between paper trading and live trading.

Concluding Thoughts: Reflections on Building the Workflow

Looking back on my experience, Alpaca’s developer-focused APIs and MCP tools helped simplify parts of the setup and integration process, allowing me to spend more time building, testing, and refining my trading workflow.

AI has fundamentally changed the game for quantitative trading, bridging the gap between individual developers and sophisticated market execution. Whether you are a developer looking to apply your coding skills to the financial markets, or a trader wanting to automate your strategies without drowning in boilerplate code, there has never been a better time to start.

Additional Resources

If you want to start building your own systematic trading system, here are the resources I found most useful:

About the Author

Chen Meng is an AI Infrastructure Engineer at Google, where he drives the end-to-end delivery of Gemini models for enterprise customers. His work centers on deploying highly optimized Gemini models to cloud and on-premise environments, navigating diverse hardware profiles, connectivity constraints, and strict security standards. He also architects autonomous agentic solutions built directly on top of these models.

Outside of his day job, Chen is a deeply curious builder who consistently channels his programming expertise into innovative side projects. In addition to developing an automated quantitative trading system, he builds custom AI agents to assist with software engineering and personal workflows, and codes web-based games to challenge AI opponents.


*The Paper Trading API is offered by AlpacaDB, Inc. and does not require real money or permit a user to transact in real securities in the market. Providing use of the Paper Trading API is not an offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, given or in any manner endorsed by AlpacaDB, Inc. or any AlpacaDB, Inc. affiliate and the information made available through the Paper Trading API is not an offer or solicitation of any kind in any jurisdiction where AlpacaDB, Inc. or any AlpacaDB, Inc. affiliate (collectively, “Alpaca”) is not authorized to do business.

Any information or outputs generated through Alpaca’s CLI, MCP Server, or connected AI agents are provided for educational and informational purposes only. They do not constitute investment advice, a recommendation to buy, sell, or hold any security or use any investment strategy, or an offer to buy or sell any security. Any securities, strategies, models, or examples discussed are provided solely for illustrative purposes, may not be suitable for all investors, and are not recommended or endorsed by Alpaca. Users should conduct their own due diligence before making investment decisions.

AI-generated and automated systems may produce inaccurate, incomplete, outdated, or unintended results and may be affected by software, data, connectivity, configuration, or coding errors. Outputs should be independently reviewed and verified before use or reliance. Automated systems may result in unintended, delayed, duplicated, missed, or erroneous orders. Automated controls do not eliminate market, execution, model, or technology risk.

All investments involve risk, including the possible loss of principal. No investment strategy can guarantee a profit or achieve its intended objectives. Past performance does not guarantee future results. Hypothetical, backtested, and paper-trading results have inherent limitations, do not reflect actual trading or all market conditions, and may differ significantly from live-trading results. Factors such as liquidity, market impact, latency, slippage, order queue position, fees, and other costs may not be fully reflected in simulated results.

Securities brokerage services are provided by Alpaca Securities LLC (dba "Alpaca Clearing"), member FINRA/SIPC, a wholly-owned subsidiary of AlpacaDB, Inc. Technology and services are offered by AlpacaDB, Inc.

This is not an offer, solicitation of an offer, or advice to buy or sell securities or open a brokerage account in any jurisdiction where Alpaca Securities is not registered or licensed, as applicable.