I tried to test this algorithm on 10M to comply with the new contest rules and it performed decently.

Clone Algorithm

74

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 |

import math import numpy as np from sklearn.decomposition import FastICA import statsmodels.api as smapi from cvxopt import matrix, solvers from cvxopt.solvers import lp def initialize(context): schedule_function(trade, date_rules.week_start(), time_rules.market_open(minutes=30)) context.done = False context.univ = None solvers.options['show_progress'] = False def handle_data(context, data): pass def trade(context, data): record(l=context.account.leverage) prices = data.history(context.univ, "price", 90, "1d") prices = prices.dropna(axis=1) returns = prices.pct_change().dropna().values returns = np.log1p(returns) sources = FastICA(10, random_state=1).fit_transform(returns) s = smapi.add_constant(sources) betas = np.zeros((np.shape(returns)[1], np.shape(s)[1])) for i in range(0, np.shape(returns)[1]): model = smapi.OLS(returns[:, i], s).fit() betas[i, :] = model.params W = getweights(betas) den = np.sum(np.abs(W)) if den == 0: den = 1 for i, sid in enumerate(prices): order_target_value(sid, W[i] / den * context.portfolio.portfolio_value * 2.8) def getweights(params): (m,n) = np.shape(params) c = -params[:, 0] c = matrix(c) A = matrix(params.T) b = matrix(0.0, (n, 1)) G = np.eye(m) h = np.ones((m, 1)) * 10000 res = lp(c=c, G=matrix(G), h=matrix(h, (m, 1)), A=A, b=b) return res['x'] def before_trading_start(context, data): if context.done: return context.done = True fundamental_df = get_fundamentals( query(fundamentals.share_class_reference.symbol) .filter(fundamentals.valuation.market_cap != None) .filter(fundamentals.company_reference.primary_exchange_id != "OTCPK") # no pink sheets .filter(fundamentals.share_class_reference.security_type == 'ST00000001') # common stock only .filter(~fundamentals.share_class_reference.symbol.contains('_WI')) # drop when-issued .filter(fundamentals.share_class_reference.is_primary_share == True) # remove ancillary classes .filter(fundamentals.share_class_reference.is_depositary_receipt == False) # !ADR/GDR .filter(fundamentals.valuation.market_cap > 5e9) .order_by(fundamentals.valuation.market_cap.desc()).limit(500)).T context.univ = fundamental_df[0:500].index