@@ -7,7 +7,7 @@ use ta_lib_in_rust::strategy::daily::multi_indicator_daily_4;
77fn main ( ) -> Result < ( ) , PolarsError > {
88 // Define the tickers to analyze
99 let tickers = vec ! [ "AAPL" , "GOOGL" , "MSFT" ] ;
10-
10+
1111 // Store results for each strategy and ticker
1212 struct StrategyResult {
1313 ticker : String ,
@@ -19,15 +19,15 @@ fn main() -> Result<(), PolarsError> {
1919 max_drawdown : f64 ,
2020 profit_factor : f64 ,
2121 }
22-
22+
2323 let mut all_results: Vec < StrategyResult > = Vec :: new ( ) ;
24-
24+
2525 // Process each ticker
2626 for ticker in & tickers {
2727 println ! ( "\n ==============================================================" ) ;
2828 println ! ( "ANALYZING {}" , ticker) ;
2929 println ! ( "==============================================================" ) ;
30-
30+
3131 // Load ticker's daily OHLCV data
3232 let file_path = format ! ( "examples/{}_daily_ohlcv.csv" , ticker) ;
3333
@@ -57,14 +57,20 @@ fn main() -> Result<(), PolarsError> {
5757 . collect ( ) ?;
5858
5959 println ! ( "--------------------------------------------------------------" ) ;
60- println ! ( "COMPARATIVE ANALYSIS OF MULTI-INDICATOR TRADING STRATEGIES FOR {}" , ticker) ;
60+ println ! (
61+ "COMPARATIVE ANALYSIS OF MULTI-INDICATOR TRADING STRATEGIES FOR {}" ,
62+ ticker
63+ ) ;
6164 println ! ( "--------------------------------------------------------------\n " ) ;
6265
6366 // Save reference to close prices for performance calculations
6467 let close_prices = df. column ( "close" ) ?;
65-
68+
6669 // Run Strategy 1
67- println ! ( "Running Strategy 1: Standard Multi-Indicator for {}..." , ticker) ;
70+ println ! (
71+ "Running Strategy 1: Standard Multi-Indicator for {}..." ,
72+ ticker
73+ ) ;
6874 let strategy1_params = multi_indicator_daily_1:: StrategyParams :: default ( ) ;
6975
7076 println ! ( "Strategy 1 Parameters:" ) ;
@@ -106,7 +112,7 @@ fn main() -> Result<(), PolarsError> {
106112 println ! ( "- Maximum Drawdown: {:.2}%" , max_drawdown1 * 100.0 ) ;
107113 println ! ( "- Profit Factor: {:.2}" , profit_factor1) ;
108114 println ! ( ) ;
109-
115+
110116 // Save strategy 1 results
111117 all_results. push ( StrategyResult {
112118 ticker : ticker. to_string ( ) ,
@@ -120,7 +126,10 @@ fn main() -> Result<(), PolarsError> {
120126 } ) ;
121127
122128 // Run Strategy 2
123- println ! ( "Running Strategy 2: Volatility-Focused Multi-Indicator for {}..." , ticker) ;
129+ println ! (
130+ "Running Strategy 2: Volatility-Focused Multi-Indicator for {}..." ,
131+ ticker
132+ ) ;
124133 let strategy2_params = multi_indicator_daily_2:: StrategyParams :: default ( ) ;
125134
126135 println ! ( "Strategy 2 Parameters:" ) ;
@@ -165,7 +174,7 @@ fn main() -> Result<(), PolarsError> {
165174 println ! ( "- Maximum Drawdown: {:.2}%" , max_drawdown2 * 100.0 ) ;
166175 println ! ( "- Profit Factor: {:.2}" , profit_factor2) ;
167176 println ! ( ) ;
168-
177+
169178 // Save strategy 2 results
170179 all_results. push ( StrategyResult {
171180 ticker : ticker. to_string ( ) ,
@@ -240,7 +249,7 @@ fn main() -> Result<(), PolarsError> {
240249 println ! ( "- Maximum Drawdown: {:.2}%" , max_drawdown3 * 100.0 ) ;
241250 println ! ( "- Profit Factor: {:.2}" , profit_factor3) ;
242251 println ! ( ) ;
243-
252+
244253 // Save strategy 3 results
245254 all_results. push ( StrategyResult {
246255 ticker : ticker. to_string ( ) ,
@@ -254,7 +263,10 @@ fn main() -> Result<(), PolarsError> {
254263 } ) ;
255264
256265 // Run Strategy 4
257- println ! ( "Running Strategy 4: Hybrid Adaptive Strategy for {}..." , ticker) ;
266+ println ! (
267+ "Running Strategy 4: Hybrid Adaptive Strategy for {}..." ,
268+ ticker
269+ ) ;
258270 let strategy4_params = multi_indicator_daily_4:: StrategyParams :: default ( ) ;
259271
260272 println ! ( "Strategy 4 Parameters:" ) ;
@@ -328,7 +340,7 @@ fn main() -> Result<(), PolarsError> {
328340 println ! ( "- Maximum Drawdown: {:.2}%" , max_drawdown4 * 100.0 ) ;
329341 println ! ( "- Profit Factor: {:.2}" , profit_factor4) ;
330342 println ! ( ) ;
331-
343+
332344 // Save strategy 4 results
333345 all_results. push ( StrategyResult {
334346 ticker : ticker. to_string ( ) ,
@@ -464,31 +476,34 @@ fn main() -> Result<(), PolarsError> {
464476 ) ;
465477 }
466478 }
467-
479+
468480 // Cross-ticker comparison for each strategy
469481 println ! ( "\n ==============================================================" ) ;
470482 println ! ( "CROSS-TICKER COMPARISON BY STRATEGY" ) ;
471483 println ! ( "==============================================================" ) ;
472-
484+
473485 // Group results by strategy
474486 let strategy_names = vec ! [
475487 "Standard Multi-Indicator" ,
476488 "Volatility-Focused Multi-Indicator" ,
477489 "Adaptive Trend-Filtered" ,
478- "Hybrid Adaptive Strategy"
490+ "Hybrid Adaptive Strategy" ,
479491 ] ;
480-
492+
481493 for strategy_name in & strategy_names {
482494 println ! ( "\n Strategy: {}" , strategy_name) ;
483495 println ! ( "--------------------------" ) ;
484- println ! ( "{:<6} {:<15} {:<10} {:<10} {:<10} {:<10}" ,
485- "Ticker" , "Return (%)" , "Final Value" , "Trades" , "Win Rate" , "Max DD%" ) ;
486-
496+ println ! (
497+ "{:<6} {:<15} {:<10} {:<10} {:<10} {:<10}" ,
498+ "Ticker" , "Return (%)" , "Final Value" , "Trades" , "Win Rate" , "Max DD%"
499+ ) ;
500+
487501 // Filter results for this strategy
488- let strategy_results: Vec < & StrategyResult > = all_results. iter ( )
502+ let strategy_results: Vec < & StrategyResult > = all_results
503+ . iter ( )
489504 . filter ( |r| r. strategy_name == * strategy_name)
490505 . collect ( ) ;
491-
506+
492507 // Print results for each ticker
493508 for result in & strategy_results {
494509 println ! (
@@ -501,35 +516,44 @@ fn main() -> Result<(), PolarsError> {
501516 result. max_drawdown * 100.0
502517 ) ;
503518 }
504-
519+
505520 // Find best performing ticker for this strategy
506521 if !strategy_results. is_empty ( ) {
507- let best_ticker = strategy_results. iter ( )
522+ let best_ticker = strategy_results
523+ . iter ( )
508524 . max_by ( |a, b| a. total_return . partial_cmp ( & b. total_return ) . unwrap ( ) )
509525 . unwrap ( ) ;
510-
511- println ! ( "\n {} performed best on {} with a {:.2}% return." ,
512- strategy_name, best_ticker. ticker, best_ticker. total_return) ;
526+
527+ println ! (
528+ "\n {} performed best on {} with a {:.2}% return." ,
529+ strategy_name, best_ticker. ticker, best_ticker. total_return
530+ ) ;
513531 }
514532 }
515-
533+
516534 // Overall best combination
517535 println ! ( "\n ==============================================================" ) ;
518536 println ! ( "OVERALL BEST STRATEGY-TICKER COMBINATION" ) ;
519537 println ! ( "==============================================================" ) ;
520-
538+
521539 if !all_results. is_empty ( ) {
522- let best_overall = all_results. iter ( )
540+ let best_overall = all_results
541+ . iter ( )
523542 . max_by ( |a, b| a. total_return . partial_cmp ( & b. total_return ) . unwrap ( ) )
524543 . unwrap ( ) ;
525-
526- println ! ( "The best overall performance was {} on {} with a {:.2}% return." ,
527- best_overall. strategy_name, best_overall. ticker, best_overall. total_return) ;
544+
545+ println ! (
546+ "The best overall performance was {} on {} with a {:.2}% return." ,
547+ best_overall. strategy_name, best_overall. ticker, best_overall. total_return
548+ ) ;
528549 println ! ( "Performance details:" ) ;
529550 println ! ( "- Final Value: ${:.2}" , best_overall. final_value) ;
530551 println ! ( "- Number of Trades: {}" , best_overall. num_trades) ;
531552 println ! ( "- Win Rate: {:.2}%" , best_overall. win_rate) ;
532- println ! ( "- Maximum Drawdown: {:.2}%" , best_overall. max_drawdown * 100.0 ) ;
553+ println ! (
554+ "- Maximum Drawdown: {:.2}%" ,
555+ best_overall. max_drawdown * 100.0
556+ ) ;
533557 println ! ( "- Profit Factor: {:.2}" , best_overall. profit_factor) ;
534558 }
535559
0 commit comments