#!/usr/bin/env python # coding: utf-8 # In[1]: get_ipython().run_line_magic('run', '"Retropy_framework.ipynb"') # In[3]: mdf = pd.read_csv("Research/GemelNet.csv") mdf["month_return"] = mdf["month_return"].astype(str) mdf["month"] = pd.to_datetime(mdf["month"], format="%Y/%m/%d") mdf["month_return"] = pd.to_numeric(mdf["month_return"].str.replace("%", ""), errors="coerce") # In[4]: #mdf = mdf.set_index("month") def getValue(df): df = df.set_index("month") ser = df["month_return"].dropna().copy() if len(ser) == 0: return pd.Series() prevMonth = ser.index[0] + pd.DateOffset(months=-1) ser[prevMonth] = 0 # we want the serie sto start at 1.0 ser = ser.sort_index() ser.index = ser.index + pd.DateOffset(months=1) return (1+ser.dropna()/100).cumprod() #sym = mdf[mdf["ID"] == 1544] #ym["month_return"] #getValue(sym).plot() def getKeren(id): df = mdf[mdf["ID"] == id] name = str(id) + " | " + df.iloc[0]["name"] s = getValue(df) usdils = getForex("USD", "ILS") s = (s/usdils).dropna() if len(s) > 0: s = s / s[0] return wrap(s, name) # ### השוואה של קרן השתלמות מחקה ממדי חול איי-בי-איי למדדי חול # In[5]: s = getKeren(1544) bench = get("URTH") bench = get("SPY:50|VGK:30|EEM:13|EWJ:7") show(s, bench, VT, trim=True) # ### השוואה של קרן השתלמות מחקה סנופי איי-בי-איי לסנופי # In[6]: s = getKeren(2265) bench = get("SPXNTR@IC") x = (s / bench).dropna() show(s, bench, trim=True) # ### כל קרנות ההשתלמות מגמל.נט # In[7]: allKranotIDs = set(mdf.loc[mdf["type"]=="קרן השתלמות", "ID"].values) allKranot = [] for id in allKranotIDs: keren = getKeren(id) allKranot.append(keren) print(keren.name) allKranot = [s for s in allKranot if len(s.s) > 0] # ### השוואה של כל קרנות ההשתלמות במסלול כללי לתיק 60\40 פשוט # In[8]: lst = [s for s in allKranot if s.index[0].year < 2010 and "כללי" in s.name] base = get("VT:60|VFITX:40") lst = [(s).dropna() for s in lst] show(*lst, base, ta=True, legend=False) # ### השוואה של כל קרנות ההשתלמות במסלול כללי לתיק 60\40 פשוט - השוואה יחסית בין הקרנות # In[9]: def getMedianSer(lst): df = pd.DataFrame([s.s for s in lst]).T return wrap(df.median(axis=1), "median") lst = [s / s[0] for s in lst] finals = [(s, s[-1]) for s in lst] finals = sorted(finals, key=lambda x: x[1]) medianSer = finals[len(finals) // 2][0] medianSer = getMedianSer(lst) lst2 = [s / medianSer for s in lst] show(*lst2, base, ta=True, legend=False) # In[ ]: # be sure to save before you publish # when done, you will get a public link to an HTML file with the results publish()