• bitcoinBitcoin(BTC)$77,186.00-1.35%
  • ethereumEthereum(ETH)$2,460.48-0.37%
  • tetherTether(USDT)$1.00-0.01%
  • binancecoinBNB(BNB)$713.95-2.40%
  • rippleXRP(XRP)$1.35-3.46%
  • usd-coinUSDC(USDC)$1.000.00%
  • solanaSolana(SOL)$99.95-2.48%
  • tronTRON(TRX)$0.3395660.08%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.030.54%
  • zcashZcash(ZEC)$1,133.56-9.11%
  • HyperliquidHyperliquid(HYPE)$80.35-5.67%
  • dogecoinDogecoin(DOGE)$0.084082-3.32%
  • RainRain(RAIN)$0.015841-0.62%
  • USDSUSDS(USDS)$1.00-0.01%
  • moneroMonero(XMR)$509.17-0.25%
  • whitebitWhiteBIT Coin(WBT)$79.88-1.07%
  • chainlinkChainlink(LINK)$11.56-2.09%
  • leo-tokenLEO Token(LEO)$9.190.07%
  • cardanoCardano(ADA)$0.208411-2.72%
  • stellarStellar(XLM)$0.177119-3.12%
  • daiDai(DAI)$1.00-0.03%
  • bitcoin-cashBitcoin Cash(BCH)$226.09-11.46%
  • Ethena USDeEthena USDe(USDE)$1.00-0.01%
  • USD1USD1(USD1)$1.00-0.01%
  • litecoinLitecoin(LTC)$52.34-2.48%
  • CantonCanton(CC)$0.098968-5.08%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.36-1.21%
  • uniswapUniswap(UNI)$6.04-5.24%
  • hedera-hashgraphHedera(HBAR)$0.075643-1.98%
  • Global DollarGlobal Dollar(USDG)$1.000.00%
  • nearNEAR Protocol(NEAR)$2.521.22%
  • avalanche-2Avalanche(AVAX)$7.59-3.56%
  • suiSui(SUI)$0.74-5.75%
  • shiba-inuShiba Inu(SHIB)$0.000005-3.76%
  • paypal-usdPayPal USD(PYUSD)$1.000.00%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • crypto-com-chainCronos(CRO)$0.056414-4.29%
  • tether-goldTether Gold(XAUT)$4,327.03-1.63%
  • MemeCoreMemeCore(M)$1.16-3.33%
  • Circle USYCCircle USYC(USYC)$1.140.01%
  • Ripple USDRipple USD(RLUSD)$1.00-0.02%
  • okbOKB(OKB)$111.19-1.32%
  • BittensorBittensor(TAO)$239.80-6.29%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.15-0.11%
  • AsterAster(ASTER)$0.70-4.44%
  • polkadotPolkadot(DOT)$1.110.13%
  • aaveAave(AAVE)$122.65-2.55%
  • mantleMantle(MNT)$0.57-5.98%
  • pax-goldPAX Gold(PAXG)$4,327.85-1.71%
  • World Liberty FinancialWorld Liberty Financial(WLFI)$0.0564320.53%
TradePoint.io
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop
No Result
View All Result
TradePoint.io
No Result
View All Result

A Coding Implementation to Portfolio Optimization with skfolio for Building Testing, Tuning, and Comparing Modern Investment Strategies

May 12, 2026
in AI & Technology
Reading Time: 2 mins read
A A
A Coding Implementation to Portfolio Optimization with skfolio for Building Testing, Tuning, and Comparing Modern Investment Strategies
ShareShareShareShareShare

YOU MAY ALSO LIKE

Meta Is Testing Community Notes In Latin America. Fact Checkers Are Worried.

IDScan Is Offering Free Credit Monitoring And ID Protection After Leaking Driver’s Licenses

factor_prices = load_factors_dataset()
X_full, F_full = prices_to_returns(prices, factor_prices)


X_tr, X_te, F_tr, F_te = train_test_split(
   X_full, F_full, test_size=0.33, shuffle=False
)


fm = MeanRisk(
   objective_function=ObjectiveFunction.MAXIMIZE_RATIO,
   risk_measure=RiskMeasure.VARIANCE,
   prior_estimator=FactorModel(),
)
fm.fit(X_tr, F_tr)
ptf_fm = fm.predict(X_te); ptf_fm.name = "Factor Model"
print(f"\nFactor-model Sharpe: {ptf_fm.annualized_sharpe_ratio:.3f}")


pipe = Pipeline([
   ("preselect",   SelectKExtremes(k=8, highest=True)),
   ("optimize",    MeanRisk(
       objective_function=ObjectiveFunction.MAXIMIZE_RATIO,
       risk_measure=RiskMeasure.VARIANCE)),
])
pipe.fit(X_train)
ptf_pipe = pipe.predict(X_test); ptf_pipe.name = "Top-8 + Max Sharpe"


wf_model = MeanRisk(
   objective_function=ObjectiveFunction.MAXIMIZE_RATIO,
   risk_measure=RiskMeasure.VARIANCE,
)
mp_portfolio = cross_val_predict(
   wf_model, X,
   cv=WalkForward(train_size=252*2, test_size=63),
   n_jobs=-1,
)
mp_portfolio.name = "Walk-Forward Max Sharpe"
print(f"\nWalk-forward portfolio  Sharpe={mp_portfolio.annualized_sharpe_ratio:.3f}  "
     f"CalmarRatio={mp_portfolio.calmar_ratio:.3f}")
mp_portfolio.plot_cumulative_returns().show()


tuned = MeanRisk(
   objective_function=ObjectiveFunction.MAXIMIZE_RATIO,
   risk_measure=RiskMeasure.VARIANCE,
   prior_estimator=EmpiricalPrior(mu_estimator=EWMu(alpha=0.1)),
)
grid = GridSearchCV(
   estimator=tuned,
   cv=WalkForward(train_size=252*2, test_size=63),
   n_jobs=-1,
   param_grid={
       "l2_coef": [0.0, 0.01, 0.1],
       "prior_estimator__mu_estimator__alpha": [0.05, 0.1, 0.2, 0.5],
   },
)
grid.fit(X_train)
print("\nBest params:", grid.best_params_)
print(f"Best CV score (Sharpe): {grid.best_score_:.3f}")


ptf_tuned = grid.best_estimator_.predict(X_test); ptf_tuned.name = "Tuned Max Sharpe"


final = Population([
   *baseline_population,
   ptf_min_var, ptf_max_sharpe,
   ptf_rb_var, ptf_rb_cvar,
   ptf_hrp, ptf_nco,
   ptf_robust, ptf_gerber,
   ptf_constr, ptf_bl, ptf_fm,
   ptf_pipe, ptf_tuned,
])


_full = final.summary()
_wanted_final = [
   "Annualized Mean", "Annualized Standard Deviation",
   "Annualized Sharpe Ratio", "Annualized Sortino Ratio",
   "CVaR at 95%", "Maximum Drawdown", "Max Drawdown",
]
_have_final = [r for r in _wanted_final if r in _full.index]
summary = _full.loc[_have_final].T.sort_values(
   "Annualized Sharpe Ratio", ascending=False
)


print("\n" + "=" * 80)
print("FINAL HORSE RACE — sorted by Sharpe (out-of-sample test set)")
print("=" * 80)
print(summary.to_string())


final.plot_cumulative_returns().show()


final.plot_composition().show()


ptf_rb_var.plot_contribution(measure=RiskMeasure.VARIANCE).show()


print("\nDone. Try swapping risk measures, adding constraints, or wiring in")
print("your own returns DataFrame — every estimator follows the sklearn API.")

Credit: Source link

ShareTweetSendSharePin

Related Posts

Meta Is Testing Community Notes In Latin America. Fact Checkers Are Worried.
AI & Technology

Meta Is Testing Community Notes In Latin America. Fact Checkers Are Worried.

September 10, 2026
IDScan Is Offering Free Credit Monitoring And ID Protection After Leaking Driver’s Licenses
AI & Technology

IDScan Is Offering Free Credit Monitoring And ID Protection After Leaking Driver’s Licenses

September 10, 2026
OpenAI Launches ChatGPT for Financial Services With Built-In Data – Unite.AI
AI & Technology

OpenAI Launches ChatGPT for Financial Services With Built-In Data – Unite.AI

September 10, 2026
Cognition Adds Dioxus Team to Advance Devin Coding Agent – Unite.AI
AI & Technology

Cognition Adds Dioxus Team to Advance Devin Coding Agent – Unite.AI

September 10, 2026
Next Post
Stay Tuned NOW Streaming Behind The Scenes! – April 29

Stay Tuned NOW Streaming Behind The Scenes! - April 29

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

No Result
View All Result
Is the Trade War Back? Also, Examining the Tate Brothers Purported Ties to the Trump Admin | July 21

Is the Trade War Back? Also, Examining the Tate Brothers Purported Ties to the Trump Admin | July 21

September 7, 2026
How Apple’s New CEO Will Shape the iPhone Maker

How Apple’s New CEO Will Shape the iPhone Maker

September 3, 2026
Matt Clifford Steps Down as ARIA Chair After Anthropic Move – Unite.AI

Matt Clifford Steps Down as ARIA Chair After Anthropic Move – Unite.AI

September 7, 2026

About

Learn more

Our Services

Legal

Privacy Policy

Terms of Use

Bloggers

Learn more

Article Links

Contact

Advertise

Ask us anything

©2020- TradePoint.io - All rights reserved!

Tradepoint.io, being just a publishing and technology platform, is not a registered broker-dealer or investment adviser. So we do not provide investment advice. Rather, brokerage services are provided to clients of Tradepoint.io by independent SEC-registered broker-dealers and members of FINRA/SIPC. Every form of investing carries some risk and past performance is not a guarantee of future results. “Tradepoint.io“, “Instant Investing” and “My Trading Tools” are registered trademarks of Apperbuild, LLC.

This website is operated by Apperbuild, LLC. We have no link to any brokerage firm and we do not provide investment advice. Every information and resource we provide is solely for the education of our readers. © 2020 Apperbuild, LLC. All rights reserved.

No Result
View All Result
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop

© 2023 - TradePoint.io - All Rights Reserved!