PortfolioTesteR0.1.4 package

Test Investment Strategies with English-Like Code

align_to_timeframe

Align Data to Strategy Timeframe

analyze_by_period

Period-level summary statistics

analyze_drawdowns

Analyze Drawdown Characteristics

analyze_performance

Analyze Backtest Performance with Daily Monitoring

analyze_vs_benchmark

Benchmark-relative performance statistics

apply_regime

Apply Market Regime Filter

apply_weighting_method

Apply Weighting Method to Values

as_selection

Convert Conditions to Selection Format

backtest_metrics

Calculate Comprehensive Backtest Metrics

bucket_returns

Bucketed label analysis by score rank

calc_cci

Calculate Commodity Channel Index (CCI)

calc_distance

Calculate Distance from Reference

calc_market_breadth

Calculate Market Breadth Percentage

calc_momentum

Calculate Price Momentum

calc_moving_average

Calculate Moving Average

calc_relative_strength_rank

Calculate Cross-Sectional Ranking of Indicators

calc_rolling_correlation

Rolling correlation of each symbol to a benchmark

calc_rolling_volatility

Calculate Rolling Volatility

calc_rsi

Calculate Relative Strength Index (RSI)

calc_sector_breadth

Calculate Market Breadth by Sector

calc_sector_relative_indicators

Calculate Indicators Relative to Sector Average

calc_stochastic_d

Calculate Stochastic D Indicator

calc_stochrsi

Stochastic RSI (StochRSI) for multiple price series

calculate_annualized_return

Calculate Annualized Return

calculate_cluster_variance_optimized

Optimized cluster variance calculation

calculate_daily_values

Daily equity curve from positions and daily prices

calculate_drawdown_series

Calculate Drawdown Time Series

calculate_drawdowns

Calculate Portfolio Drawdowns

calculate_enhanced_metrics

Calculate Enhanced Performance Metrics

calculate_erc_weights

Calculate Equal Risk Contribution weights (simplified)

calculate_hrp_weights

Calculate HRP weights for a given returns matrix

calculate_max_div_weights

Calculate Maximum Diversification Portfolio weights

cap_exposure

Apply post-weight exposure caps

cap_turnover

Cap turnover sequentially across dates

carry_forward_weights

Carry-forward weights between rebalances (validation helper)

combine_filters

Combine Multiple Filter Conditions

combine_scores

Combine multiple score panels (mean / weighted / rank-average / trimme...

combine_weights

Combine Multiple Weighting Schemes

convert_to_nweeks

Convert Data to N-Week Frequency

coverage_by_date

Count finite entries per date

create_regime_buckets

Convert Continuous Indicator to Discrete Regimes

csv_adapter

Load Price Data from CSV File

cv_tune_seq

Purged/embargoed K-fold CV for sequence models (inside IS window)

demo_sector_map

Demo sector (group) map for examples/tests

dot-wf_make_splits

Create Window Splits for Walk-Forward

download_sp500_sectors

Download S&P 500 Sector Mappings from Wikipedia

ensure_dt_copy

Ensure Data.Table Without Mutation

evaluate_scores

Evaluate scores vs labels (IC and hit-rate)

filter_above

Filter Stocks Above Threshold

filter_below

Filter Stocks Below Threshold

filter_between

Filter Stocks Between Two Values

filter_by_percentile

Filter by Percentile

filter_rank

Select Top or Bottom N Stocks by Signal

filter_threshold

Filter by Threshold Value

filter_top_n_where

Select Top N from Qualified Stocks

filter_top_n

Select Top N Stocks by Signal Value

get_data_frequency

Detect Data Frequency from Dates

ic_series

Information Coefficient time series

invert_signal

Invert Signal Values for Preference Reversal

join_panels

Join multiple panels on intersecting dates (unique symbol names)

limit_positions

Limit per-date selections to top-K (legacy API)

list_examples

List available example scripts

load_mixed_symbols

Load Mixed Symbols Including VIX

make_labels

Make future-return labels aligned to the decision date

manual_adapter

Adapter for User-Provided Data

membership_stability

Membership stability across dates

metric_sharpe

Calculate Sharpe Ratio with Frequency Detection

ml_add_interactions

Add interaction panels to a feature list

ml_backtest_multi

Run multi-horizon ML backtests (pooled or sector-neutral)

ml_backtest_seq

One-call backtest wrapper (sequence features)

ml_backtest

One-call backtest wrapper (tabular features)

ml_ic_series_on_scores

Rank-IC series computed on score (rebalance) dates

ml_make_ensemble

NA-tolerant ensemble blender (row-wise)

ml_make_model

Model factory for tabular cross-sectional learners

ml_make_seq_model

Deterministic sequence model factory (GRU/LSTM/CNN1D with linear fallb...

ml_panel_op

Panel-safe binary operation on aligned wide panels

ml_panel_reduce

Reduce multiple panels with a binary operator

ml_plot_ic_roll

Rolling rank-IC plot (rebalance dates; leakage-safe)

ml_prepare_features

Prepare tabular features (weekly + aligned daily volatility)

panel_lag

Lag each symbol column by k steps

panel_returns_simple

Panel simple returns from prices

perf_metrics

Portfolio performance metrics

plot.backtest_result

Plot Backtest Results

plot.param_grid_result

Plot Parameter Grid Results (1D/2D/3D and Facets)

plot.performance_analysis

Plot Performance Analysis Results

plot.wf_optimization_result

Plot Walk-Forward Results

portfolio_returns

Portfolio returns from weights and prices (CASH-aware)

PortfolioTesteR-package

PortfolioTesteR: Test Investment Strategies with English-Like Code

print.backtest_result

Print Backtest Results

print.param_grid_result

Print a param_grid_result

print.performance_analysis

Print Performance Analysis Results

print.wf_optimization_result

Print a wf_optimization_result

pt_collect_results

Collect diagnostics from two ml_backtest_multi() runs

rank_within_sector

Rank Indicators Within Each Sector

rebalance_calendar

Rebalance calendar (rows with non-zero allocation)

recursive_bisection_optimized

Optimized recursive bisection for HRP

roll_fit_predict_seq

Rolling fit/predict for sequence models (flattened steps-by-p features...

roll_fit_predict

Rolling fit/predict for tabular features (pooled / per-symbol / per-gr...

roll_ic_stats

Rolling IC mean, standard deviation, and ICIR

run_backtest

Run Portfolio Backtest

run_example

Run an Example Script

run_param_grid

Run Parameter Grid Optimization (safe + ergonomic)

run_walk_forward

Walk-Forward Optimization Analysis

safe_any

Safe ANY Operation with NA Handling

safe_divide

Safe Division with NA and Zero Handling

scores_oos_only

Mask score tables to out-of-sample decision dates

select_top_k_scores_by_group

Select top-k symbols per group by score

select_top_k_scores

Select top-K scores per date

sql_adapter_adjusted

Load Adjusted Price Data from SQL Database

sql_adapter

Load Price Data from SQL Database

standardize_data_format

Standardize Data to Library Format

summary.backtest_result

Summary method for backtest results

switch_weights

Switch Between Weighting Schemes

transform_scores

Per-date score transform (z-score or rank)

tune_ml_backtest

Quick grid tuning for tabular pipeline

turnover_by_date

Turnover by date

update_vix_in_db

Update VIX data in database

validate_data_format

Validate Data Format for Library Functions

validate_group_map

Validate a symbol-to-group mapping

validate_no_leakage

Quick leakage guard: date alignment & NA expectations

validate_performance_inputs

Validate Performance Analysis Inputs

vol_target

Volatility targeting (row-wise) with optional down-only cap

weight_by_hrp

Hierarchical Risk Parity Weighting

weight_by_rank

Rank-Based Portfolio Weighting

weight_by_regime

Regime-Based Adaptive Weighting

weight_by_risk_parity

Risk Parity Weighting Suite

weight_by_signal

Signal-Based Portfolio Weighting

weight_by_volatility

Volatility-Based Portfolio Weighting

weight_equally

Equal Weight Portfolio Construction

weight_from_scores

Map scores to portfolio weights

wf_report

Generate Walk-Forward Report

wf_stitch

Stitch Out-of-Sample Results (overlap-safe)

wf_sweep_tabular

Walk-forward sweep of tabular configs (window-wise distribution of met...

yahoo_adapter

Download Price Data from Yahoo Finance

Design, backtest, and analyze portfolio strategies using simple, English-like function chains. Includes technical indicators, flexible stock selection, portfolio construction methods (equal weighting, signal weighting, inverse volatility, hierarchical risk parity), and a compact backtesting engine for portfolio returns, drawdowns, and summary metrics.

  • Maintainer: Alberto Pallotta
  • License: MIT + file LICENSE
  • Last published: 2025-11-01