If you know anything about financial markets, you should know that past returns are not a good predictor of future returns. This little project was done for research only, do not use it as a guide for your financial decisions.
%load_ext autoreload
from src.data import stocks
Get your free security/stocks API key in this link.
API_KEY = ""
- The baseline symbol is the ticker for the security you mostly want to compare others (the targets) with. It is designed to be some market index, in order to be able to conclude how consistently the target securities have (or not) "beat the market". The ITOT symbol is from an total-market ETF for the US.
minimum_nr_of_months
is the minimum number of months of data a security must have in a year so that the year is accounted for. E.g: if some fund was created in july 1997, andminimum_nr_of_months
is 6, then the year 1997 won't be analyzed.- if
subtract_returns_to_baseline
is set toTrue
then all the target securities yearly growths are subtracted to baseline value of the corresponding year, so that clearer insights on on yearly performance are obtained
%autoreload 2
from src.analysis import returns
continuous_returns, returns_by_year, median_yearly_returns, avg_yearly_returns, beat_the_market_ratio = returns.compare_stocks(
baseline_symbol="ITOT",
targets_symbols=[
"SPY",
"PREFX",
"QQQ",
"VGT",
],
api_key=API_KEY,
minimum_nr_of_months=8,
subtract_returns_to_baseline=True
)
The continuous returns are computed throught only the time of data available
continuous_returns
{'baseline': 3.076656392323726,
'targets': [('QQQ', 7.361796454274539),
('VGT', 6.186002583837699),
('PREFX', 4.309599591407751),
('SPY', 3.020131363260466)]}
returns_by_year
ITOT | QQQ | VGT | PREFX | SPY | |
---|---|---|---|---|---|
2020 | 0.0285272 | 0.245175 | 0.198617 | 0.145352 | -0.00405211 |
2019 | 0.326818 | 0.0928743 | 0.189091 | 0.0418739 | 0.0064179 |
2018 | -0.056447 | 0.0501804 | 0.0763515 | 0.0425129 | 0.00738419 |
2017 | 0.204165 | 0.113243 | 0.157712 | 0.0722189 | 0.00467258 |
2016 | 0.146367 | -0.0515708 | 0.0125219 | -0.100687 | -0.00747229 |
2015 | 0.00265032 | 0.0864347 | 0.0422622 | 0.0605095 | 0.00575137 |
2014 | 0.132249 | 0.0651254 | 0.0526517 | -0.0255987 | 0.00675079 |
2013 | 0.288168 | 0.046215 | -0.00786564 | 0.0329283 | 0.0102813 |
2012 | 0.138362 | 0.0203827 | -0.0199444 | -0.00169805 | 0.00103648 |
2011 | 0.0059413 | 0.018494 | -0.00927043 | -0.0253387 | 0.0052181 |
2010 | 0.154556 | 0.029777 | -0.040592 | 0.0399018 | -0.0135024 |
2009 | 0.264371 | 0.281029 | 0.351654 | 0.105863 | -0.00350482 |
2008 | -0.362375 | -0.0554733 | -0.0720163 | -0.0630634 | -0.00707368 |
2007 | 0.0454063 | 0.136619 | 0.0911635 | 0.0855945 | 0.00129388 |
2006 | 0.148192 | -0.0830631 | -0.0644156 | -0.0746371 | 0.00399728 |
2005 | 0.0499895 | -0.0380743 | -0.0287254 | 0.010048 | -0.00768162 |
2004 | 0.0972514 | -0.0139772 | -0.119201 | 0.00704305 | -0.0120677 |
avg_yearly_returns
[('QQQ', 0.05549356348395734),
('VGT', 0.04764677966302673),
('PREFX', 0.020754305059020928),
('SPY', -0.00015004256161888022)]
median_yearly_returns
[('QQQ', 0.046215010426060465),
('PREFX', 0.03292825606759314),
('VGT', 0.012521879430894084),
('SPY', 0.001293878091998435)]