PortfolioTesteR logo

PortfolioTesteR

Test Investment Strategies with English-Like Code

PortfolioTesteR is an R package designed for students and individual investors to test investment strategies using clear, readable code. Unlike complex quantitative libraries, PortfolioTesteR uses intuitive function names that read like plain English, making strategy development accessible to everyone.

Why PortfolioTesteR?

Installation

Install from GitHub:

# install.packages("devtools")
devtools::install_github("alb3rtazzo/PortfolioTesteR")

Quick Start Example

library(PortfolioTesteR)

# Load sample data
data(sample_prices_weekly)

# Calculate 12-week momentum
momentum <- calc_momentum(sample_prices_weekly, lookback = 12)

# Select top 10 momentum stocks
top_momentum <- filter_top_n(momentum, n = 10)

# Weight selected stocks equally
weights <- weight_equally(top_momentum)

# Run backtest
result <- run_backtest(
  prices = sample_prices_weekly,
  weights = weights,
  initial_capital = 100000,
  name = "Simple Momentum"
)

# View results
print(result)
summary(result)
plot(result)

Main Functions

Data Loading

Technical Indicators

Stock Selection

Portfolio Weighting

Backtesting & Analysis

Sample Data Included

The package includes three datasets for immediate testing: - sample_prices_weekly - Weekly prices for 20 stocks (2017-2020) - sample_prices_daily - Daily prices for detailed analysis - sample_sp500_sectors - Sector classifications

Load them with:

data(sample_prices_weekly)
data(sample_prices_daily)
data(sample_sp500_sectors)

Documentation

Every function includes detailed documentation with examples:

?run_backtest
?calc_momentum
?filter_top_n

Disclaimer

This package is for educational and research purposes only. Past performance does not guarantee future results. Always conduct your own research before making investment decisions. The author is not responsible for any financial losses incurred from using this software.

Author

Alberto Pallotta

License

MIT License

Contributing

We welcome contributions! Please feel free to submit issues and pull requests on GitHub.