Algo Trading
Algotrading strategies for stock market - backtesting based on backtrader framework
Install / Use
npx skills add qbajas/algo-tradingInstalls into whichever agent you are using.
README
Algotrading strategies for ETFs
About
Implementation of the trading algorithm which invests capital in the most undervalued asset:
- each day a "score" is calculated which represents the undervaluation of an asset
- allocation of the capital is switched to the most undervalued asset
Features of the algorithm:
- using a combination of RSI(2) and RSI(3) as a basis for a score
- adjusting score to currency movements
- use of CCI for trend adjustments
- management of stop losses
- exiting the market when all assets are overvalued
- adjusting score to ex dividend dates
Installation
Runs on Python 3.10 with Backtrader framework
- https://www.backtrader.com/docu/installation/
- https://github.com/mementum/backtrader#installation
Running a simulation
Execute the simulation
Run the following file to execute the backtest:
jj_standard_strategy.py
Sample output
Information about annualized returns, yearly returns, sharpe ration, max drawdown, executed trades etc
Ticker SumOfProfits Trades AvgProfit
XLP 73.64% 463 0.16%
QQQ 101.43% 309 0.33%
TLT 82.31% 470 0.18%
SPY 9.3% 173 0.05%
EEM 53.7% 414 0.13%
GLD 72.96% 624 0.12%
IWM 125.91% 408 0.31%
OrderedDict([(2005,
-0.02086414012834914),
(2006, 0.11257870068465303),
(2007, 0.19096626781834147),
(2008, 0.5922068521683199),
(2009, 0.4277439522230537),
(2010, 0.23170772609894597),
(2011, 0.25052435038907594),
(2012, 0.2851946122866036),
(2013,
-0.07002976846893916),
(2014, 0.1506862873912309),
(2015, 0.2052908419375139),
(2016, 0.05768348150426994),
(2017, 0.18728871309046569),
(2018, 0.05206206192727225),
(2019, 0.3748708481986356),
(2020, 1.1832607423091677),
(2021, 0.10697139538220202),
(2022, 0.2195313331456259),
(2023, 0.3102546191657225),
(2024, 0.5452675054456357),
(2025,
0.01981537601500083)])
========================================
Annualized return: 25.539542 percent
OrderedDict([('sharperatio',
0.9298749765713412)])
OrderedDict([('maxdrawdown',
25.059548287502768),
('maxdrawdownperiod', 319)])
========================================
Monthly avg returns:
[1.55, 2.37, 4.5, 1.84, 0.51, 2.48, 2.53,
1.65, 1.66, 2.78, 2.03, 0.45]
Daily avg returns:
[0.05, 0.22, 0.06, 0.07, 0.09]
Support
Ideas? Suggestions? Feel free to contact me at jaskowiecj@gmail.com
Related Skills
node-connect
385.5kDiagnose OpenClaw Android, iOS, or macOS node pairing, QR/setup code, route, auth, and connection failures.
python-debugpy
385.5kDebug Python with pdb, breakpoint(), post-mortem inspection, and debugpy remote attach.
skill-creator
385.5kCreate, edit, audit, tidy, validate, or restructure AgentSkills and SKILL.md files.
claude-opus-4-5-migration
140.7kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
