Here's my Financials tearsheet challenge entry. I will post the tearsheet next.

Clone Algorithm

42

Loading...

There was an error loading this backtest.

Backtest from
to
with
initial capital

Cumulative performance:

Algorithm
Benchmark

Custom data:

Total Returns

--

Alpha

--

Beta

--

Sharpe

--

Sortino

--

Max Drawdown

--

Benchmark Returns

--

Volatility

--

Returns | 1 Month | 3 Month | 6 Month | 12 Month |

Alpha | 1 Month | 3 Month | 6 Month | 12 Month |

Beta | 1 Month | 3 Month | 6 Month | 12 Month |

Sharpe | 1 Month | 3 Month | 6 Month | 12 Month |

Sortino | 1 Month | 3 Month | 6 Month | 12 Month |

Volatility | 1 Month | 3 Month | 6 Month | 12 Month |

Max Drawdown | 1 Month | 3 Month | 6 Month | 12 Month |

from quantopian.algorithm import attach_pipeline, pipeline_output from quantopian.pipeline import Pipeline from quantopian.pipeline.factors import RollingLinearRegressionOfReturns import quantopian.optimize as opt from quantopian.pipeline.filters import QTradableStocksUS import numpy as np from quantopian.pipeline.data.factset import RBICSFocus def normalize(x): r = x - x.mean() return r/r.abs().sum() def regression_pipeline(): QTU = QTradableStocksUS() sector = RBICSFocus.l1_name.latest universe = QTU & sector.eq('Finance') regression = RollingLinearRegressionOfReturns( target=symbol('SPY'), returns_length=2, regression_length=8, mask=universe, ) alpha = regression.alpha beta = regression.beta correlation = regression.r_value pipe = Pipeline(columns = { 'alpha':alpha, 'beta':beta, 'correlation':correlation, }, screen = universe) return pipe def initialize(context): attach_pipeline(regression_pipeline(), 'regression_pipeline') # Schedule my rebalance function schedule_function(func=rebalance, date_rule=date_rules.every_day(), time_rule=time_rules.market_close(), half_days=True) # record my portfolio variables at the end of day schedule_function(func=recording_statements, date_rule=date_rules.every_day(), time_rule=time_rules.market_close(), half_days=True) set_commission(commission.PerShare(cost=0, min_trade_cost=0)) set_slippage(slippage.FixedSlippage(spread=0)) def recording_statements(context, data): record(num_positions=len(context.portfolio.positions)) record(leverage=context.account.leverage) def rebalance(context, data): alpha = normalize(-pipeline_output('regression_pipeline')['alpha']).dropna() objective = opt.TargetWeights(alpha) order_optimal_portfolio(objective=objective, constraints=[] )