|
| 1 | +import yfinance as yf |
| 2 | +import numpy as np |
| 3 | +import matplotlib.pyplot as plt |
| 4 | + |
| 5 | +plt.style.use('dark_background') |
| 6 | + |
| 7 | +tickers =['GGAL','GGAL.BA','YPF','YPFD.BA','PAM','PAMP.BA'] |
| 8 | +data = yf.download(tickers, auto_adjust=True, start='2011-01-01')['Close'] |
| 9 | +print('\n\n') |
| 10 | + |
| 11 | +ccl = data['YPFD.BA']/data['YPF'] |
| 12 | +ccl += data['GGAL.BA']/data['GGAL'] * 10 |
| 13 | +ccl += data['PAMP.BA']/data['PAM'] * 25 |
| 14 | +ccl /= 3 |
| 15 | + |
| 16 | +ruedas = 55 |
| 17 | +subas_fw = ccl.pct_change(ruedas)*100 |
| 18 | +fig, ax = plt.subplots(figsize=(15,10), nrows=2) |
| 19 | + |
| 20 | +ax[0].hist(subas_fw, bins=150, width=0.2, color='w', alpha=0.4) |
| 21 | +ax[0].set_title(f'CCL pctChange a {ruedas} Ruedas, Histograma', y=1, fontsize=16) |
| 22 | + |
| 23 | +serie = subas_fw.rolling(20).mean() |
| 24 | +ax[1].plot(serie, color='silver', lw=1, alpha=0.75) |
| 25 | +ax[1].fill_between(serie.index, 0, serie, where = serie < 0 , color='red', alpha=0.2) |
| 26 | +ax[1].fill_between(serie.index, 0, serie, where = serie > 0 , color='green', alpha=0.2) |
| 27 | + |
| 28 | +ax[1].set_title('CCL pctChange a {ruedas} Ruedas, SMA mensual', y=1, fontsize=16) |
| 29 | + |
| 30 | +values = [5,10,15,20,25,30] |
| 31 | +targets = ((1 + np.array(values)/100)*ccl.iloc[-1]).round(2) |
| 32 | + |
| 33 | +for z in range(len(values)): |
| 34 | + ax[0].axvline(values[z], color='w', ls='--', lw=1, alpha=0.35) |
| 35 | + ax[1].plot(ccl.index, [values[z]]*len(ccl), 'w--', alpha=0.35) |
| 36 | + sup_z = len(subas_fw.loc[subas_fw > values[z] ])/len(subas_fw) |
| 37 | + print(f'Prob de suba {ruedas} ruedas > {values[z]}% (${targets[z]}): {round(sup_z*100,1)}%') |
| 38 | + |
| 39 | +plt.subplots_adjust(wspace=None, hspace=0.2) |
| 40 | +plt.show() |
0 commit comments