Financial Trading in R
Build signal-based trading strategies in R with quantstrat: indicators, signals, entry and exit rules, and performance checks with the Sharpe ratio.
Signal-based trading strategies are built step by step in R with the quantstrat package. You transform market data into indicators, turn the ways prices and indicators interact into signals, and write rules that open and close positions and set order sizes. The finished strategy then runs as a simulation and is judged on its trade statistics, its performance over time and its reward relative to risk.
What You Will Achieve
- Pull financial data into R, plot it and overlay a moving average to read the trend
- Configure a new quantstrat strategy with its time zone, currency and instruments
- Write a custom indicator and combine several signals to drive entry and exit decisions
- Judge a simulated strategy using profit factor, percent positive and the Sharpe ratio
Program Overview
Trading Philosophies and Strategy Setup
Why people trade, how momentum and oscillation approaches differ, and the settings quantstrat needs before a strategy can be built.
- Momentum and oscillation trading philosophies
- Trading system pitfalls and overfitting
- Getting and plotting financial data
- Quantstrat initialization settings
Indicator and Signal Construction
Trend and oscillation indicators, from ready-made library functions to one you code yourself, and the four quantstrat signal types built on them.
- SMA and RSI functions
- Coding and applying your own indicator
- sigComparison, sigCrossover, sigThreshold and sigFormula
- Combining signals
Trading Rules and Performance Analysis
Rules that act on signals, followed by running the strategy and reading how it performed.
- Entry and exit rules with add.rule()
- Order quantity, type, side and order sizing functions
- Profit factor and percent positive
- chart.Posn() charts and cash and returns Sharpe ratios
Certificate Awarded (Paid)
Job Outlook
Building and evaluating signal-based strategies in R is used in quantitative trading and finance work that turns market data into rules and measures returns against risk.
Good for: R users who already work with financial data and want to assemble, simulate and evaluate a rule-based trading strategy inside one package.
Keep in mind: The chapter on rules is a primer on how entry, exit and order sizing rules work, and it points to where to keep learning about them.
Bottom line: One quantstrat strategy grows layer by layer, with each chapter adding a piece and the last one measuring its reward against risk.
Frequently Asked Questions
Which signal types does quantstrat provide?
Quantstrat has four: sigComparison, sigCrossover, sigThreshold and sigFormula. Each describes how market data relates to an indicator or how two indicators relate, and the lessons practice every type before combining them.
Can I build my own trading indicator?
Yes. After working with pre-programmed indicators such as SMA and RSI from other libraries, you code an indicator of your own and apply it to market data within the strategy.
How is overfitting handled before strategy building starts?
The opening chapter defines overfitting as one of the pitfalls of trading systems and shows ways to prevent it, so the risk is understood before any quantstrat code is written.
How many ways of computing the Sharpe ratio are taught?
Two. The final chapter computes a cash Sharpe ratio and a returns Sharpe ratio in quantstrat, alongside trade statistics such as profit factor and percent positive.
Please log in to report a problem with this page.


There are no reviews yet.