├── .gitignore ├── .DS_Store ├── README.md ├── Capitulo_09_MT5.py ├── ES_ML_Capítulo_08_SVR.ipynb ├── .ipynb_checkpoints └── ES_ML_Capítulo_08_SVR-checkpoint.ipynb ├── ES_ML_Capítulo_09_MT5_Trading_en_Vivo_Random.ipynb ├── ES_ML_Capítulo_01_Los_fundamentos_de_Python.ipynb └── ES_ML_Capítulo_03_Importar_los_datos.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joanby/trading-algoritmico-ml/HEAD/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Trading Algorítmico utilizando estrategias de Machine Learning 2 | 3 | 🇪🇸 Puedes apuntarte en nuestro curso en: https://cursos.frogamesformacion.com/courses/trading-algoritmico-6 4 | 5 | O obtener la Ruta completa de trading algorítmico en: https://cursos.frogamesformacion.com/bundles/ruta-trading 6 | 7 | ### Recursos 8 | 9 | 💰 Únete a la comunidad de [Discord](https://discord.gg/z3dx5XpkX4) 10 | 11 | 📚 Puedes leer nuestro libro en [Amazon](https://www.amazon.es/Python-para-finanzas-trading-algor%C3%ADtmico-ebook/dp/B0BT4ZS9Q3) 12 | 13 | 🖥️ El canal de [YouTube de Quantreo's](https://www.youtube.com/channel/UCp7jckfiEglNf_Gj62VR0pw) (en inglés) y el de [Frogames](https://www.youtube.com/channel/UCMUxXNYrVCv6-bQakhomvBg) en Español 14 | 15 | 16 | 17 | ### VPS / Instalar Windows en tu Mac 18 | 19 | VPS: https://billing.virmach.com/aff.php?aff=10561 20 | 21 | BOOT CAMP MAC: https://www.youtube.com/watch?v=Hmm9Q-T0oTo 22 | 23 | Parallels Desktop: https://www.parallels.com/ 24 | -------------------------------------------------------------------------------- /Capitulo_09_MT5.py: -------------------------------------------------------------------------------- 1 | import warnings 2 | from datetime import datetime 3 | import pandas as pd 4 | import MetaTrader5 as mt5 5 | warnings.filterwarnings("ignore") 6 | mt5.initialize() 7 | 8 | 9 | class MT5: 10 | 11 | def get_data(symbol, n, timeframe=mt5.TIMEFRAME_D1): 12 | """ Function to import the data of the chosen symbol""" 13 | 14 | # Initialize the connection if there is not 15 | mt5.initialize() 16 | 17 | # Current date extract 18 | utc_from = datetime.now() 19 | 20 | # Import the data into a tuple 21 | rates = mt5.copy_rates_from(symbol, timeframe, utc_from, n) 22 | 23 | # Tuple to dataframe 24 | rates_frame = pd.DataFrame(rates) 25 | 26 | # Convert time in seconds into the datetime format 27 | rates_frame['time'] = pd.to_datetime(rates_frame['time'], unit='s') 28 | 29 | # Convert the column "time" in the right format 30 | rates_frame['time'] = pd.to_datetime(rates_frame['time'], format='%Y-%m-%d') 31 | 32 | # Set column time as the index of the dataframe 33 | rates_frame = rates_frame.set_index('time') 34 | return rates_frame 35 | 36 | def orders(symbol, lot, buy=True, id_position=None): 37 | """ Send the orders """ 38 | 39 | # Initialize the connection if there is not 40 | if mt5.initialize() == False: 41 | mt5.initialize() 42 | 43 | # Get filling mode 44 | filling_mode = mt5.symbol_info(symbol).filling_mode - 1 45 | 46 | # Take ask price 47 | ask_price = mt5.symbol_info_tick(symbol).ask 48 | 49 | # Take bid price 50 | bid_price = mt5.symbol_info_tick(symbol).bid 51 | 52 | # Take the point of the asset 53 | point = mt5.symbol_info(symbol).point 54 | 55 | deviation = 20 # mt5.getSlippage(symbol) 56 | # **************************** Open a trade ***************************** 57 | if id_position == None: 58 | 59 | # Buy order Parameters 60 | if buy: 61 | type_trade = mt5.ORDER_TYPE_BUY 62 | sl = ask_price*(1-0.01) 63 | tp = ask_price*(1+0.01) 64 | price = ask_price 65 | 66 | # Sell order Parameters 67 | else: 68 | type_trade = mt5.ORDER_TYPE_SELL 69 | sl = bid_price*(1+0.01) 70 | tp = bid_price*(1-0.01) 71 | price = bid_price 72 | 73 | # Open the trade 74 | request = { 75 | "action": mt5.TRADE_ACTION_DEAL, 76 | "symbol": symbol, 77 | "volume": lot, 78 | "type": type_trade, 79 | "price": price, 80 | "deviation": deviation, 81 | "sl": sl, 82 | "tp": tp, 83 | "magic": 234000, 84 | "comment": "python script order", 85 | "type_time": mt5.ORDER_TIME_GTC, 86 | "type_filling": filling_mode, 87 | } 88 | # send a trading request 89 | result = mt5.order_send(request) 90 | result_comment = result.comment 91 | 92 | # **************************** Close a trade ***************************** 93 | else: 94 | # Buy order Parameters 95 | if buy: 96 | type_trade = mt5.ORDER_TYPE_SELL 97 | price = bid_price 98 | 99 | # Sell order Parameters 100 | else: 101 | type_trade = mt5.ORDER_TYPE_BUY 102 | price = ask_price 103 | 104 | # Close the trade 105 | request = { 106 | "action": mt5.TRADE_ACTION_DEAL, 107 | "symbol": symbol, 108 | "volume": lot, 109 | "type": type_trade, 110 | "position": id_position, 111 | "price": price, 112 | "deviation": deviation, 113 | "magic": 234000, 114 | "comment": "python script order", 115 | "type_time": mt5.ORDER_TIME_GTC, 116 | "type_filling": filling_mode, 117 | } 118 | 119 | # send a trading request 120 | result = mt5.order_send(request) 121 | result_comment = result.comment 122 | return result.comment 123 | 124 | def resume(): 125 | """ Return the current positions. Position=0 --> Buy """ 126 | # Initialize the connection if there is not 127 | mt5.initialize() 128 | 129 | # Define the name of the columns that we will create 130 | colonnes = ["ticket", "position", "symbol", "volume"] 131 | 132 | # Go take the current open trades 133 | current = mt5.positions_get() 134 | 135 | # Create a empty dataframe 136 | summary = pd.DataFrame() 137 | 138 | # Loop to add each row in dataframe 139 | # (Can be ameliorate using of list of list) 140 | for element in current: 141 | element_pandas = pd.DataFrame([element.ticket, 142 | element.type, 143 | element.symbol, 144 | element.volume], 145 | index=colonnes).transpose() 146 | summary = pd.concat((summary, element_pandas), axis=0) 147 | 148 | return summary 149 | 150 | 151 | def run(symbol, long, short, lot): 152 | 153 | # Initialize the connection if there is not 154 | if mt5.initialize() == False: 155 | mt5.initialize() 156 | 157 | # Choose your symbol 158 | print("------------------------------------------------------------------") 159 | print("Date: ", datetime.now().strftime("%Y-%m-%d %H:%M:%S")) 160 | print("SYMBOL:", symbol) 161 | 162 | # Initialize the device 163 | current_open_positions = MT5.resume() 164 | # Buy or sell 165 | print(f"BUY: {long} \t SHORT: {short}") 166 | 167 | """ Close trade eventually """ 168 | # Extraction type trade 169 | try: 170 | position = current_open_positions.loc[current_open_positions["symbol"]==symbol].values[0][1] 171 | 172 | identifier = current_open_positions.loc[current_open_positions["symbol"]==symbol].values[0][0] 173 | except: 174 | position= None 175 | identifier = None 176 | 177 | print(f"POSITION: {position} \t ID: {identifier}") 178 | 179 | # Close trades 180 | if long==True and position==0: 181 | long=False 182 | 183 | elif long==False and position==0: 184 | res = MT5.orders(symbol, lot, buy=True, id_position=identifier) 185 | print(f"CLOSE LONG TRADE: {res}") 186 | 187 | elif short==True and position ==1: 188 | short=False 189 | 190 | elif short == False and position == 1: 191 | res = MT5.orders(symbol, lot, buy=False, id_position=identifier) 192 | print(f"CLOSE SHORT TRADE: {res}") 193 | 194 | else: 195 | pass 196 | 197 | 198 | """ Buy or short """ 199 | if long==True: 200 | 201 | res = MT5.orders(symbol, lot, buy=True, id_position=None) 202 | print(f"OPEN LONG TRADE: {res}") 203 | 204 | if short==True: 205 | res = MT5.orders(symbol, lot, buy=False, id_position=None) 206 | print(f"OPEN SHORT TRADE: {res}") 207 | 208 | print("------------------------------------------------------------------") 209 | 210 | def close_all_night(): 211 | result = MT5.resume() 212 | for i in range(len(result)): 213 | before = mt5.account_info().balance 214 | row = result.iloc[0+i:1+i,:] 215 | if row["position"][0]==0: 216 | res = MT5.orders(row["symbol"][0], row["volume"][0], buy=True, id_position=row["ticket"][0]) 217 | 218 | else: 219 | res = MT5.orders(row["symbol"][0], row["volume"][0], buy=False, id_position=row["ticket"][0]) -------------------------------------------------------------------------------- /ES_ML_Capítulo_08_SVR.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "021d25d0", 7 | "metadata": { 8 | "id": "021d25d0", 9 | "outputId": "e688c139-0a6c-4a4a-ae90-8479e74c23ea" 10 | }, 11 | "outputs": [ 12 | { 13 | "name": "stdout", 14 | "output_type": "stream", 15 | "text": [ 16 | "------------------------------------------------------------------\n", 17 | "Date: 2021-11-20 11:01:06\n", 18 | "Balance: 10000.0 USD, \tEquity: 10000.0 USD, \tProfit: 0.0 USD\n", 19 | "------------------------------------------------------------------\n", 20 | "------------------------------------------------------------------\n", 21 | "Date: 2021-11-20 11:01:08\n", 22 | "SYMBOL: EURUSD\n", 23 | "BUY: True \t SHORT: False\n", 24 | "POSITION: None \t ID: None\n", 25 | "OPEN LONG TRADE: Market closed\n", 26 | "------------------------------------------------------------------\n", 27 | "------------------------------------------------------------------\n", 28 | "Date: 2021-11-20 11:01:09\n", 29 | "SYMBOL: EURUSD\n", 30 | "BUY: True \t SHORT: False\n", 31 | "POSITION: None \t ID: None\n", 32 | "OPEN LONG TRADE: Market closed\n", 33 | "------------------------------------------------------------------\n", 34 | "------------------------------------------------------------------\n", 35 | "Date: 2021-11-20 11:01:10\n", 36 | "SYMBOL: EURUSD\n", 37 | "BUY: True \t SHORT: False\n", 38 | "POSITION: None \t ID: None\n", 39 | "OPEN LONG TRADE: Market closed\n", 40 | "------------------------------------------------------------------\n" 41 | ] 42 | }, 43 | { 44 | "ename": "KeyboardInterrupt", 45 | "evalue": "", 46 | "output_type": "error", 47 | "traceback": [ 48 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 49 | "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", 50 | "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_4436/3614998999.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 95\u001b[0m \u001b[1;31m# Verfication for launch\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 96\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mdatetime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mweekday\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 97\u001b[1;33m \u001b[0mis_time\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdatetime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstrftime\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"%H:%M:%S\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mstart\u001b[0m \u001b[1;31m#\"23:59:59\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 98\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 99\u001b[0m \u001b[0mis_time\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 51 | "\u001b[1;31mKeyboardInterrupt\u001b[0m: " 52 | ] 53 | } 54 | ], 55 | "source": [ 56 | "from Chapter_09_MT5 import *\n", 57 | "import ta\n", 58 | "import numpy as np\n", 59 | "import warnings\n", 60 | "from datetime import datetime\n", 61 | "import pandas as pd\n", 62 | "import MetaTrader5 as mt5\n", 63 | "warnings.filterwarnings(\"ignore\")\n", 64 | "mt5.initialize()\n", 65 | "\n", 66 | "\n", 67 | "def svm_reg_trading(symbol):\n", 68 | "\n", 69 | " def feature_engineering(df):\n", 70 | " \"\"\" Create new variables\"\"\"\n", 71 | "\n", 72 | " # We copy the dataframe to avoid interferences in the data\n", 73 | " df_copy = df.dropna().copy()\n", 74 | "\n", 75 | " # Create the returns\n", 76 | " df_copy[\"returns\"] = df_copy[\"close\"].pct_change(1)\n", 77 | "\n", 78 | " # Create the SMAs\n", 79 | " df_indicators = ta.add_all_ta_features(\n", 80 | " df, open=\"open\", high=\"high\", low=\"low\", close=\"close\", volume=\"volume\", fillna=True).shift(1)\n", 81 | "\n", 82 | " dfc = pd.concat((df_indicators, df_copy), axis=1)\n", 83 | "\n", 84 | " return dfc.dropna()\n", 85 | "\n", 86 | "\n", 87 | " # Import the data\n", 88 | " df = MT5.get_data(symbol, 3500)[[\"open\", \"high\", \"low\", \"close\", \"tick_volume\"]]\n", 89 | "\n", 90 | " df.columns = [\"open\", \"high\", \"low\", \"close\", \"volume\"]\n", 91 | "\n", 92 | " dfc = feature_engineering(df)\n", 93 | "\n", 94 | " # Percentage train set\n", 95 | " split = int(0.99*len(dfc))\n", 96 | "\n", 97 | " # Train set creation\n", 98 | " X_train = dfc.iloc[:split,6:dfc.shape[1]-1]\n", 99 | " y_train = dfc[[\"returns\"]].iloc[:split]\n", 100 | "\n", 101 | "\n", 102 | " # Test set creation\n", 103 | " X_test = dfc.iloc[split:,6:dfc.shape[1]-1]\n", 104 | " y_test = dfc[[\"returns\"]].iloc[split:]\n", 105 | "\n", 106 | "\n", 107 | " # What you need to remind about this chapter\n", 108 | " from sklearn.preprocessing import StandardScaler\n", 109 | " sc = StandardScaler()\n", 110 | "\n", 111 | " X_train_sc = sc.fit_transform(X_train)\n", 112 | " X_test_sc = sc.transform(X_test)\n", 113 | "\n", 114 | "\n", 115 | " from sklearn.decomposition import PCA\n", 116 | " pca = PCA(n_components=6)\n", 117 | " X_train_pca = pca.fit_transform(X_train_sc)\n", 118 | " X_test_pca = pca.transform(X_test_sc)\n", 119 | "\n", 120 | " # Import the class\n", 121 | " from sklearn.svm import SVR\n", 122 | "\n", 123 | " # Initialize the class\n", 124 | " reg = SVR()\n", 125 | "\n", 126 | " # Fit the model\n", 127 | " reg.fit(X_train_pca, y_train)\n", 128 | "\n", 129 | " # Create predictions for the whole dataset\n", 130 | " X = np.concatenate((X_train_pca, X_test_pca), axis=0)\n", 131 | "\n", 132 | " dfc[\"prediction\"] = reg.predict(X)\n", 133 | "\n", 134 | " buy = dfc[\"prediction\"].iloc[-1]>0\n", 135 | " sell = not buy\n", 136 | " return buy, sell\n", 137 | "\n", 138 | "mt5.initialize()\n", 139 | "# True = Live Trading and False = Screener\n", 140 | "live = True\n", 141 | "\n", 142 | "if live:\n", 143 | " current_account_info = mt5.account_info()\n", 144 | " print(\"------------------------------------------------------------------\")\n", 145 | " print(\"Date: \", datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\"))\n", 146 | " print(f\"Balance: {current_account_info.balance} USD, \\t\"\n", 147 | " f\"Equity: {current_account_info.equity} USD, \\t\"\n", 148 | " f\"Profit: {current_account_info.profit} USD\")\n", 149 | " print(\"------------------------------------------------------------------\")\n", 150 | "\n", 151 | "\n", 152 | "info_order = {\n", 153 | " \"RUSSEL 2000\": [\"EURUSD\", 1.],\n", 154 | " \"Bitcoin\": [\"EURUSD\", 0.1],\n", 155 | " \"Nasdaq 100\": [\"EURUSD\", 0.3]\n", 156 | "}\n", 157 | "\n", 158 | "\n", 159 | "start = datetime.now().strftime(\"%H:%M:%S\")\n", 160 | "while True:\n", 161 | " # Verfication for launch\n", 162 | " if datetime.now().weekday() not in (1,2):\n", 163 | " is_time = datetime.now().strftime(\"%H:%M:%S\") == start #\"23:59:59\"\n", 164 | " else:\n", 165 | " is_time = False\n", 166 | "\n", 167 | " \n", 168 | " # Launch the algorithm\n", 169 | " if is_time:\n", 170 | "\n", 171 | " # Open the trades\n", 172 | " for asset in info_order.keys():\n", 173 | "\n", 174 | " # Initialize the inputs\n", 175 | " symbol = info_order[asset][0]\n", 176 | " lot = info_order[asset][1]\n", 177 | "\n", 178 | " # Create the signals\n", 179 | " buy, sell = svm_reg_trading(symbol)\n", 180 | "\n", 181 | " # Run the algorithm\n", 182 | " if live:\n", 183 | " MT5.run(symbol, buy, sell,lot)\n", 184 | "\n", 185 | " else:\n", 186 | " print(f\"Symbol: {symbol}\\t\"\n", 187 | " f\"Buy: {buy}\\t\"\n", 188 | " f\"Sell: {sell}\")\n", 189 | " time.sleep(1)" 190 | ] 191 | } 192 | ], 193 | "metadata": { 194 | "colab": { 195 | "name": "MT5_Live_Trading.ipynb", 196 | "provenance": [] 197 | }, 198 | "kernelspec": { 199 | "display_name": "Python 3", 200 | "language": "python", 201 | "name": "python3" 202 | }, 203 | "language_info": { 204 | "codemirror_mode": { 205 | "name": "ipython", 206 | "version": 3 207 | }, 208 | "file_extension": ".py", 209 | "mimetype": "text/x-python", 210 | "name": "python", 211 | "nbconvert_exporter": "python", 212 | "pygments_lexer": "ipython3", 213 | "version": "3.8.8" 214 | } 215 | }, 216 | "nbformat": 4, 217 | "nbformat_minor": 5 218 | } 219 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/ES_ML_Capítulo_08_SVR-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "021d25d0", 7 | "metadata": { 8 | "id": "021d25d0", 9 | "outputId": "e688c139-0a6c-4a4a-ae90-8479e74c23ea" 10 | }, 11 | "outputs": [ 12 | { 13 | "name": "stdout", 14 | "output_type": "stream", 15 | "text": [ 16 | "------------------------------------------------------------------\n", 17 | "Date: 2021-11-20 11:01:06\n", 18 | "Balance: 10000.0 USD, \tEquity: 10000.0 USD, \tProfit: 0.0 USD\n", 19 | "------------------------------------------------------------------\n", 20 | "------------------------------------------------------------------\n", 21 | "Date: 2021-11-20 11:01:08\n", 22 | "SYMBOL: EURUSD\n", 23 | "BUY: True \t SHORT: False\n", 24 | "POSITION: None \t ID: None\n", 25 | "OPEN LONG TRADE: Market closed\n", 26 | "------------------------------------------------------------------\n", 27 | "------------------------------------------------------------------\n", 28 | "Date: 2021-11-20 11:01:09\n", 29 | "SYMBOL: EURUSD\n", 30 | "BUY: True \t SHORT: False\n", 31 | "POSITION: None \t ID: None\n", 32 | "OPEN LONG TRADE: Market closed\n", 33 | "------------------------------------------------------------------\n", 34 | "------------------------------------------------------------------\n", 35 | "Date: 2021-11-20 11:01:10\n", 36 | "SYMBOL: EURUSD\n", 37 | "BUY: True \t SHORT: False\n", 38 | "POSITION: None \t ID: None\n", 39 | "OPEN LONG TRADE: Market closed\n", 40 | "------------------------------------------------------------------\n" 41 | ] 42 | }, 43 | { 44 | "ename": "KeyboardInterrupt", 45 | "evalue": "", 46 | "output_type": "error", 47 | "traceback": [ 48 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 49 | "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", 50 | "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_4436/3614998999.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 95\u001b[0m \u001b[1;31m# Verfication for launch\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 96\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mdatetime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mweekday\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 97\u001b[1;33m \u001b[0mis_time\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdatetime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstrftime\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"%H:%M:%S\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mstart\u001b[0m \u001b[1;31m#\"23:59:59\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 98\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 99\u001b[0m \u001b[0mis_time\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 51 | "\u001b[1;31mKeyboardInterrupt\u001b[0m: " 52 | ] 53 | } 54 | ], 55 | "source": [ 56 | "from Chapter_09_MT5 import *\n", 57 | "import ta\n", 58 | "import numpy as np\n", 59 | "import warnings\n", 60 | "from datetime import datetime\n", 61 | "import pandas as pd\n", 62 | "import MetaTrader5 as mt5\n", 63 | "warnings.filterwarnings(\"ignore\")\n", 64 | "mt5.initialize()\n", 65 | "\n", 66 | "\n", 67 | "def svm_reg_trading(symbol):\n", 68 | "\n", 69 | " def feature_engineering(df):\n", 70 | " \"\"\" Create new variables\"\"\"\n", 71 | "\n", 72 | " # We copy the dataframe to avoid interferences in the data\n", 73 | " df_copy = df.dropna().copy()\n", 74 | "\n", 75 | " # Create the returns\n", 76 | " df_copy[\"returns\"] = df_copy[\"close\"].pct_change(1)\n", 77 | "\n", 78 | " # Create the SMAs\n", 79 | " df_indicators = ta.add_all_ta_features(\n", 80 | " df, open=\"open\", high=\"high\", low=\"low\", close=\"close\", volume=\"volume\", fillna=True).shift(1)\n", 81 | "\n", 82 | " dfc = pd.concat((df_indicators, df_copy), axis=1)\n", 83 | "\n", 84 | " return dfc.dropna()\n", 85 | "\n", 86 | "\n", 87 | " # Import the data\n", 88 | " df = MT5.get_data(symbol, 3500)[[\"open\", \"high\", \"low\", \"close\", \"tick_volume\"]]\n", 89 | "\n", 90 | " df.columns = [\"open\", \"high\", \"low\", \"close\", \"volume\"]\n", 91 | "\n", 92 | " dfc = feature_engineering(df)\n", 93 | "\n", 94 | " # Percentage train set\n", 95 | " split = int(0.99*len(dfc))\n", 96 | "\n", 97 | " # Train set creation\n", 98 | " X_train = dfc.iloc[:split,6:dfc.shape[1]-1]\n", 99 | " y_train = dfc[[\"returns\"]].iloc[:split]\n", 100 | "\n", 101 | "\n", 102 | " # Test set creation\n", 103 | " X_test = dfc.iloc[split:,6:dfc.shape[1]-1]\n", 104 | " y_test = dfc[[\"returns\"]].iloc[split:]\n", 105 | "\n", 106 | "\n", 107 | " # What you need to remind about this chapter\n", 108 | " from sklearn.preprocessing import StandardScaler\n", 109 | " sc = StandardScaler()\n", 110 | "\n", 111 | " X_train_sc = sc.fit_transform(X_train)\n", 112 | " X_test_sc = sc.transform(X_test)\n", 113 | "\n", 114 | "\n", 115 | " from sklearn.decomposition import PCA\n", 116 | " pca = PCA(n_components=6)\n", 117 | " X_train_pca = pca.fit_transform(X_train_sc)\n", 118 | " X_test_pca = pca.transform(X_test_sc)\n", 119 | "\n", 120 | " # Import the class\n", 121 | " from sklearn.svm import SVR\n", 122 | "\n", 123 | " # Initialize the class\n", 124 | " reg = SVR()\n", 125 | "\n", 126 | " # Fit the model\n", 127 | " reg.fit(X_train_pca, y_train)\n", 128 | "\n", 129 | " # Create predictions for the whole dataset\n", 130 | " X = np.concatenate((X_train_pca, X_test_pca), axis=0)\n", 131 | "\n", 132 | " dfc[\"prediction\"] = reg.predict(X)\n", 133 | "\n", 134 | " buy = dfc[\"prediction\"].iloc[-1]>0\n", 135 | " sell = not buy\n", 136 | " return buy, sell\n", 137 | "\n", 138 | "mt5.initialize()\n", 139 | "# True = Live Trading and False = Screener\n", 140 | "live = True\n", 141 | "\n", 142 | "if live:\n", 143 | " current_account_info = mt5.account_info()\n", 144 | " print(\"------------------------------------------------------------------\")\n", 145 | " print(\"Date: \", datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\"))\n", 146 | " print(f\"Balance: {current_account_info.balance} USD, \\t\"\n", 147 | " f\"Equity: {current_account_info.equity} USD, \\t\"\n", 148 | " f\"Profit: {current_account_info.profit} USD\")\n", 149 | " print(\"------------------------------------------------------------------\")\n", 150 | "\n", 151 | "\n", 152 | "info_order = {\n", 153 | " \"RUSSEL 2000\": [\"EURUSD\", 1.],\n", 154 | " \"Bitcoin\": [\"EURUSD\", 0.1],\n", 155 | " \"Nasdaq 100\": [\"EURUSD\", 0.3]\n", 156 | "}\n", 157 | "\n", 158 | "\n", 159 | "start = datetime.now().strftime(\"%H:%M:%S\")\n", 160 | "while True:\n", 161 | " # Verfication for launch\n", 162 | " if datetime.now().weekday() not in (1,2):\n", 163 | " is_time = datetime.now().strftime(\"%H:%M:%S\") == start #\"23:59:59\"\n", 164 | " else:\n", 165 | " is_time = False\n", 166 | "\n", 167 | " \n", 168 | " # Launch the algorithm\n", 169 | " if is_time:\n", 170 | "\n", 171 | " # Open the trades\n", 172 | " for asset in info_order.keys():\n", 173 | "\n", 174 | " # Initialize the inputs\n", 175 | " symbol = info_order[asset][0]\n", 176 | " lot = info_order[asset][1]\n", 177 | "\n", 178 | " # Create the signals\n", 179 | " buy, sell = svm_reg_trading(symbol)\n", 180 | "\n", 181 | " # Run the algorithm\n", 182 | " if live:\n", 183 | " MT5.run(symbol, buy, sell,lot)\n", 184 | "\n", 185 | " else:\n", 186 | " print(f\"Symbol: {symbol}\\t\"\n", 187 | " f\"Buy: {buy}\\t\"\n", 188 | " f\"Sell: {sell}\")\n", 189 | " time.sleep(1)" 190 | ] 191 | } 192 | ], 193 | "metadata": { 194 | "colab": { 195 | "name": "MT5_Live_Trading.ipynb", 196 | "provenance": [] 197 | }, 198 | "kernelspec": { 199 | "display_name": "Python 3", 200 | "language": "python", 201 | "name": "python3" 202 | }, 203 | "language_info": { 204 | "codemirror_mode": { 205 | "name": "ipython", 206 | "version": 3 207 | }, 208 | "file_extension": ".py", 209 | "mimetype": "text/x-python", 210 | "name": "python", 211 | "nbconvert_exporter": "python", 212 | "pygments_lexer": "ipython3", 213 | "version": "3.8.8" 214 | } 215 | }, 216 | "nbformat": 4, 217 | "nbformat_minor": 5 218 | } 219 | -------------------------------------------------------------------------------- /ES_ML_Capítulo_09_MT5_Trading_en_Vivo_Random.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 3, 6 | "id": "dacf6cd9", 7 | "metadata": {}, 8 | "outputs": [ 9 | { 10 | "name": "stdout", 11 | "output_type": "stream", 12 | "text": [ 13 | "Collecting numpy==1.19.2\n", 14 | " Downloading numpy-1.19.2-cp38-cp38-macosx_10_9_x86_64.whl (15.3 MB)\n", 15 | "\u001b[K |████████████████████████████████| 15.3 MB 23.6 MB/s eta 0:00:01\n", 16 | "\u001b[?25hInstalling collected packages: numpy\n", 17 | "\u001b[33m WARNING: The scripts f2py, f2py3 and f2py3.8 are installed in '/Users/juangabriel/.local/bin' which is not on PATH.\n", 18 | " Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\u001b[0m\n", 19 | "Successfully installed numpy-1.19.2\n", 20 | "Requirement already satisfied: scipy==1.6.2 in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (1.6.2)\n", 21 | "Requirement already satisfied: numpy<1.23.0,>=1.16.5 in /Users/juangabriel/.local/lib/python3.8/site-packages (from scipy==1.6.2) (1.19.2)\n", 22 | "Collecting ta\n", 23 | " Downloading ta-0.10.1.tar.gz (24 kB)\n", 24 | "Requirement already satisfied: numpy in /Users/juangabriel/.local/lib/python3.8/site-packages (from ta) (1.19.2)\n", 25 | "Requirement already satisfied: pandas in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from ta) (1.2.4)\n", 26 | "Requirement already satisfied: python-dateutil>=2.7.3 in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from pandas->ta) (2.8.1)\n", 27 | "Requirement already satisfied: pytz>=2017.3 in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from pandas->ta) (2021.1)\n", 28 | "Requirement already satisfied: six>=1.5 in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from python-dateutil>=2.7.3->pandas->ta) (1.15.0)\n", 29 | "Building wheels for collected packages: ta\n", 30 | " Building wheel for ta (setup.py) ... \u001b[?25ldone\n", 31 | "\u001b[?25h Created wheel for ta: filename=ta-0.10.1-py3-none-any.whl size=28986 sha256=19fa3fed51f7d63585b496cb389f80668b180259336e597d8daea515771e391c\n", 32 | " Stored in directory: /Users/juangabriel/Library/Caches/pip/wheels/18/9a/81/694fa8602da445fa009fd13c8da25001be19efdfb67a9cc348\n", 33 | "Successfully built ta\n", 34 | "Installing collected packages: ta\n", 35 | "Successfully installed ta-0.10.1\n", 36 | "Collecting datetime\n", 37 | " Downloading DateTime-4.4-py2.py3-none-any.whl (51 kB)\n", 38 | "\u001b[K |████████████████████████████████| 51 kB 1.1 MB/s eta 0:00:01\n", 39 | "\u001b[?25hRequirement already satisfied: pytz in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from datetime) (2021.1)\n", 40 | "Requirement already satisfied: zope.interface in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from datetime) (5.3.0)\n", 41 | "Requirement already satisfied: setuptools in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from zope.interface->datetime) (52.0.0.post20210125)\n", 42 | "Installing collected packages: datetime\n", 43 | "Successfully installed datetime-4.4\n", 44 | "Collecting yfinance\n", 45 | " Downloading yfinance-0.1.72-py2.py3-none-any.whl (27 kB)\n", 46 | "Collecting requests>=2.26\n", 47 | " Downloading requests-2.28.0-py3-none-any.whl (62 kB)\n", 48 | "\u001b[K |████████████████████████████████| 62 kB 2.0 MB/s eta 0:00:011\n", 49 | "\u001b[?25hRequirement already satisfied: lxml>=4.5.1 in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from yfinance) (4.6.3)\n", 50 | "Requirement already satisfied: numpy>=1.15 in /Users/juangabriel/.local/lib/python3.8/site-packages (from yfinance) (1.19.2)\n", 51 | "Requirement already satisfied: pandas>=0.24.0 in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from yfinance) (1.2.4)\n", 52 | "Collecting multitasking>=0.0.7\n", 53 | " Downloading multitasking-0.0.10.tar.gz (8.2 kB)\n", 54 | "Requirement already satisfied: python-dateutil>=2.7.3 in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from pandas>=0.24.0->yfinance) (2.8.1)\n", 55 | "Requirement already satisfied: pytz>=2017.3 in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from pandas>=0.24.0->yfinance) (2021.1)\n", 56 | "Requirement already satisfied: six>=1.5 in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from python-dateutil>=2.7.3->pandas>=0.24.0->yfinance) (1.15.0)\n", 57 | "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from requests>=2.26->yfinance) (1.22)\n", 58 | "Requirement already satisfied: idna<4,>=2.5 in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from requests>=2.26->yfinance) (2.6)\n", 59 | "Requirement already satisfied: certifi>=2017.4.17 in /Users/juangabriel/opt/anaconda3/lib/python3.8/site-packages (from requests>=2.26->yfinance) (2020.12.5)\n", 60 | "Collecting charset-normalizer~=2.0.0\n", 61 | " Downloading charset_normalizer-2.0.12-py3-none-any.whl (39 kB)\n", 62 | "Building wheels for collected packages: multitasking\n", 63 | " Building wheel for multitasking (setup.py) ... \u001b[?25ldone\n", 64 | "\u001b[?25h Created wheel for multitasking: filename=multitasking-0.0.10-py3-none-any.whl size=8488 sha256=464b015e696019c4bbeb2915e0281594b248900ca08545b6be77a7fe15d58b1d\n", 65 | " Stored in directory: /Users/juangabriel/Library/Caches/pip/wheels/21/c9/66/b41c847de65c7985db52ec21d59996841598b8b0e93f2b9500\n", 66 | "Successfully built multitasking\n", 67 | "Installing collected packages: charset-normalizer, requests, multitasking, yfinance\n", 68 | "\u001b[33m WARNING: The script normalizer is installed in '/Users/juangabriel/.local/bin' which is not on PATH.\n", 69 | " Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\u001b[0m\n", 70 | "\u001b[33m WARNING: The script sample is installed in '/Users/juangabriel/.local/bin' which is not on PATH.\n", 71 | " Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\u001b[0m\n", 72 | "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", 73 | "conda-repo-cli 1.0.4 requires pathlib, which is not installed.\n", 74 | "anaconda-project 0.9.1 requires ruamel-yaml, which is not installed.\n", 75 | "sphinx 4.0.1 requires Jinja2<3.0,>=2.3, but you have jinja2 3.0.1 which is incompatible.\n", 76 | "sphinx 4.0.1 requires MarkupSafe<2.0, but you have markupsafe 2.0.1 which is incompatible.\u001b[0m\n", 77 | "Successfully installed charset-normalizer-2.0.12 multitasking-0.0.10 requests-2.28.0 yfinance-0.1.72\n", 78 | "\u001b[31mERROR: Could not find a version that satisfies the requirement MetaTrader5--user\u001b[0m\n", 79 | "\u001b[31mERROR: No matching distribution found for MetaTrader5--user\u001b[0m\n" 80 | ] 81 | } 82 | ], 83 | "source": [ 84 | "import sys\n", 85 | "\n", 86 | "!{sys.executable} -m pip install numpy==1.19.2 --user\n", 87 | "!{sys.executable} -m pip install scipy==1.6.2 --user\n", 88 | "!{sys.executable} -m pip install ta --user\n", 89 | "!{sys.executable} -m pip install datetime --user\n", 90 | "!{sys.executable} -m pip install yfinance --user\n", 91 | "!{sys.executable} -m pip install MetaTrader5 --user" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 12, 97 | "id": "021d25d0", 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "name": "stdout", 102 | "output_type": "stream", 103 | "text": [ 104 | "------------------------------------------------------------------\n", 105 | "Date: 2022-01-14 08:33:32\n", 106 | "Balance: 10000.0 USD, \tEquity: 9991.28 USD, \tProfit: -8.72 USD\n", 107 | "------------------------------------------------------------------\n", 108 | "------------------------------------------------------------------\n", 109 | "Date: 2022-01-14 08:33:32\n", 110 | "SYMBOL: BTCUSD\n", 111 | "BUY: False \t SHORT: False\n", 112 | "POSITION: None \t ID: None\n", 113 | "------------------------------------------------------------------\n", 114 | "------------------------------------------------------------------\n", 115 | "Date: 2022-01-14 08:33:32\n", 116 | "SYMBOL: XMRUSD\n", 117 | "BUY: False \t SHORT: False\n", 118 | "POSITION: None \t ID: None\n", 119 | "------------------------------------------------------------------\n", 120 | "------------------------------------------------------------------\n", 121 | "Date: 2022-01-14 08:33:32\n", 122 | "SYMBOL: ETHUSD\n", 123 | "BUY: False \t SHORT: False\n", 124 | "POSITION: None \t ID: None\n", 125 | "------------------------------------------------------------------\n", 126 | "------------------------------------------------------------------\n", 127 | "Date: 2022-01-14 08:33:32\n", 128 | "SYMBOL: ETCUSD\n", 129 | "BUY: False \t SHORT: False\n", 130 | "POSITION: None \t ID: None\n", 131 | "------------------------------------------------------------------\n", 132 | "------------------------------------------------------------------\n", 133 | "Date: 2022-01-14 08:33:32\n", 134 | "SYMBOL: ZECUSD\n", 135 | "BUY: False \t SHORT: False\n", 136 | "POSITION: None \t ID: None\n", 137 | "------------------------------------------------------------------\n", 138 | "------------------------------------------------------------------\n", 139 | "Date: 2022-01-14 08:33:32\n", 140 | "SYMBOL: BTCUSD\n", 141 | "BUY: False \t SHORT: False\n", 142 | "POSITION: None \t ID: None\n", 143 | "------------------------------------------------------------------\n", 144 | "------------------------------------------------------------------\n", 145 | "Date: 2022-01-14 08:33:32\n", 146 | "SYMBOL: XMRUSD\n", 147 | "BUY: False \t SHORT: False\n", 148 | "POSITION: None \t ID: None\n", 149 | "------------------------------------------------------------------\n", 150 | "------------------------------------------------------------------\n", 151 | "Date: 2022-01-14 08:33:32\n", 152 | "SYMBOL: ETHUSD\n", 153 | "BUY: False \t SHORT: False\n", 154 | "POSITION: None \t ID: None\n", 155 | "------------------------------------------------------------------\n", 156 | "------------------------------------------------------------------\n", 157 | "Date: 2022-01-14 08:33:32\n", 158 | "SYMBOL: ETCUSD\n", 159 | "BUY: False \t SHORT: False\n", 160 | "POSITION: None \t ID: None\n", 161 | "------------------------------------------------------------------\n", 162 | "------------------------------------------------------------------\n", 163 | "Date: 2022-01-14 08:33:32\n", 164 | "SYMBOL: ZECUSD\n", 165 | "BUY: False \t SHORT: False\n", 166 | "POSITION: None \t ID: None\n", 167 | "------------------------------------------------------------------\n", 168 | "------------------------------------------------------------------\n", 169 | "Date: 2022-01-14 08:33:32\n", 170 | "SYMBOL: BTCUSD\n", 171 | "BUY: False \t SHORT: False\n", 172 | "POSITION: None \t ID: None\n", 173 | "------------------------------------------------------------------\n", 174 | "------------------------------------------------------------------\n", 175 | "Date: 2022-01-14 08:33:32\n", 176 | "SYMBOL: XMRUSD\n", 177 | "BUY: False \t SHORT: False\n", 178 | "POSITION: None \t ID: None\n", 179 | "------------------------------------------------------------------\n", 180 | "------------------------------------------------------------------\n", 181 | "Date: 2022-01-14 08:33:32\n", 182 | "SYMBOL: ETHUSD\n", 183 | "BUY: False \t SHORT: False\n", 184 | "POSITION: None \t ID: None\n", 185 | "------------------------------------------------------------------\n", 186 | "------------------------------------------------------------------\n", 187 | "Date: 2022-01-14 08:33:32\n", 188 | "SYMBOL: ETCUSD\n", 189 | "BUY: False \t SHORT: False\n", 190 | "POSITION: None \t ID: None\n", 191 | "------------------------------------------------------------------\n", 192 | "------------------------------------------------------------------\n", 193 | "Date: 2022-01-14 08:33:32\n", 194 | "SYMBOL: ZECUSD\n", 195 | "BUY: False \t SHORT: False\n", 196 | "POSITION: None \t ID: None\n", 197 | "------------------------------------------------------------------\n", 198 | "------------------------------------------------------------------\n", 199 | "Date: 2022-01-14 08:33:32\n", 200 | "SYMBOL: BTCUSD\n", 201 | "BUY: False \t SHORT: False\n", 202 | "POSITION: None \t ID: None\n", 203 | "------------------------------------------------------------------\n", 204 | "------------------------------------------------------------------\n", 205 | "Date: 2022-01-14 08:33:32\n", 206 | "SYMBOL: XMRUSD\n", 207 | "BUY: False \t SHORT: False\n", 208 | "POSITION: None \t ID: None\n", 209 | "------------------------------------------------------------------\n", 210 | "------------------------------------------------------------------\n", 211 | "Date: 2022-01-14 08:33:32\n", 212 | "SYMBOL: ETHUSD\n", 213 | "BUY: False \t SHORT: False\n", 214 | "POSITION: None \t ID: None\n", 215 | "------------------------------------------------------------------\n", 216 | "------------------------------------------------------------------\n", 217 | "Date: 2022-01-14 08:33:33\n", 218 | "SYMBOL: ETCUSD\n", 219 | "BUY: False \t SHORT: False\n", 220 | "POSITION: None \t ID: None\n", 221 | "------------------------------------------------------------------\n", 222 | "------------------------------------------------------------------\n", 223 | "Date: 2022-01-14 08:33:33\n", 224 | "SYMBOL: ZECUSD\n", 225 | "BUY: False \t SHORT: False\n", 226 | "POSITION: None \t ID: None\n", 227 | "------------------------------------------------------------------\n" 228 | ] 229 | }, 230 | { 231 | "ename": "KeyboardInterrupt", 232 | "evalue": "", 233 | "output_type": "error", 234 | "traceback": [ 235 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 236 | "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", 237 | "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_5916/4152256203.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 72\u001b[0m \u001b[1;31m# Verfication for launch\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 73\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mdatetime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mweekday\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m6\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m# If you want to trade only from Monday to Friday\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 74\u001b[1;33m \u001b[0mis_time\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdatetime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstrftime\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"%H:%M:%S\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mstart\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 75\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 76\u001b[0m \u001b[0mis_time\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 238 | "\u001b[1;31mKeyboardInterrupt\u001b[0m: " 239 | ] 240 | } 241 | ], 242 | "source": [ 243 | "from Chapter_09_MT5 import *\n", 244 | "import warnings\n", 245 | "warnings.filterwarnings(\"ignore\")\n", 246 | "import time\n", 247 | "import numpy as np\n", 248 | "\n", 249 | "import MetaTrader5 as mt5\n", 250 | "mt5.initialize()\n", 251 | "\n", 252 | "\n", 253 | "def random():\n", 254 | " \n", 255 | " values = [True, False]\n", 256 | " \n", 257 | " buy = np.random.choice(values)\n", 258 | " sell = not buy\n", 259 | " \n", 260 | "\n", 261 | " return buy, sell\n", 262 | "\n", 263 | "\n", 264 | "symbols_list = {\n", 265 | " \"Nasdaq 100\": [\"NAS100\", 0.1],\n", 266 | " \"Russel 2000\": [\"US2000\", 0.1],\n", 267 | " \"Gold USD\": [\"XAUUSD\", 0.01],\n", 268 | " \"S&P 500\": [\"US500\", 0.1],\n", 269 | " \"US dollar vs Canadian dollar\": [\"USDCAD\", 0.01],\n", 270 | " \"Euro vs US dollar\": [\"EURUSD\", 0.01]\n", 271 | "}\n", 272 | "\n", 273 | "current_account_info = mt5.account_info()\n", 274 | "print(\"------------------------------------------------------------------\")\n", 275 | "print(\"Date: \", datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\"))\n", 276 | "print(f\"Balance: {current_account_info.balance} USD, \\t\"\n", 277 | " f\"Equity: {current_account_info.equity} USD, \\t\"\n", 278 | " f\"Profit: {current_account_info.profit} USD\")\n", 279 | "print(\"------------------------------------------------------------------\")\n", 280 | "\n", 281 | "\n", 282 | "start = datetime.now().strftime(\"%H:%M:%S\") #\"23:59:59\"\n", 283 | "\n", 284 | "while True:\n", 285 | "\n", 286 | " # Verificación para lanzar el algoritmo\n", 287 | " if datetime.now().weekday() not in (5,6): # Para hacer trading solamente de Lunes a Viernes\n", 288 | " is_time = datetime.now().strftime(\"%H:%M:%S\") == start \n", 289 | " else:\n", 290 | " is_time = False\n", 291 | "\n", 292 | " \n", 293 | " # Lanzamos el algoritmo\n", 294 | " if is_time:\n", 295 | "\n", 296 | " # Podemos cerrar todas las posiciones abiertas\n", 297 | " if mt5.positions_total() > 0:\n", 298 | " MT5.close_all_night()\n", 299 | " \n", 300 | " # Abrimos el trading\n", 301 | " for asset in symbols_list.keys():\n", 302 | "\n", 303 | " # Inicializamos la entrada de datos\n", 304 | " symbol = symbols_list[asset][0]\n", 305 | " lot = symbols_list[asset][1]\n", 306 | "\n", 307 | " # Creamos la señal\n", 308 | " buy, sell = random()\n", 309 | "\n", 310 | " # Ejecutamos el algoritmo\n", 311 | " MT5.run(symbol, buy, sell, lot)\n" 312 | ] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": null, 317 | "id": "36b23b8b", 318 | "metadata": {}, 319 | "outputs": [], 320 | "source": [] 321 | } 322 | ], 323 | "metadata": { 324 | "kernelspec": { 325 | "display_name": "Python 3", 326 | "language": "python", 327 | "name": "python3" 328 | }, 329 | "language_info": { 330 | "codemirror_mode": { 331 | "name": "ipython", 332 | "version": 3 333 | }, 334 | "file_extension": ".py", 335 | "mimetype": "text/x-python", 336 | "name": "python", 337 | "nbconvert_exporter": "python", 338 | "pygments_lexer": "ipython3", 339 | "version": "3.8.8" 340 | } 341 | }, 342 | "nbformat": 4, 343 | "nbformat_minor": 5 344 | } 345 | -------------------------------------------------------------------------------- /ES_ML_Capítulo_01_Los_fundamentos_de_Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "ES-TA Capítulo 01: Los fundamentos de Python.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [ 9 | "Kd-SYHI-ZF85", 10 | "2UHCKDk8bJEf", 11 | "W9Vc62veaNKg", 12 | "7xKs11J6akHQ", 13 | "wwObVh1w9Wl9", 14 | "-9ElsbKP-xvK", 15 | "emrr2xJjhmKd", 16 | "S0TnQtBMfRXB", 17 | "F8rax_dDgnFI", 18 | "4NWfx4mRhpgX" 19 | ], 20 | "toc_visible": true, 21 | "include_colab_link": true 22 | }, 23 | "kernelspec": { 24 | "name": "python3", 25 | "display_name": "Python 3" 26 | } 27 | }, 28 | "cells": [ 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "id": "view-in-github", 33 | "colab_type": "text" 34 | }, 35 | "source": [ 36 | "\"Open" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": { 42 | "id": "HwIk5lNgltIS" 43 | }, 44 | "source": [ 45 | "

\"Colaboratory\n", 46 | "\"Colaboratory

\n", 47 | "\n", 48 | "# PRERREQUISITOS - **Las Bases de Python**\n", 49 | "\n", 50 | "Este capítulo te dará los fundamentos de python que necesitas para seguir el resto del curso. Estos son sólo recordatorios de lo que será útil. Por eso te aconsejo que sigas una formación rápida de Python para tus proyectos, porque si eres totalmente ajeno a él, puede ser difícil hacer tu proyecto. Nosotros te recomendamos el curso de más de 50 horas de programación, [Python de la A a la Z que puedes obtener desde nuestra web de frogames](https://cursos.frogamesformacion.com/courses/python-az/).\n", 51 | "\n", 52 | "\n", 53 | "### Parte 1: Los fundamentos de Python\n", 54 | "* Tipos de objetos:\n", 55 | "> * Números, Strings y Booleanos\n", 56 | "> * Tuplas y Listas\n", 57 | "> * Asignación de Variables\n", 58 | "* Estructuras de Python:\n", 59 | "> * If/Elif/Else\n", 60 | "> * For\n", 61 | "> * While\n", 62 | "* Las funciones\n", 63 | "> * Base de las funciones\n", 64 | "> * Variable local\n", 65 | "> * Variable global\n", 66 | "> * Función lambda\n", 67 | "\n", 68 | "\n", 69 | "\n", 70 | "💰 Únete a la comunidad de [Discord](https://discord.gg/z3dx5XpkX4)\n", 71 | "\n", 72 | "📚 Puedes leer nuestro libro en [Amazon](https://www.amazon.es/Python-para-finanzas-trading-algor%C3%ADtmico-ebook/dp/B0BT4ZS9Q3/)\n", 73 | "\n", 74 | "🖥️ El canal de [YouTube de Quantreo's](https://www.youtube.com/channel/UCp7jckfiEglNf_Gj62VR0pw) (en inglés) y el de [Frogames](https://www.youtube.com/channel/UCMUxXNYrVCv6-bQakhomvBg) en español\n", 75 | "\n", 76 | "\n", 77 | "\n", 78 | "\n" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": { 84 | "id": "nJYyIbZ_WbFT" 85 | }, 86 | "source": [ 87 | "### Tipos de Objetos" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "metadata": { 93 | "id": "DuY3oXKNWd1h" 94 | }, 95 | "source": [ 96 | "##### Números" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "metadata": { 102 | "id": "yoYnGbme8kcq", 103 | "colab": { 104 | "base_uri": "https://localhost:8080/" 105 | }, 106 | "outputId": "437cc0f9-8fe7-48d2-eed3-2f291f12b80d" 107 | }, 108 | "source": [ 109 | "# Suma\n", 110 | "6 + 3" 111 | ], 112 | "execution_count": null, 113 | "outputs": [ 114 | { 115 | "output_type": "execute_result", 116 | "data": { 117 | "text/plain": [ 118 | "9" 119 | ] 120 | }, 121 | "metadata": {}, 122 | "execution_count": 2 123 | } 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "metadata": { 129 | "id": "lPQ-ZedRCtL0", 130 | "colab": { 131 | "base_uri": "https://localhost:8080/" 132 | }, 133 | "outputId": "c048434e-1297-4fc4-af46-2e3c6c60068f" 134 | }, 135 | "source": [ 136 | "# Resta\n", 137 | "6 - 3" 138 | ], 139 | "execution_count": null, 140 | "outputs": [ 141 | { 142 | "output_type": "execute_result", 143 | "data": { 144 | "text/plain": [ 145 | "3" 146 | ] 147 | }, 148 | "metadata": {}, 149 | "execution_count": 3 150 | } 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "metadata": { 156 | "id": "FSWWYIqBCwlg", 157 | "colab": { 158 | "base_uri": "https://localhost:8080/" 159 | }, 160 | "outputId": "7a563f0c-e5ff-4e7c-ab34-43e71e9f4868" 161 | }, 162 | "source": [ 163 | "# Multiplicación\n", 164 | "6 * 3" 165 | ], 166 | "execution_count": null, 167 | "outputs": [ 168 | { 169 | "output_type": "execute_result", 170 | "data": { 171 | "text/plain": [ 172 | "18" 173 | ] 174 | }, 175 | "metadata": {}, 176 | "execution_count": 4 177 | } 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "metadata": { 183 | "id": "fMQNWXVvC0Sx", 184 | "colab": { 185 | "base_uri": "https://localhost:8080/" 186 | }, 187 | "outputId": "49d726ae-5b3c-4325-a41f-776ac22050e0" 188 | }, 189 | "source": [ 190 | "# División \n", 191 | "16 / 3" 192 | ], 193 | "execution_count": null, 194 | "outputs": [ 195 | { 196 | "output_type": "execute_result", 197 | "data": { 198 | "text/plain": [ 199 | "5.333333333333333" 200 | ] 201 | }, 202 | "metadata": {}, 203 | "execution_count": 5 204 | } 205 | ] 206 | }, 207 | { 208 | "cell_type": "code", 209 | "metadata": { 210 | "id": "DH1jRr5_Xxo2", 211 | "colab": { 212 | "base_uri": "https://localhost:8080/" 213 | }, 214 | "outputId": "73f6324b-0da9-4aac-ef28-e3c137926ef3" 215 | }, 216 | "source": [ 217 | "# Potencias 2*2*2\n", 218 | "2**3" 219 | ], 220 | "execution_count": null, 221 | "outputs": [ 222 | { 223 | "output_type": "execute_result", 224 | "data": { 225 | "text/plain": [ 226 | "8" 227 | ] 228 | }, 229 | "metadata": {}, 230 | "execution_count": 8 231 | } 232 | ] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "metadata": { 237 | "id": "abqfE8I2C2cr", 238 | "colab": { 239 | "base_uri": "https://localhost:8080/" 240 | }, 241 | "outputId": "72e08e7e-5327-428a-baef-4f543e1d02be" 242 | }, 243 | "source": [ 244 | "# División entera (euclídea) | 5.33 --> 5\n", 245 | "16 // 3" 246 | ], 247 | "execution_count": null, 248 | "outputs": [ 249 | { 250 | "output_type": "execute_result", 251 | "data": { 252 | "text/plain": [ 253 | "5" 254 | ] 255 | }, 256 | "metadata": {}, 257 | "execution_count": 9 258 | } 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "metadata": { 264 | "id": "SnktoxGAC_ew", 265 | "colab": { 266 | "base_uri": "https://localhost:8080/" 267 | }, 268 | "outputId": "69f73e5f-62a7-4ee5-d5fb-aedcf4e86af6" 269 | }, 270 | "source": [ 271 | "# Módulo | 16 = 5*3 + 1 \n", 272 | "16 % 3" 273 | ], 274 | "execution_count": null, 275 | "outputs": [ 276 | { 277 | "output_type": "execute_result", 278 | "data": { 279 | "text/plain": [ 280 | "1" 281 | ] 282 | }, 283 | "metadata": {}, 284 | "execution_count": 10 285 | } 286 | ] 287 | }, 288 | { 289 | "cell_type": "markdown", 290 | "metadata": { 291 | "id": "iEQQbsVFWkKi" 292 | }, 293 | "source": [ 294 | "##### String" 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "metadata": { 300 | "id": "8jOPFgexDF2H", 301 | "colab": { 302 | "base_uri": "https://localhost:8080/", 303 | "height": 35 304 | }, 305 | "outputId": "b85f9965-8c17-410b-cf3a-31d544dbe048" 306 | }, 307 | "source": [ 308 | "# Simple String\n", 309 | "print(\"Soy una información\")" 310 | ], 311 | "execution_count": null, 312 | "outputs": [ 313 | { 314 | "output_type": "execute_result", 315 | "data": { 316 | "text/plain": [ 317 | "'Soy una información'" 318 | ], 319 | "application/vnd.google.colaboratory.intrinsic+json": { 320 | "type": "string" 321 | } 322 | }, 323 | "metadata": {}, 324 | "execution_count": 2 325 | } 326 | ] 327 | }, 328 | { 329 | "cell_type": "code", 330 | "metadata": { 331 | "colab": { 332 | "base_uri": "https://localhost:8080/" 333 | }, 334 | "id": "ibeFvaYOnCDd", 335 | "outputId": "b7fc4fde-fcc3-4c07-c2a4-f7b423ca28ba" 336 | }, 337 | "source": [ 338 | "# Añadir una tabulación\n", 339 | "print(\"Media:10% \\t Volatilidad:10%\")" 340 | ], 341 | "execution_count": null, 342 | "outputs": [ 343 | { 344 | "output_type": "stream", 345 | "name": "stdout", 346 | "text": [ 347 | "Media:10% \t Volatilidad:10%\n" 348 | ] 349 | } 350 | ] 351 | }, 352 | { 353 | "cell_type": "code", 354 | "metadata": { 355 | "colab": { 356 | "base_uri": "https://localhost:8080/" 357 | }, 358 | "id": "rGWkCu3vpDoW", 359 | "outputId": "156abeae-6884-45a8-deee-3a2c317f50a5" 360 | }, 361 | "source": [ 362 | "# Salto de línea\n", 363 | "print(\"Media:10% \\nVolatilidad:10%\")" 364 | ], 365 | "execution_count": null, 366 | "outputs": [ 367 | { 368 | "output_type": "stream", 369 | "name": "stdout", 370 | "text": [ 371 | "Media:10% \n", 372 | "Volatilidad:10%\n" 373 | ] 374 | } 375 | ] 376 | }, 377 | { 378 | "cell_type": "code", 379 | "metadata": { 380 | "id": "zLAVLu5rWv2a", 381 | "colab": { 382 | "base_uri": "https://localhost:8080/" 383 | }, 384 | "outputId": "1ba52c4b-7fa0-44b6-b559-7428edbeb48c" 385 | }, 386 | "source": [ 387 | "# String dinámico (primera opción: simple string using the format function)\n", 388 | "print(\"Precio de las acciones de Tesla: {}$ en la fecha {}\".format(110,\"01-01-2020\"))" 389 | ], 390 | "execution_count": null, 391 | "outputs": [ 392 | { 393 | "output_type": "stream", 394 | "name": "stdout", 395 | "text": [ 396 | "Precio de las acciones de Tesla: 110$ en la fecha 01-01-2020\n" 397 | ] 398 | } 399 | ] 400 | }, 401 | { 402 | "cell_type": "code", 403 | "metadata": { 404 | "id": "shGzNr67Wvx0", 405 | "colab": { 406 | "base_uri": "https://localhost:8080/" 407 | }, 408 | "outputId": "f8c2e1f3-877e-4cda-92a4-34290d4c1489" 409 | }, 410 | "source": [ 411 | "# String dinámico (segunda opción: f-string )\n", 412 | "print(f\"Precio de las acciones de Tesla: {110}$ en la fecha {'01-01-2010'}\")" 413 | ], 414 | "execution_count": null, 415 | "outputs": [ 416 | { 417 | "output_type": "stream", 418 | "name": "stdout", 419 | "text": [ 420 | "Precio de las acciones de Tesla: 110$ en la fecha 01-01-2010\n" 421 | ] 422 | } 423 | ] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "metadata": { 428 | "colab": { 429 | "base_uri": "https://localhost:8080/" 430 | }, 431 | "id": "Uaz_tqJgpMae", 432 | "outputId": "d7c120c8-94e4-4b86-9a3e-75e62093c010" 433 | }, 434 | "source": [ 435 | "# Redondear un número con f-string\n", 436 | "print(f\"Precio de las acciones de Tesla: {'%.2f' % 110.15645147854}$\")" 437 | ], 438 | "execution_count": null, 439 | "outputs": [ 440 | { 441 | "output_type": "stream", 442 | "name": "stdout", 443 | "text": [ 444 | "Precio de las acciones de Tesla: 110.16$\n" 445 | ] 446 | } 447 | ] 448 | }, 449 | { 450 | "cell_type": "code", 451 | "metadata": { 452 | "id": "ud27MNZYdwSG", 453 | "colab": { 454 | "base_uri": "https://localhost:8080/", 455 | "height": 35 456 | }, 457 | "outputId": "6a81412a-0bca-47d0-943f-19f71cdaecad" 458 | }, 459 | "source": [ 460 | "# Slicing en strings\n", 461 | "\"Soy una información\"[0:6]" 462 | ], 463 | "execution_count": null, 464 | "outputs": [ 465 | { 466 | "output_type": "execute_result", 467 | "data": { 468 | "text/plain": [ 469 | "'Soy un'" 470 | ], 471 | "application/vnd.google.colaboratory.intrinsic+json": { 472 | "type": "string" 473 | } 474 | }, 475 | "metadata": {}, 476 | "execution_count": 20 477 | } 478 | ] 479 | }, 480 | { 481 | "cell_type": "markdown", 482 | "metadata": { 483 | "id": "JUULnsP_Xemv" 484 | }, 485 | "source": [ 486 | "##### Operadores booleanos / lógicos" 487 | ] 488 | }, 489 | { 490 | "cell_type": "code", 491 | "metadata": { 492 | "id": "vM_KlXcMWvtr", 493 | "colab": { 494 | "base_uri": "https://localhost:8080/" 495 | }, 496 | "outputId": "0a313eb1-7dd2-4d3d-e7d0-d6fdbfa87f77" 497 | }, 498 | "source": [ 499 | "# Tipo Booleano (True)\n", 500 | "True" 501 | ], 502 | "execution_count": null, 503 | "outputs": [ 504 | { 505 | "output_type": "execute_result", 506 | "data": { 507 | "text/plain": [ 508 | "True" 509 | ] 510 | }, 511 | "metadata": {}, 512 | "execution_count": 21 513 | } 514 | ] 515 | }, 516 | { 517 | "cell_type": "code", 518 | "metadata": { 519 | "id": "53gTC6s5WvsF", 520 | "colab": { 521 | "base_uri": "https://localhost:8080/" 522 | }, 523 | "outputId": "ead7f7ef-4360-4066-b2ac-678935d6f3a9" 524 | }, 525 | "source": [ 526 | "# Tipo Booleano (False)\n", 527 | "False" 528 | ], 529 | "execution_count": null, 530 | "outputs": [ 531 | { 532 | "output_type": "execute_result", 533 | "data": { 534 | "text/plain": [ 535 | "False" 536 | ] 537 | }, 538 | "metadata": {}, 539 | "execution_count": 22 540 | } 541 | ] 542 | }, 543 | { 544 | "cell_type": "code", 545 | "metadata": { 546 | "id": "IoozzT2bdK_u", 547 | "colab": { 548 | "base_uri": "https://localhost:8080/" 549 | }, 550 | "outputId": "3bf66adb-979c-47bd-9788-7881cd5ad3d8" 551 | }, 552 | "source": [ 553 | "# Igualdad\n", 554 | "5 == 6" 555 | ], 556 | "execution_count": null, 557 | "outputs": [ 558 | { 559 | "output_type": "execute_result", 560 | "data": { 561 | "text/plain": [ 562 | "False" 563 | ] 564 | }, 565 | "metadata": {}, 566 | "execution_count": 23 567 | } 568 | ] 569 | }, 570 | { 571 | "cell_type": "code", 572 | "metadata": { 573 | "id": "_f1XD2w3dgY5", 574 | "colab": { 575 | "base_uri": "https://localhost:8080/" 576 | }, 577 | "outputId": "cc706dde-a4e8-4138-a41b-fe0d2d0a8ebe" 578 | }, 579 | "source": [ 580 | "# Sup\n", 581 | "5 > 6" 582 | ], 583 | "execution_count": null, 584 | "outputs": [ 585 | { 586 | "output_type": "execute_result", 587 | "data": { 588 | "text/plain": [ 589 | "False" 590 | ] 591 | }, 592 | "metadata": {}, 593 | "execution_count": 24 594 | } 595 | ] 596 | }, 597 | { 598 | "cell_type": "code", 599 | "metadata": { 600 | "id": "yZj4kBbLdkUo", 601 | "colab": { 602 | "base_uri": "https://localhost:8080/" 603 | }, 604 | "outputId": "b3d124fd-25f1-4749-9255-1071af1b3e1c" 605 | }, 606 | "source": [ 607 | "# Inf\n", 608 | "5 < 6" 609 | ], 610 | "execution_count": null, 611 | "outputs": [ 612 | { 613 | "output_type": "execute_result", 614 | "data": { 615 | "text/plain": [ 616 | "True" 617 | ] 618 | }, 619 | "metadata": {}, 620 | "execution_count": 25 621 | } 622 | ] 623 | }, 624 | { 625 | "cell_type": "code", 626 | "metadata": { 627 | "id": "BbEIqsW4ducB", 628 | "colab": { 629 | "base_uri": "https://localhost:8080/" 630 | }, 631 | "outputId": "b11aa784-f150-47bf-8008-e9603f3514d9" 632 | }, 633 | "source": [ 634 | "# No Igual\n", 635 | "5 != 6" 636 | ], 637 | "execution_count": null, 638 | "outputs": [ 639 | { 640 | "output_type": "execute_result", 641 | "data": { 642 | "text/plain": [ 643 | "True" 644 | ] 645 | }, 646 | "metadata": {}, 647 | "execution_count": 26 648 | } 649 | ] 650 | }, 651 | { 652 | "cell_type": "code", 653 | "metadata": { 654 | "id": "15J-4du3d0o-", 655 | "colab": { 656 | "base_uri": "https://localhost:8080/" 657 | }, 658 | "outputId": "cc67cd4e-2e58-499b-8013-51c3b6565bb3" 659 | }, 660 | "source": [ 661 | "# Y \n", 662 | "(1<2) and (5>6)" 663 | ], 664 | "execution_count": null, 665 | "outputs": [ 666 | { 667 | "output_type": "execute_result", 668 | "data": { 669 | "text/plain": [ 670 | "False" 671 | ] 672 | }, 673 | "metadata": {}, 674 | "execution_count": 29 675 | } 676 | ] 677 | }, 678 | { 679 | "cell_type": "code", 680 | "metadata": { 681 | "id": "XtzLTurHd47e", 682 | "colab": { 683 | "base_uri": "https://localhost:8080/" 684 | }, 685 | "outputId": "e57589ab-2768-49a0-d50e-2db3522fd49e" 686 | }, 687 | "source": [ 688 | "# O\n", 689 | "(1<2) or (5>6)" 690 | ], 691 | "execution_count": null, 692 | "outputs": [ 693 | { 694 | "output_type": "execute_result", 695 | "data": { 696 | "text/plain": [ 697 | "True" 698 | ] 699 | }, 700 | "metadata": {}, 701 | "execution_count": 32 702 | } 703 | ] 704 | }, 705 | { 706 | "cell_type": "code", 707 | "metadata": { 708 | "id": "pTRdjRHyZKZ7", 709 | "colab": { 710 | "base_uri": "https://localhost:8080/" 711 | }, 712 | "outputId": "d194dabe-5ad9-4d9c-d851-a35bd1a4093b" 713 | }, 714 | "source": [ 715 | "# No \n", 716 | "not (5>6)" 717 | ], 718 | "execution_count": null, 719 | "outputs": [ 720 | { 721 | "output_type": "execute_result", 722 | "data": { 723 | "text/plain": [ 724 | "True" 725 | ] 726 | }, 727 | "metadata": {}, 728 | "execution_count": 34 729 | } 730 | ] 731 | }, 732 | { 733 | "cell_type": "markdown", 734 | "metadata": { 735 | "id": "cGqtdDyYX1Dk" 736 | }, 737 | "source": [ 738 | "##### Asignación de variables" 739 | ] 740 | }, 741 | { 742 | "cell_type": "code", 743 | "metadata": { 744 | "id": "q3PsKlhZWvlz", 745 | "colab": { 746 | "base_uri": "https://localhost:8080/" 747 | }, 748 | "outputId": "adde20ff-1905-4e46-a915-6fe23c153e5f" 749 | }, 750 | "source": [ 751 | "# Variables Numéricas\n", 752 | "x = 6\n", 753 | "y = 5\n", 754 | "print(x + y)" 755 | ], 756 | "execution_count": null, 757 | "outputs": [ 758 | { 759 | "output_type": "stream", 760 | "name": "stdout", 761 | "text": [ 762 | "11\n" 763 | ] 764 | } 765 | ] 766 | }, 767 | { 768 | "cell_type": "code", 769 | "metadata": { 770 | "id": "NrwwCpCCWvkU", 771 | "colab": { 772 | "base_uri": "https://localhost:8080/" 773 | }, 774 | "outputId": "665c7bc5-3a0c-4120-e892-a9e818329a3b" 775 | }, 776 | "source": [ 777 | "# Variables String\n", 778 | "date = \"03-13-2020\"\n", 779 | "price = 180\n", 780 | "info = f\"Tesla: {price}$, Fecha: {date}\"\n", 781 | "\n", 782 | "print(info)" 783 | ], 784 | "execution_count": null, 785 | "outputs": [ 786 | { 787 | "output_type": "stream", 788 | "name": "stdout", 789 | "text": [ 790 | "Tesla: 180$, Fecha: 03-13-2020\n" 791 | ] 792 | } 793 | ] 794 | }, 795 | { 796 | "cell_type": "code", 797 | "metadata": { 798 | "id": "ufENsej-WveT", 799 | "colab": { 800 | "base_uri": "https://localhost:8080/" 801 | }, 802 | "outputId": "229f98c1-c9e7-40b0-c6a0-08a064510907" 803 | }, 804 | "source": [ 805 | "# Variables Booleanas\n", 806 | "time = \"20:00\"\n", 807 | "market_open = (\"08:00\" < time) and (time < \"19:00\")\n", 808 | "print(market_open)" 809 | ], 810 | "execution_count": null, 811 | "outputs": [ 812 | { 813 | "output_type": "stream", 814 | "name": "stdout", 815 | "text": [ 816 | "False\n" 817 | ] 818 | } 819 | ] 820 | }, 821 | { 822 | "cell_type": "markdown", 823 | "metadata": { 824 | "id": "EMAdDk_6YXgw" 825 | }, 826 | "source": [ 827 | "##### Tuplas y Listas" 828 | ] 829 | }, 830 | { 831 | "cell_type": "code", 832 | "metadata": { 833 | "id": "WY3Eyz5PWvcm", 834 | "colab": { 835 | "base_uri": "https://localhost:8080/" 836 | }, 837 | "outputId": "57db579f-888d-4b6e-fe88-109437893669" 838 | }, 839 | "source": [ 840 | "# Tupla\n", 841 | "my_tuple = (1,2,3)\n", 842 | "my_tuple" 843 | ], 844 | "execution_count": null, 845 | "outputs": [ 846 | { 847 | "output_type": "execute_result", 848 | "data": { 849 | "text/plain": [ 850 | "(1, 2, 3)" 851 | ] 852 | }, 853 | "metadata": {}, 854 | "execution_count": 42 855 | } 856 | ] 857 | }, 858 | { 859 | "cell_type": "code", 860 | "metadata": { 861 | "id": "L7RGe8QgWvYt", 862 | "colab": { 863 | "base_uri": "https://localhost:8080/" 864 | }, 865 | "outputId": "635fdc99-0bfa-4080-bd42-5abb8f157776" 866 | }, 867 | "source": [ 868 | "# Crear una lista\n", 869 | "my_list = [1,2,3,4,5,6,7,8,9,10]\n", 870 | "my_list" 871 | ], 872 | "execution_count": null, 873 | "outputs": [ 874 | { 875 | "output_type": "execute_result", 876 | "data": { 877 | "text/plain": [ 878 | "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" 879 | ] 880 | }, 881 | "metadata": {}, 882 | "execution_count": 43 883 | } 884 | ] 885 | }, 886 | { 887 | "cell_type": "code", 888 | "metadata": { 889 | "id": "OSQw1R5yWvPy", 890 | "colab": { 891 | "base_uri": "https://localhost:8080/" 892 | }, 893 | "outputId": "aed8de95-11ec-4344-9814-4e51adaf1cd4" 894 | }, 895 | "source": [ 896 | "# Añadir valores\n", 897 | "my_list.append(11)\n", 898 | "my_list" 899 | ], 900 | "execution_count": null, 901 | "outputs": [ 902 | { 903 | "output_type": "execute_result", 904 | "data": { 905 | "text/plain": [ 906 | "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]" 907 | ] 908 | }, 909 | "metadata": {}, 910 | "execution_count": 44 911 | } 912 | ] 913 | }, 914 | { 915 | "cell_type": "code", 916 | "metadata": { 917 | "colab": { 918 | "base_uri": "https://localhost:8080/" 919 | }, 920 | "id": "8p9Tpd42zOq_", 921 | "outputId": "5be98bbb-0c0b-4feb-e923-d4daefd60213" 922 | }, 923 | "source": [ 924 | "# Añadir valores\n", 925 | "my_list.extend([12,13,14,15,16,17])\n", 926 | "my_list" 927 | ], 928 | "execution_count": null, 929 | "outputs": [ 930 | { 931 | "output_type": "execute_result", 932 | "data": { 933 | "text/plain": [ 934 | "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]" 935 | ] 936 | }, 937 | "metadata": {}, 938 | "execution_count": 45 939 | } 940 | ] 941 | }, 942 | { 943 | "cell_type": "code", 944 | "metadata": { 945 | "id": "i391z7t4ZwnM", 946 | "colab": { 947 | "base_uri": "https://localhost:8080/" 948 | }, 949 | "outputId": "236b147c-9142-4a2b-8318-6378ab511054" 950 | }, 951 | "source": [ 952 | "# Índices\n", 953 | "my_list[0]" 954 | ], 955 | "execution_count": null, 956 | "outputs": [ 957 | { 958 | "output_type": "execute_result", 959 | "data": { 960 | "text/plain": [ 961 | "1" 962 | ] 963 | }, 964 | "metadata": {}, 965 | "execution_count": 51 966 | } 967 | ] 968 | }, 969 | { 970 | "cell_type": "code", 971 | "metadata": { 972 | "id": "owXGp0IsZ3Lg", 973 | "colab": { 974 | "base_uri": "https://localhost:8080/" 975 | }, 976 | "outputId": "ad56180f-9c36-4553-cf6b-a4b669a266f9" 977 | }, 978 | "source": [ 979 | "# Selección de un rango de valores\n", 980 | "my_list[0:9]" 981 | ], 982 | "execution_count": null, 983 | "outputs": [ 984 | { 985 | "output_type": "execute_result", 986 | "data": { 987 | "text/plain": [ 988 | "[1, 2, 3, 4, 5, 6, 7, 8, 9]" 989 | ] 990 | }, 991 | "metadata": {}, 992 | "execution_count": 56 993 | } 994 | ] 995 | }, 996 | { 997 | "cell_type": "code", 998 | "metadata": { 999 | "id": "g5SsaYNjZ6Jo", 1000 | "colab": { 1001 | "base_uri": "https://localhost:8080/" 1002 | }, 1003 | "outputId": "6dedb085-aef8-4525-e9d1-265284929463" 1004 | }, 1005 | "source": [ 1006 | "# Eliminar un valor\n", 1007 | "del my_list[0]\n", 1008 | "my_list" 1009 | ], 1010 | "execution_count": null, 1011 | "outputs": [ 1012 | { 1013 | "output_type": "execute_result", 1014 | "data": { 1015 | "text/plain": [ 1016 | "[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]" 1017 | ] 1018 | }, 1019 | "metadata": {}, 1020 | "execution_count": 57 1021 | } 1022 | ] 1023 | }, 1024 | { 1025 | "cell_type": "code", 1026 | "metadata": { 1027 | "id": "JH1xzsjTZOhr", 1028 | "colab": { 1029 | "base_uri": "https://localhost:8080/" 1030 | }, 1031 | "outputId": "6b5e73a4-377f-4e75-f451-f9792121517c" 1032 | }, 1033 | "source": [ 1034 | "# Bonus: Listas anidadas\n", 1035 | "my_list = [[1,15], 3, \"Finance\"]\n", 1036 | "\n", 1037 | "# Imprimir la sublista\n", 1038 | "print(my_list[0])\n", 1039 | "\n", 1040 | "# Imprimir el valor 15\n", 1041 | "print(my_list[0][1])" 1042 | ], 1043 | "execution_count": null, 1044 | "outputs": [ 1045 | { 1046 | "output_type": "stream", 1047 | "name": "stdout", 1048 | "text": [ 1049 | "[1, 15]\n", 1050 | "15\n" 1051 | ] 1052 | } 1053 | ] 1054 | }, 1055 | { 1056 | "cell_type": "markdown", 1057 | "metadata": { 1058 | "id": "Kd-SYHI-ZF85" 1059 | }, 1060 | "source": [ 1061 | "##### Diccionarios" 1062 | ] 1063 | }, 1064 | { 1065 | "cell_type": "code", 1066 | "metadata": { 1067 | "id": "7PasvUGAZw7L" 1068 | }, 1069 | "source": [ 1070 | "# Inicializar un diccionario\n", 1071 | "dic = {}" 1072 | ], 1073 | "execution_count": null, 1074 | "outputs": [] 1075 | }, 1076 | { 1077 | "cell_type": "code", 1078 | "metadata": { 1079 | "id": "FngIfxOfZ-o5", 1080 | "colab": { 1081 | "base_uri": "https://localhost:8080/" 1082 | }, 1083 | "outputId": "1875dd1e-d27b-4830-f73e-a76f29929a63" 1084 | }, 1085 | "source": [ 1086 | "# Inicializar con valores\n", 1087 | "dic = {\"Tesla price\" : 1500,\n", 1088 | " \"Google price\": 3000}\n", 1089 | "dic" 1090 | ], 1091 | "execution_count": null, 1092 | "outputs": [ 1093 | { 1094 | "output_type": "execute_result", 1095 | "data": { 1096 | "text/plain": [ 1097 | "{'Google price': 3000, 'Tesla price': 1500}" 1098 | ] 1099 | }, 1100 | "metadata": {}, 1101 | "execution_count": 65 1102 | } 1103 | ] 1104 | }, 1105 | { 1106 | "cell_type": "code", 1107 | "metadata": { 1108 | "id": "XT9t_7nraYJL", 1109 | "colab": { 1110 | "base_uri": "https://localhost:8080/" 1111 | }, 1112 | "outputId": "4680300b-414e-4a25-c364-71ec3422aad7" 1113 | }, 1114 | "source": [ 1115 | "# Añadir un valor\n", 1116 | "dic[\"Microsoft price\"] = 1500\n", 1117 | "dic" 1118 | ], 1119 | "execution_count": null, 1120 | "outputs": [ 1121 | { 1122 | "output_type": "execute_result", 1123 | "data": { 1124 | "text/plain": [ 1125 | "{'Google price': 3000, 'Microsoft price': 1500, 'Tesla price': 1500}" 1126 | ] 1127 | }, 1128 | "metadata": {}, 1129 | "execution_count": 66 1130 | } 1131 | ] 1132 | }, 1133 | { 1134 | "cell_type": "code", 1135 | "metadata": { 1136 | "colab": { 1137 | "base_uri": "https://localhost:8080/" 1138 | }, 1139 | "id": "1fnoJHGmaRtG", 1140 | "outputId": "91dcd881-dac2-4841-cb36-af28484bcebf" 1141 | }, 1142 | "source": [ 1143 | "# Cambiar un valor\n", 1144 | "dic[\"Microsoft price\"] = 3000\n", 1145 | "dic" 1146 | ], 1147 | "execution_count": null, 1148 | "outputs": [ 1149 | { 1150 | "output_type": "execute_result", 1151 | "data": { 1152 | "text/plain": [ 1153 | "{'Google price': 3000, 'Microsoft price': 3000, 'Tesla price': 1500}" 1154 | ] 1155 | }, 1156 | "metadata": {}, 1157 | "execution_count": 67 1158 | } 1159 | ] 1160 | }, 1161 | { 1162 | "cell_type": "code", 1163 | "metadata": { 1164 | "id": "t4GhmGtdapWP", 1165 | "colab": { 1166 | "base_uri": "https://localhost:8080/" 1167 | }, 1168 | "outputId": "17603bb6-99dd-461d-8921-1e4bf3e98b9a" 1169 | }, 1170 | "source": [ 1171 | "# Extraer un valor\n", 1172 | "dic[\"Microsoft price\"]" 1173 | ], 1174 | "execution_count": null, 1175 | "outputs": [ 1176 | { 1177 | "output_type": "execute_result", 1178 | "data": { 1179 | "text/plain": [ 1180 | "3000" 1181 | ] 1182 | }, 1183 | "metadata": {}, 1184 | "execution_count": 68 1185 | } 1186 | ] 1187 | }, 1188 | { 1189 | "cell_type": "code", 1190 | "metadata": { 1191 | "colab": { 1192 | "base_uri": "https://localhost:8080/" 1193 | }, 1194 | "id": "rOBalLlC3Et8", 1195 | "outputId": "5b5a1592-8b2b-482c-c502-be8a5df99fcb" 1196 | }, 1197 | "source": [ 1198 | "# Eliminar un valor\n", 1199 | "del dic[\"Microsoft price\"]\n", 1200 | "dic" 1201 | ], 1202 | "execution_count": null, 1203 | "outputs": [ 1204 | { 1205 | "output_type": "execute_result", 1206 | "data": { 1207 | "text/plain": [ 1208 | "{'Google price': 3000, 'Tesla price': 1500}" 1209 | ] 1210 | }, 1211 | "metadata": {}, 1212 | "execution_count": 69 1213 | } 1214 | ] 1215 | }, 1216 | { 1217 | "cell_type": "code", 1218 | "metadata": { 1219 | "colab": { 1220 | "base_uri": "https://localhost:8080/" 1221 | }, 1222 | "id": "otvn059la3Ct", 1223 | "outputId": "fe4b018b-7f13-4182-eec6-70ad0cd473d0" 1224 | }, 1225 | "source": [ 1226 | "# Extraer el nombre de las claves\n", 1227 | "dic.keys()" 1228 | ], 1229 | "execution_count": null, 1230 | "outputs": [ 1231 | { 1232 | "output_type": "execute_result", 1233 | "data": { 1234 | "text/plain": [ 1235 | "dict_keys(['Tesla price', 'Google price'])" 1236 | ] 1237 | }, 1238 | "metadata": {}, 1239 | "execution_count": 70 1240 | } 1241 | ] 1242 | }, 1243 | { 1244 | "cell_type": "code", 1245 | "metadata": { 1246 | "colab": { 1247 | "base_uri": "https://localhost:8080/" 1248 | }, 1249 | "id": "ndKUymfzbF4t", 1250 | "outputId": "df471e24-bb8d-4f43-9dd9-344ca72f0a12" 1251 | }, 1252 | "source": [ 1253 | "# Extraer los valores del diccionario\n", 1254 | "dic.values()" 1255 | ], 1256 | "execution_count": null, 1257 | "outputs": [ 1258 | { 1259 | "output_type": "execute_result", 1260 | "data": { 1261 | "text/plain": [ 1262 | "dict_values([1500, 3000])" 1263 | ] 1264 | }, 1265 | "metadata": {}, 1266 | "execution_count": 71 1267 | } 1268 | ] 1269 | }, 1270 | { 1271 | "cell_type": "markdown", 1272 | "metadata": { 1273 | "id": "2UHCKDk8bJEf" 1274 | }, 1275 | "source": [ 1276 | "##### Conjuntos" 1277 | ] 1278 | }, 1279 | { 1280 | "cell_type": "code", 1281 | "metadata": { 1282 | "id": "viHNp-EHbQ9H", 1283 | "colab": { 1284 | "base_uri": "https://localhost:8080/" 1285 | }, 1286 | "outputId": "130d4fa3-df3c-46a8-fbd9-06cb707f69c5" 1287 | }, 1288 | "source": [ 1289 | "# Crear un conjunto\n", 1290 | "{1,3,9}" 1291 | ], 1292 | "execution_count": 1, 1293 | "outputs": [ 1294 | { 1295 | "output_type": "execute_result", 1296 | "data": { 1297 | "text/plain": [ 1298 | "{1, 3, 9}" 1299 | ] 1300 | }, 1301 | "metadata": {}, 1302 | "execution_count": 1 1303 | } 1304 | ] 1305 | }, 1306 | { 1307 | "cell_type": "code", 1308 | "metadata": { 1309 | "id": "_E1aFnTcbYpJ", 1310 | "colab": { 1311 | "base_uri": "https://localhost:8080/" 1312 | }, 1313 | "outputId": "c7d78f55-cce1-4fb7-fec7-ff97ff2a23f3" 1314 | }, 1315 | "source": [ 1316 | "# Propiedad de los Conjuntos\n", 1317 | "{1,1,1, 3,3,3, 9,9,9}" 1318 | ], 1319 | "execution_count": 2, 1320 | "outputs": [ 1321 | { 1322 | "output_type": "execute_result", 1323 | "data": { 1324 | "text/plain": [ 1325 | "{1, 3, 9}" 1326 | ] 1327 | }, 1328 | "metadata": {}, 1329 | "execution_count": 2 1330 | } 1331 | ] 1332 | }, 1333 | { 1334 | "cell_type": "code", 1335 | "metadata": { 1336 | "id": "2kc9rLF6be3l", 1337 | "colab": { 1338 | "base_uri": "https://localhost:8080/" 1339 | }, 1340 | "outputId": "e7b7e73e-623d-4f6d-868e-4d73ccad2e92" 1341 | }, 1342 | "source": [ 1343 | "# Crear una lista\n", 1344 | "my_list = [\"Finanzas\", \"Estadística\", \"Matemáticas\",\n", 1345 | " \"Finanzas\", \"Estadística\", \"Finanzas\",\n", 1346 | " \"Matemáticas\", \"Finanzas\", \"Estadística\"]\n", 1347 | "\n", 1348 | "# Transformar una lista en un conjunto\n", 1349 | "set(my_list)" 1350 | ], 1351 | "execution_count": 3, 1352 | "outputs": [ 1353 | { 1354 | "output_type": "execute_result", 1355 | "data": { 1356 | "text/plain": [ 1357 | "{'Estadística', 'Finanzas', 'Matemáticas'}" 1358 | ] 1359 | }, 1360 | "metadata": {}, 1361 | "execution_count": 3 1362 | } 1363 | ] 1364 | }, 1365 | { 1366 | "cell_type": "code", 1367 | "metadata": { 1368 | "id": "s2b-8LgkcLs1", 1369 | "colab": { 1370 | "base_uri": "https://localhost:8080/" 1371 | }, 1372 | "outputId": "1b06f669-e2c3-4343-836d-8367caecfc02" 1373 | }, 1374 | "source": [ 1375 | "# Añadir un valor\n", 1376 | "s = {1,3,5}\n", 1377 | "print(s)\n", 1378 | "\n", 1379 | "s.add(56)\n", 1380 | "s.add(68)\n", 1381 | "print(s)" 1382 | ], 1383 | "execution_count": 4, 1384 | "outputs": [ 1385 | { 1386 | "output_type": "stream", 1387 | "name": "stdout", 1388 | "text": [ 1389 | "{1, 3, 5}\n", 1390 | "{1, 3, 68, 5, 56}\n" 1391 | ] 1392 | } 1393 | ] 1394 | }, 1395 | { 1396 | "cell_type": "markdown", 1397 | "metadata": { 1398 | "id": "W9Vc62veaNKg" 1399 | }, 1400 | "source": [ 1401 | "### Estructuras de código en Python " 1402 | ] 1403 | }, 1404 | { 1405 | "cell_type": "markdown", 1406 | "metadata": { 1407 | "id": "7xKs11J6akHQ" 1408 | }, 1409 | "source": [ 1410 | "##### If/ Elif/ Else" 1411 | ] 1412 | }, 1413 | { 1414 | "cell_type": "code", 1415 | "metadata": { 1416 | "id": "CqZigieEaOkf", 1417 | "colab": { 1418 | "base_uri": "https://localhost:8080/" 1419 | }, 1420 | "outputId": "41b03c0f-1f20-454f-b488-0e6811604694" 1421 | }, 1422 | "source": [ 1423 | "# Estructuras condicionales IF\n", 1424 | "if 5<6:\n", 1425 | " print(\"Sí\")" 1426 | ], 1427 | "execution_count": 6, 1428 | "outputs": [ 1429 | { 1430 | "output_type": "stream", 1431 | "name": "stdout", 1432 | "text": [ 1433 | "Sí\n" 1434 | ] 1435 | } 1436 | ] 1437 | }, 1438 | { 1439 | "cell_type": "code", 1440 | "metadata": { 1441 | "id": "neKqpCKn8y9N", 1442 | "colab": { 1443 | "base_uri": "https://localhost:8080/" 1444 | }, 1445 | "outputId": "89d60d03-66f9-427f-8502-acd44a74bf96" 1446 | }, 1447 | "source": [ 1448 | "# Estructuras condicionales IF/ ELSE\n", 1449 | "if 5>6:\n", 1450 | " print(\"Sí\")\n", 1451 | "else:\n", 1452 | " print(\"No\")" 1453 | ], 1454 | "execution_count": 9, 1455 | "outputs": [ 1456 | { 1457 | "output_type": "stream", 1458 | "name": "stdout", 1459 | "text": [ 1460 | "No\n" 1461 | ] 1462 | } 1463 | ] 1464 | }, 1465 | { 1466 | "cell_type": "code", 1467 | "metadata": { 1468 | "id": "qEKi-yu_873c", 1469 | "colab": { 1470 | "base_uri": "https://localhost:8080/" 1471 | }, 1472 | "outputId": "1a9da90c-cbee-4abb-a2b7-f0827b793238" 1473 | }, 1474 | "source": [ 1475 | "# Estructuras condicionales IF/ ELIF/ ELSE\n", 1476 | "x = 11\n", 1477 | "\n", 1478 | "if x>=15:\n", 1479 | " print(\"X>=15\")\n", 1480 | "elif x>10:\n", 1481 | " print(\"10\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mmy_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mloc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 1858 | "\u001b[0;31mNameError\u001b[0m: name 'loc' is not defined" 1859 | ] 1860 | } 1861 | ] 1862 | }, 1863 | { 1864 | "cell_type": "markdown", 1865 | "metadata": { 1866 | "id": "F8rax_dDgnFI" 1867 | }, 1868 | "source": [ 1869 | "##### Variable Global" 1870 | ] 1871 | }, 1872 | { 1873 | "cell_type": "code", 1874 | "metadata": { 1875 | "id": "7330M1h4gpnQ" 1876 | }, 1877 | "source": [ 1878 | "# Variable Global\n", 1879 | "def my_function():\n", 1880 | " global variable\n", 1881 | " variable=15" 1882 | ], 1883 | "execution_count": 18, 1884 | "outputs": [] 1885 | }, 1886 | { 1887 | "cell_type": "code", 1888 | "metadata": { 1889 | "id": "LgzzqLCDgp-M" 1890 | }, 1891 | "source": [ 1892 | "# Ejecutar la función e imprimir el valor de la variable global\n", 1893 | "my_function()" 1894 | ], 1895 | "execution_count": 19, 1896 | "outputs": [] 1897 | }, 1898 | { 1899 | "cell_type": "code", 1900 | "metadata": { 1901 | "colab": { 1902 | "base_uri": "https://localhost:8080/" 1903 | }, 1904 | "id": "KFEQ7BB-2m5g", 1905 | "outputId": "20f93ce8-b84d-4272-fff6-c66eb322f61c" 1906 | }, 1907 | "source": [ 1908 | "print(variable)" 1909 | ], 1910 | "execution_count": 20, 1911 | "outputs": [ 1912 | { 1913 | "output_type": "stream", 1914 | "name": "stdout", 1915 | "text": [ 1916 | "15\n" 1917 | ] 1918 | } 1919 | ] 1920 | }, 1921 | { 1922 | "cell_type": "markdown", 1923 | "metadata": { 1924 | "id": "4NWfx4mRhpgX" 1925 | }, 1926 | "source": [ 1927 | "##### Lambda" 1928 | ] 1929 | }, 1930 | { 1931 | "cell_type": "code", 1932 | "metadata": { 1933 | "id": "mhxlEyFthuQa" 1934 | }, 1935 | "source": [ 1936 | "# Crear un objeto lambda\n", 1937 | "f = lambda x: x**2" 1938 | ], 1939 | "execution_count": 21, 1940 | "outputs": [] 1941 | }, 1942 | { 1943 | "cell_type": "code", 1944 | "metadata": { 1945 | "id": "NFQxwMIWh-B_", 1946 | "colab": { 1947 | "base_uri": "https://localhost:8080/" 1948 | }, 1949 | "outputId": "d420dfad-4246-4264-990b-bf0e93ed30da" 1950 | }, 1951 | "source": [ 1952 | "# Crear una lista para aplicar una función lambda\n", 1953 | "lis = [1,2,3,4,5,6,7,8]\n", 1954 | "\n", 1955 | "# Usar la función map para aplicar la función lambda a una lista\n", 1956 | "generator = map(f,lis)\n", 1957 | "generator" 1958 | ], 1959 | "execution_count": 23, 1960 | "outputs": [ 1961 | { 1962 | "output_type": "execute_result", 1963 | "data": { 1964 | "text/plain": [ 1965 | "" 1966 | ] 1967 | }, 1968 | "metadata": {}, 1969 | "execution_count": 23 1970 | } 1971 | ] 1972 | }, 1973 | { 1974 | "cell_type": "code", 1975 | "metadata": { 1976 | "id": "_AX5enMai7O-", 1977 | "colab": { 1978 | "base_uri": "https://localhost:8080/" 1979 | }, 1980 | "outputId": "47555d4d-c771-4652-c5a2-3f07db4e3ff8" 1981 | }, 1982 | "source": [ 1983 | "# La transformamos en una lista\n", 1984 | "list(generator)" 1985 | ], 1986 | "execution_count": 24, 1987 | "outputs": [ 1988 | { 1989 | "output_type": "execute_result", 1990 | "data": { 1991 | "text/plain": [ 1992 | "[1, 4, 9, 16, 25, 36, 49, 64]" 1993 | ] 1994 | }, 1995 | "metadata": {}, 1996 | "execution_count": 24 1997 | } 1998 | ] 1999 | }, 2000 | { 2001 | "cell_type": "code", 2002 | "metadata": { 2003 | "id": "bWRIV_RZ4cBs" 2004 | }, 2005 | "source": [ 2006 | "" 2007 | ], 2008 | "execution_count": null, 2009 | "outputs": [] 2010 | } 2011 | ] 2012 | } -------------------------------------------------------------------------------- /ES_ML_Capítulo_03_Importar_los_datos.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "collapsed_sections": [], 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "id": "cCV0K8_frdn3" 33 | }, 34 | "source": [ 35 | "

\"Colaboratory\n", 36 | "\"Colaboratory

\n", 37 | "\n", 38 | " # Importar los datos\n", 39 | "La importación de los datos es lo más importante. En efecto, unos datos erróneos podrían permitirnos tomar decisiones equivocadas sobre las estrategias a utilizar y, por tanto, perder dinero. Vamos a ver la librería de finanzas que nos permitirá importar los precios de yahoo finance con extrema facilidad. Sin embargo, esta facilidad tiene un precio. A veces los datos de yahoo son de mala calidad en algunos activos. \n", 40 | "\n", 41 | "
\n", 42 | "
\n", 43 | "\n", 44 | "\n", 45 | "**Es imprescindible verificar las estrategias de trading creadas utilizando los datos de su broker a posteriori.
\n", 46 | "TODOS LOS NOMBRES DE LOS TELETIPOS SON LOS MISMOS QUE LOS DEL SITIO WEB DE YAHOO FINANCE**\n", 47 | "\n", 48 | "
\n", 49 | "\n", 50 | "### Contenido\n", 51 | "* Librería de Yahoo Finance \n", 52 | "* Algunas otras formas\n", 53 | "\n", 54 | "
\n", 55 | "\n", 56 | "\n", 57 | "\n", 58 | "💰 Únete a la comunidad de [Discord](https://discord.gg/z3dx5XpkX4)\n", 59 | "\n", 60 | "📚 Puedes leer nuestro libro en [Amazon](https://www.amazon.es/Python-para-finanzas-trading-algor%C3%ADtmico-ebook/dp/B0BT4ZS9Q3/)\n", 61 | "\n", 62 | "🖥️ El canal de [YouTube de Quantreo's](https://www.youtube.com/channel/UCp7jckfiEglNf_Gj62VR0pw) (en inglés) y el de [Frogames](https://www.youtube.com/channel/UCMUxXNYrVCv6-bQakhomvBg) en español\n", 63 | "\n", 64 | "\n", 65 | "\n" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "metadata": { 71 | "colab": { 72 | "base_uri": "https://localhost:8080/" 73 | }, 74 | "id": "H-CCSZcHrWe8", 75 | "outputId": "0b4ba877-6e87-48e6-8965-580c66a6db34" 76 | }, 77 | "source": [ 78 | "!pip install yfinance" 79 | ], 80 | "execution_count": 1, 81 | "outputs": [ 82 | { 83 | "output_type": "stream", 84 | "name": "stdout", 85 | "text": [ 86 | "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", 87 | "Collecting yfinance\n", 88 | " Downloading yfinance-0.1.74-py2.py3-none-any.whl (27 kB)\n", 89 | "Requirement already satisfied: numpy>=1.15 in /usr/local/lib/python3.7/dist-packages (from yfinance) (1.21.6)\n", 90 | "Collecting requests>=2.26\n", 91 | " Downloading requests-2.28.1-py3-none-any.whl (62 kB)\n", 92 | "\u001b[K |████████████████████████████████| 62 kB 1.6 MB/s \n", 93 | "\u001b[?25hRequirement already satisfied: pandas>=0.24.0 in /usr/local/lib/python3.7/dist-packages (from yfinance) (1.3.5)\n", 94 | "Requirement already satisfied: multitasking>=0.0.7 in /usr/local/lib/python3.7/dist-packages (from yfinance) (0.0.11)\n", 95 | "Requirement already satisfied: lxml>=4.5.1 in /usr/local/lib/python3.7/dist-packages (from yfinance) (4.9.1)\n", 96 | "Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=0.24.0->yfinance) (2022.2.1)\n", 97 | "Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=0.24.0->yfinance) (2.8.2)\n", 98 | "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas>=0.24.0->yfinance) (1.15.0)\n", 99 | "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.26->yfinance) (1.24.3)\n", 100 | "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.26->yfinance) (2022.6.15)\n", 101 | "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.26->yfinance) (2.10)\n", 102 | "Requirement already satisfied: charset-normalizer<3,>=2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.26->yfinance) (2.1.1)\n", 103 | "Installing collected packages: requests, yfinance\n", 104 | " Attempting uninstall: requests\n", 105 | " Found existing installation: requests 2.23.0\n", 106 | " Uninstalling requests-2.23.0:\n", 107 | " Successfully uninstalled requests-2.23.0\n", 108 | "Successfully installed requests-2.28.1 yfinance-0.1.74\n" 109 | ] 110 | } 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": { 116 | "id": "h-1P69jxrgo0" 117 | }, 118 | "source": [ 119 | "# Sección 1: La librería de Yahoo Finance" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "metadata": { 125 | "id": "A8n9iIQopuBs" 126 | }, 127 | "source": [ 128 | "# Importar la librería yfinance \n", 129 | "import yfinance as yf" 130 | ], 131 | "execution_count": 2, 132 | "outputs": [] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "metadata": { 137 | "id": "R4HxsprkqU0m", 138 | "colab": { 139 | "base_uri": "https://localhost:8080/", 140 | "height": 473 141 | }, 142 | "outputId": "3f689ada-ccc9-47b9-bb24-1487ec05955e" 143 | }, 144 | "source": [ 145 | "# Importar simple de datos\n", 146 | "yf.download(\"GOOG\")" 147 | ], 148 | "execution_count": 3, 149 | "outputs": [ 150 | { 151 | "output_type": "stream", 152 | "name": "stdout", 153 | "text": [ 154 | "\r[*********************100%***********************] 1 of 1 completed\n" 155 | ] 156 | }, 157 | { 158 | "output_type": "execute_result", 159 | "data": { 160 | "text/plain": [ 161 | " Open High Low Close Adj Close \\\n", 162 | "Date \n", 163 | "2004-08-19 2.490664 2.591785 2.390042 2.499133 2.499133 \n", 164 | "2004-08-20 2.515820 2.716817 2.503118 2.697639 2.697639 \n", 165 | "2004-08-23 2.758411 2.826406 2.716070 2.724787 2.724787 \n", 166 | "2004-08-24 2.770615 2.779581 2.579581 2.611960 2.611960 \n", 167 | "2004-08-25 2.614201 2.689918 2.587302 2.640104 2.640104 \n", 168 | "... ... ... ... ... ... \n", 169 | "2022-09-22 99.449997 101.680000 99.410004 100.570000 100.570000 \n", 170 | "2022-09-23 100.059998 100.110001 98.010002 99.169998 99.169998 \n", 171 | "2022-09-26 98.610001 100.440002 98.379997 98.809998 98.809998 \n", 172 | "2022-09-27 99.910004 100.459999 97.339996 98.089996 98.089996 \n", 173 | "2022-09-28 98.019997 101.400002 97.800003 100.739998 100.739998 \n", 174 | "\n", 175 | " Volume \n", 176 | "Date \n", 177 | "2004-08-19 897427216 \n", 178 | "2004-08-20 458857488 \n", 179 | "2004-08-23 366857939 \n", 180 | "2004-08-24 306396159 \n", 181 | "2004-08-25 184645512 \n", 182 | "... ... \n", 183 | "2022-09-22 21272700 \n", 184 | "2022-09-23 25645100 \n", 185 | "2022-09-26 22437900 \n", 186 | "2022-09-27 24225000 \n", 187 | "2022-09-28 24594800 \n", 188 | "\n", 189 | "[4560 rows x 6 columns]" 190 | ], 191 | "text/html": [ 192 | "\n", 193 | "
\n", 194 | "
\n", 195 | "
\n", 196 | "\n", 209 | "\n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | " \n", 242 | " \n", 243 | " \n", 244 | " \n", 245 | " \n", 246 | " \n", 247 | " \n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | " \n", 273 | " \n", 274 | " \n", 275 | " \n", 276 | " \n", 277 | " \n", 278 | " \n", 279 | " \n", 280 | " \n", 281 | " \n", 282 | " \n", 283 | " \n", 284 | " \n", 285 | " \n", 286 | " \n", 287 | " \n", 288 | " \n", 289 | " \n", 290 | " \n", 291 | " \n", 292 | " \n", 293 | " \n", 294 | " \n", 295 | " \n", 296 | " \n", 297 | " \n", 298 | " \n", 299 | " \n", 300 | " \n", 301 | " \n", 302 | " \n", 303 | " \n", 304 | " \n", 305 | " \n", 306 | " \n", 307 | " \n", 308 | " \n", 309 | " \n", 310 | " \n", 311 | " \n", 312 | " \n", 313 | " \n", 314 | " \n", 315 | " \n", 316 | " \n", 317 | " \n", 318 | " \n", 319 | " \n", 320 | " \n", 321 | " \n", 322 | " \n", 323 | " \n", 324 | " \n", 325 | " \n", 326 | " \n", 327 | " \n", 328 | " \n", 329 | " \n", 330 | " \n", 331 | "
OpenHighLowCloseAdj CloseVolume
Date
2004-08-192.4906642.5917852.3900422.4991332.499133897427216
2004-08-202.5158202.7168172.5031182.6976392.697639458857488
2004-08-232.7584112.8264062.7160702.7247872.724787366857939
2004-08-242.7706152.7795812.5795812.6119602.611960306396159
2004-08-252.6142012.6899182.5873022.6401042.640104184645512
.....................
2022-09-2299.449997101.68000099.410004100.570000100.57000021272700
2022-09-23100.059998100.11000198.01000299.16999899.16999825645100
2022-09-2698.610001100.44000298.37999798.80999898.80999822437900
2022-09-2799.910004100.45999997.33999698.08999698.08999624225000
2022-09-2898.019997101.40000297.800003100.739998100.73999824594800
\n", 332 | "

4560 rows × 6 columns

\n", 333 | "
\n", 334 | " \n", 344 | " \n", 345 | " \n", 382 | "\n", 383 | " \n", 407 | "
\n", 408 | "
\n", 409 | " " 410 | ] 411 | }, 412 | "metadata": {}, 413 | "execution_count": 3 414 | } 415 | ] 416 | }, 417 | { 418 | "cell_type": "code", 419 | "metadata": { 420 | "id": "ek5upxGy-Hi2", 421 | "colab": { 422 | "base_uri": "https://localhost:8080/", 423 | "height": 742 424 | }, 425 | "outputId": "61a45795-0b50-44ff-f419-8151c478ccaa" 426 | }, 427 | "source": [ 428 | "# Importación múltiple\n", 429 | "ticker_list = [\"GOOG\", \"EURUSD=X\", \"^GSPC\"]\n", 430 | "yf.download(ticker_list)" 431 | ], 432 | "execution_count": 4, 433 | "outputs": [ 434 | { 435 | "output_type": "stream", 436 | "name": "stdout", 437 | "text": [ 438 | "[*********************100%***********************] 3 of 3 completed\n" 439 | ] 440 | }, 441 | { 442 | "output_type": "execute_result", 443 | "data": { 444 | "text/plain": [ 445 | " Adj Close Close \\\n", 446 | " EURUSD=X GOOG ^GSPC EURUSD=X GOOG \n", 447 | "Date \n", 448 | "1950-01-03 NaN NaN 16.660000 NaN NaN \n", 449 | "1950-01-04 NaN NaN 16.850000 NaN NaN \n", 450 | "1950-01-05 NaN NaN 16.930000 NaN NaN \n", 451 | "1950-01-06 NaN NaN 16.980000 NaN NaN \n", 452 | "1950-01-09 NaN NaN 17.080000 NaN NaN \n", 453 | "... ... ... ... ... ... \n", 454 | "2022-09-23 0.984155 99.169998 3693.229980 0.984155 99.169998 \n", 455 | "2022-09-26 0.968992 98.809998 3655.040039 0.968992 98.809998 \n", 456 | "2022-09-27 0.962371 98.089996 3647.290039 0.962371 98.089996 \n", 457 | "2022-09-28 0.959619 100.739998 3719.040039 0.959619 100.739998 \n", 458 | "2022-09-29 0.969274 NaN NaN 0.969274 NaN \n", 459 | "\n", 460 | " High Low \\\n", 461 | " ^GSPC EURUSD=X GOOG ^GSPC EURUSD=X \n", 462 | "Date \n", 463 | "1950-01-03 16.660000 NaN NaN 16.660000 NaN \n", 464 | "1950-01-04 16.850000 NaN NaN 16.850000 NaN \n", 465 | "1950-01-05 16.930000 NaN NaN 16.930000 NaN \n", 466 | "1950-01-06 16.980000 NaN NaN 16.980000 NaN \n", 467 | "1950-01-09 17.080000 NaN NaN 17.080000 NaN \n", 468 | "... ... ... ... ... ... \n", 469 | "2022-09-23 3693.229980 0.985222 100.110001 3727.139893 0.970393 \n", 470 | "2022-09-26 3655.040039 0.969989 100.440002 3715.669922 0.958231 \n", 471 | "2022-09-27 3647.290039 0.967006 100.459999 3717.530029 0.959453 \n", 472 | "2022-09-28 3719.040039 0.968626 101.400002 3736.739990 0.954016 \n", 473 | "2022-09-29 NaN 0.973899 NaN NaN 0.964041 \n", 474 | "\n", 475 | " Open \\\n", 476 | " GOOG ^GSPC EURUSD=X GOOG ^GSPC \n", 477 | "Date \n", 478 | "1950-01-03 NaN 16.660000 NaN NaN 16.660000 \n", 479 | "1950-01-04 NaN 16.850000 NaN NaN 16.850000 \n", 480 | "1950-01-05 NaN 16.930000 NaN NaN 16.930000 \n", 481 | "1950-01-06 NaN 16.980000 NaN NaN 16.980000 \n", 482 | "1950-01-09 NaN 17.080000 NaN NaN 17.080000 \n", 483 | "... ... ... ... ... ... \n", 484 | "2022-09-23 98.010002 3647.469971 0.984155 100.059998 3727.139893 \n", 485 | "2022-09-26 98.379997 3644.760010 0.968992 98.610001 3682.719971 \n", 486 | "2022-09-27 97.339996 3623.290039 0.962371 99.910004 3686.439941 \n", 487 | "2022-09-28 97.800003 3640.610107 0.959619 98.019997 3651.939941 \n", 488 | "2022-09-29 NaN NaN 0.973710 NaN NaN \n", 489 | "\n", 490 | " Volume \n", 491 | " EURUSD=X GOOG ^GSPC \n", 492 | "Date \n", 493 | "1950-01-03 NaN NaN 1.260000e+06 \n", 494 | "1950-01-04 NaN NaN 1.890000e+06 \n", 495 | "1950-01-05 NaN NaN 2.550000e+06 \n", 496 | "1950-01-06 NaN NaN 2.010000e+06 \n", 497 | "1950-01-09 NaN NaN 2.520000e+06 \n", 498 | "... ... ... ... \n", 499 | "2022-09-23 0.0 25645100.0 5.144270e+09 \n", 500 | "2022-09-26 0.0 22437900.0 4.886140e+09 \n", 501 | "2022-09-27 0.0 24225000.0 4.577740e+09 \n", 502 | "2022-09-28 0.0 24594800.0 0.000000e+00 \n", 503 | "2022-09-29 0.0 NaN NaN \n", 504 | "\n", 505 | "[18478 rows x 18 columns]" 506 | ], 507 | "text/html": [ 508 | "\n", 509 | "
\n", 510 | "
\n", 511 | "
\n", 512 | "\n", 529 | "\n", 530 | " \n", 531 | " \n", 532 | " \n", 533 | " \n", 534 | " \n", 535 | " \n", 536 | " \n", 537 | " \n", 538 | " \n", 539 | " \n", 540 | " \n", 541 | " \n", 542 | " \n", 543 | " \n", 544 | " \n", 545 | " \n", 546 | " \n", 547 | " \n", 548 | " \n", 549 | " \n", 550 | " \n", 551 | " \n", 552 | " \n", 553 | " \n", 554 | " \n", 555 | " \n", 556 | " \n", 557 | " \n", 558 | " \n", 559 | " \n", 560 | " \n", 561 | " \n", 562 | " \n", 563 | " \n", 564 | " \n", 565 | " \n", 566 | " \n", 567 | " \n", 568 | " \n", 569 | " \n", 570 | " \n", 571 | " \n", 572 | " \n", 573 | " \n", 574 | " \n", 575 | " \n", 576 | " \n", 577 | " \n", 578 | " \n", 579 | " \n", 580 | " \n", 581 | " \n", 582 | " \n", 583 | " \n", 584 | " \n", 585 | " \n", 586 | " \n", 587 | " \n", 588 | " \n", 589 | " \n", 590 | " \n", 591 | " \n", 592 | " \n", 593 | " \n", 594 | " \n", 595 | " \n", 596 | " \n", 597 | " \n", 598 | " \n", 599 | " \n", 600 | " \n", 601 | " \n", 602 | " \n", 603 | " \n", 604 | " \n", 605 | " \n", 606 | " \n", 607 | " \n", 608 | " \n", 609 | " \n", 610 | " \n", 611 | " \n", 612 | " \n", 613 | " \n", 614 | " \n", 615 | " \n", 616 | " \n", 617 | " \n", 618 | " \n", 619 | " \n", 620 | " \n", 621 | " \n", 622 | " \n", 623 | " \n", 624 | " \n", 625 | " \n", 626 | " \n", 627 | " \n", 628 | " \n", 629 | " \n", 630 | " \n", 631 | " \n", 632 | " \n", 633 | " \n", 634 | " \n", 635 | " \n", 636 | " \n", 637 | " \n", 638 | " \n", 639 | " \n", 640 | " \n", 641 | " \n", 642 | " \n", 643 | " \n", 644 | " \n", 645 | " \n", 646 | " \n", 647 | " \n", 648 | " \n", 649 | " \n", 650 | " \n", 651 | " \n", 652 | " \n", 653 | " \n", 654 | " \n", 655 | " \n", 656 | " \n", 657 | " \n", 658 | " \n", 659 | " \n", 660 | " \n", 661 | " \n", 662 | " \n", 663 | " \n", 664 | " \n", 665 | " \n", 666 | " \n", 667 | " \n", 668 | " \n", 669 | " \n", 670 | " \n", 671 | " \n", 672 | " \n", 673 | " \n", 674 | " \n", 675 | " \n", 676 | " \n", 677 | " \n", 678 | " \n", 679 | " \n", 680 | " \n", 681 | " \n", 682 | " \n", 683 | " \n", 684 | " \n", 685 | " \n", 686 | " \n", 687 | " \n", 688 | " \n", 689 | " \n", 690 | " \n", 691 | " \n", 692 | " \n", 693 | " \n", 694 | " \n", 695 | " \n", 696 | " \n", 697 | " \n", 698 | " \n", 699 | " \n", 700 | " \n", 701 | " \n", 702 | " \n", 703 | " \n", 704 | " \n", 705 | " \n", 706 | " \n", 707 | " \n", 708 | " \n", 709 | " \n", 710 | " \n", 711 | " \n", 712 | " \n", 713 | " \n", 714 | " \n", 715 | " \n", 716 | " \n", 717 | " \n", 718 | " \n", 719 | " \n", 720 | " \n", 721 | " \n", 722 | " \n", 723 | " \n", 724 | " \n", 725 | " \n", 726 | " \n", 727 | " \n", 728 | " \n", 729 | " \n", 730 | " \n", 731 | " \n", 732 | " \n", 733 | " \n", 734 | " \n", 735 | " \n", 736 | " \n", 737 | " \n", 738 | " \n", 739 | " \n", 740 | " \n", 741 | " \n", 742 | " \n", 743 | " \n", 744 | " \n", 745 | " \n", 746 | " \n", 747 | " \n", 748 | " \n", 749 | " \n", 750 | " \n", 751 | " \n", 752 | " \n", 753 | " \n", 754 | " \n", 755 | " \n", 756 | " \n", 757 | " \n", 758 | " \n", 759 | " \n", 760 | " \n", 761 | " \n", 762 | " \n", 763 | " \n", 764 | " \n", 765 | " \n", 766 | " \n", 767 | " \n", 768 | " \n", 769 | " \n", 770 | " \n", 771 | " \n", 772 | " \n", 773 | " \n", 774 | " \n", 775 | " \n", 776 | " \n", 777 | " \n", 778 | " \n", 779 | " \n", 780 | " \n", 781 | " \n", 782 | " \n", 783 | " \n", 784 | " \n", 785 | " \n", 786 | " \n", 787 | " \n", 788 | " \n", 789 | " \n", 790 | " \n", 791 | " \n", 792 | " \n", 793 | " \n", 794 | " \n", 795 | " \n", 796 | " \n", 797 | " \n", 798 | " \n", 799 | " \n", 800 | " \n", 801 | " \n", 802 | " \n", 803 | " \n", 804 | " \n", 805 | " \n", 806 | " \n", 807 | " \n", 808 | " \n", 809 | " \n", 810 | " \n", 811 | " \n", 812 | " \n", 813 | " \n", 814 | " \n", 815 | " \n", 816 | "
Adj CloseCloseHighLowOpenVolume
EURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPC
Date
1950-01-03NaNNaN16.660000NaNNaN16.660000NaNNaN16.660000NaNNaN16.660000NaNNaN16.660000NaNNaN1.260000e+06
1950-01-04NaNNaN16.850000NaNNaN16.850000NaNNaN16.850000NaNNaN16.850000NaNNaN16.850000NaNNaN1.890000e+06
1950-01-05NaNNaN16.930000NaNNaN16.930000NaNNaN16.930000NaNNaN16.930000NaNNaN16.930000NaNNaN2.550000e+06
1950-01-06NaNNaN16.980000NaNNaN16.980000NaNNaN16.980000NaNNaN16.980000NaNNaN16.980000NaNNaN2.010000e+06
1950-01-09NaNNaN17.080000NaNNaN17.080000NaNNaN17.080000NaNNaN17.080000NaNNaN17.080000NaNNaN2.520000e+06
.........................................................
2022-09-230.98415599.1699983693.2299800.98415599.1699983693.2299800.985222100.1100013727.1398930.97039398.0100023647.4699710.984155100.0599983727.1398930.025645100.05.144270e+09
2022-09-260.96899298.8099983655.0400390.96899298.8099983655.0400390.969989100.4400023715.6699220.95823198.3799973644.7600100.96899298.6100013682.7199710.022437900.04.886140e+09
2022-09-270.96237198.0899963647.2900390.96237198.0899963647.2900390.967006100.4599993717.5300290.95945397.3399963623.2900390.96237199.9100043686.4399410.024225000.04.577740e+09
2022-09-280.959619100.7399983719.0400390.959619100.7399983719.0400390.968626101.4000023736.7399900.95401697.8000033640.6101070.95961998.0199973651.9399410.024594800.00.000000e+00
2022-09-290.969274NaNNaN0.969274NaNNaN0.973899NaNNaN0.964041NaNNaN0.973710NaNNaN0.0NaNNaN
\n", 817 | "

18478 rows × 18 columns

\n", 818 | "
\n", 819 | " \n", 829 | " \n", 830 | " \n", 867 | "\n", 868 | " \n", 892 | "
\n", 893 | "
\n", 894 | " " 895 | ] 896 | }, 897 | "metadata": {}, 898 | "execution_count": 4 899 | } 900 | ] 901 | }, 902 | { 903 | "cell_type": "code", 904 | "metadata": { 905 | "id": "hLx1Plo3qbvZ", 906 | "colab": { 907 | "base_uri": "https://localhost:8080/", 908 | "height": 742 909 | }, 910 | "outputId": "e69229ab-cb5d-4e2a-ce48-9ffebc307e78" 911 | }, 912 | "source": [ 913 | "# Personalizar los rangos de datos\n", 914 | "yf.download(ticker_list, start=\"2000-01-01\", end=\"2010-01-01\")" 915 | ], 916 | "execution_count": 5, 917 | "outputs": [ 918 | { 919 | "output_type": "stream", 920 | "name": "stdout", 921 | "text": [ 922 | "[*********************100%***********************] 3 of 3 completed\n" 923 | ] 924 | }, 925 | { 926 | "output_type": "execute_result", 927 | "data": { 928 | "text/plain": [ 929 | " Adj Close Close \\\n", 930 | " EURUSD=X GOOG ^GSPC EURUSD=X GOOG \n", 931 | "Date \n", 932 | "2000-01-03 NaN NaN 1455.219971 NaN NaN \n", 933 | "2000-01-04 NaN NaN 1399.420044 NaN NaN \n", 934 | "2000-01-05 NaN NaN 1402.109985 NaN NaN \n", 935 | "2000-01-06 NaN NaN 1403.449951 NaN NaN \n", 936 | "2000-01-07 NaN NaN 1441.469971 NaN NaN \n", 937 | "... ... ... ... ... ... \n", 938 | "2009-12-28 1.437505 15.513601 1127.780029 1.437505 15.513601 \n", 939 | "2009-12-29 1.434309 15.427175 1126.199951 1.434309 15.427175 \n", 940 | "2009-12-30 1.434206 15.510114 1126.420044 1.434206 15.510114 \n", 941 | "2009-12-31 1.432706 15.441621 1115.099976 1.432706 15.441621 \n", 942 | "2010-01-01 1.438994 NaN NaN 1.438994 NaN \n", 943 | "\n", 944 | " High Low \\\n", 945 | " ^GSPC EURUSD=X GOOG ^GSPC EURUSD=X \n", 946 | "Date \n", 947 | "2000-01-03 1455.219971 NaN NaN 1478.000000 NaN \n", 948 | "2000-01-04 1399.420044 NaN NaN 1455.219971 NaN \n", 949 | "2000-01-05 1402.109985 NaN NaN 1413.270020 NaN \n", 950 | "2000-01-06 1403.449951 NaN NaN 1411.900024 NaN \n", 951 | "2000-01-07 1441.469971 NaN NaN 1441.469971 NaN \n", 952 | "... ... ... ... ... ... \n", 953 | "2009-12-28 1127.780029 1.441504 15.591310 1130.380005 1.435627 \n", 954 | "2009-12-29 1126.199951 1.445609 15.562667 1130.380005 1.433897 \n", 955 | "2009-12-30 1126.420044 1.436204 15.510114 1126.420044 1.427796 \n", 956 | "2009-12-31 1115.099976 1.443897 15.576615 1127.640015 1.431045 \n", 957 | "2010-01-01 NaN 1.440196 NaN NaN 1.432706 \n", 958 | "\n", 959 | " Open Volume \\\n", 960 | " GOOG ^GSPC EURUSD=X GOOG ^GSPC EURUSD=X \n", 961 | "Date \n", 962 | "2000-01-03 NaN 1438.359985 NaN NaN 1469.250000 NaN \n", 963 | "2000-01-04 NaN 1397.430054 NaN NaN 1455.219971 NaN \n", 964 | "2000-01-05 NaN 1377.680054 NaN NaN 1399.420044 NaN \n", 965 | "2000-01-06 NaN 1392.099976 NaN NaN 1402.109985 NaN \n", 966 | "2000-01-07 NaN 1400.729980 NaN NaN 1403.449951 NaN \n", 967 | "... ... ... ... ... ... ... \n", 968 | "2009-12-28 15.404261 1123.510010 1.437484 15.483464 1127.530029 0.0 \n", 969 | "2009-12-29 15.399529 1126.079956 1.437505 15.560177 1128.550049 0.0 \n", 970 | "2009-12-30 15.392555 1121.939941 1.434803 15.404759 1125.530029 0.0 \n", 971 | "2009-12-31 15.441621 1114.810059 1.434206 15.560426 1126.599976 0.0 \n", 972 | "2010-01-01 NaN NaN 1.432706 NaN NaN 0.0 \n", 973 | "\n", 974 | " \n", 975 | " GOOG ^GSPC \n", 976 | "Date \n", 977 | "2000-01-03 NaN 9.318000e+08 \n", 978 | "2000-01-04 NaN 1.009000e+09 \n", 979 | "2000-01-05 NaN 1.085500e+09 \n", 980 | "2000-01-06 NaN 1.092300e+09 \n", 981 | "2000-01-07 NaN 1.225200e+09 \n", 982 | "... ... ... \n", 983 | "2009-12-28 68170566.0 2.716400e+09 \n", 984 | "2009-12-29 57205620.0 2.491020e+09 \n", 985 | "2009-12-30 58843737.0 2.277300e+09 \n", 986 | "2009-12-31 48974884.0 2.076990e+09 \n", 987 | "2010-01-01 NaN NaN \n", 988 | "\n", 989 | "[2572 rows x 18 columns]" 990 | ], 991 | "text/html": [ 992 | "\n", 993 | "
\n", 994 | "
\n", 995 | "
\n", 996 | "\n", 1013 | "\n", 1014 | " \n", 1015 | " \n", 1016 | " \n", 1017 | " \n", 1018 | " \n", 1019 | " \n", 1020 | " \n", 1021 | " \n", 1022 | " \n", 1023 | " \n", 1024 | " \n", 1025 | " \n", 1026 | " \n", 1027 | " \n", 1028 | " \n", 1029 | " \n", 1030 | " \n", 1031 | " \n", 1032 | " \n", 1033 | " \n", 1034 | " \n", 1035 | " \n", 1036 | " \n", 1037 | " \n", 1038 | " \n", 1039 | " \n", 1040 | " \n", 1041 | " \n", 1042 | " \n", 1043 | " \n", 1044 | " \n", 1045 | " \n", 1046 | " \n", 1047 | " \n", 1048 | " \n", 1049 | " \n", 1050 | " \n", 1051 | " \n", 1052 | " \n", 1053 | " \n", 1054 | " \n", 1055 | " \n", 1056 | " \n", 1057 | " \n", 1058 | " \n", 1059 | " \n", 1060 | " \n", 1061 | " \n", 1062 | " \n", 1063 | " \n", 1064 | " \n", 1065 | " \n", 1066 | " \n", 1067 | " \n", 1068 | " \n", 1069 | " \n", 1070 | " \n", 1071 | " \n", 1072 | " \n", 1073 | " \n", 1074 | " \n", 1075 | " \n", 1076 | " \n", 1077 | " \n", 1078 | " \n", 1079 | " \n", 1080 | " \n", 1081 | " \n", 1082 | " \n", 1083 | " \n", 1084 | " \n", 1085 | " \n", 1086 | " \n", 1087 | " \n", 1088 | " \n", 1089 | " \n", 1090 | " \n", 1091 | " \n", 1092 | " \n", 1093 | " \n", 1094 | " \n", 1095 | " \n", 1096 | " \n", 1097 | " \n", 1098 | " \n", 1099 | " \n", 1100 | " \n", 1101 | " \n", 1102 | " \n", 1103 | " \n", 1104 | " \n", 1105 | " \n", 1106 | " \n", 1107 | " \n", 1108 | " \n", 1109 | " \n", 1110 | " \n", 1111 | " \n", 1112 | " \n", 1113 | " \n", 1114 | " \n", 1115 | " \n", 1116 | " \n", 1117 | " \n", 1118 | " \n", 1119 | " \n", 1120 | " \n", 1121 | " \n", 1122 | " \n", 1123 | " \n", 1124 | " \n", 1125 | " \n", 1126 | " \n", 1127 | " \n", 1128 | " \n", 1129 | " \n", 1130 | " \n", 1131 | " \n", 1132 | " \n", 1133 | " \n", 1134 | " \n", 1135 | " \n", 1136 | " \n", 1137 | " \n", 1138 | " \n", 1139 | " \n", 1140 | " \n", 1141 | " \n", 1142 | " \n", 1143 | " \n", 1144 | " \n", 1145 | " \n", 1146 | " \n", 1147 | " \n", 1148 | " \n", 1149 | " \n", 1150 | " \n", 1151 | " \n", 1152 | " \n", 1153 | " \n", 1154 | " \n", 1155 | " \n", 1156 | " \n", 1157 | " \n", 1158 | " \n", 1159 | " \n", 1160 | " \n", 1161 | " \n", 1162 | " \n", 1163 | " \n", 1164 | " \n", 1165 | " \n", 1166 | " \n", 1167 | " \n", 1168 | " \n", 1169 | " \n", 1170 | " \n", 1171 | " \n", 1172 | " \n", 1173 | " \n", 1174 | " \n", 1175 | " \n", 1176 | " \n", 1177 | " \n", 1178 | " \n", 1179 | " \n", 1180 | " \n", 1181 | " \n", 1182 | " \n", 1183 | " \n", 1184 | " \n", 1185 | " \n", 1186 | " \n", 1187 | " \n", 1188 | " \n", 1189 | " \n", 1190 | " \n", 1191 | " \n", 1192 | " \n", 1193 | " \n", 1194 | " \n", 1195 | " \n", 1196 | " \n", 1197 | " \n", 1198 | " \n", 1199 | " \n", 1200 | " \n", 1201 | " \n", 1202 | " \n", 1203 | " \n", 1204 | " \n", 1205 | " \n", 1206 | " \n", 1207 | " \n", 1208 | " \n", 1209 | " \n", 1210 | " \n", 1211 | " \n", 1212 | " \n", 1213 | " \n", 1214 | " \n", 1215 | " \n", 1216 | " \n", 1217 | " \n", 1218 | " \n", 1219 | " \n", 1220 | " \n", 1221 | " \n", 1222 | " \n", 1223 | " \n", 1224 | " \n", 1225 | " \n", 1226 | " \n", 1227 | " \n", 1228 | " \n", 1229 | " \n", 1230 | " \n", 1231 | " \n", 1232 | " \n", 1233 | " \n", 1234 | " \n", 1235 | " \n", 1236 | " \n", 1237 | " \n", 1238 | " \n", 1239 | " \n", 1240 | " \n", 1241 | " \n", 1242 | " \n", 1243 | " \n", 1244 | " \n", 1245 | " \n", 1246 | " \n", 1247 | " \n", 1248 | " \n", 1249 | " \n", 1250 | " \n", 1251 | " \n", 1252 | " \n", 1253 | " \n", 1254 | " \n", 1255 | " \n", 1256 | " \n", 1257 | " \n", 1258 | " \n", 1259 | " \n", 1260 | " \n", 1261 | " \n", 1262 | " \n", 1263 | " \n", 1264 | " \n", 1265 | " \n", 1266 | " \n", 1267 | " \n", 1268 | " \n", 1269 | " \n", 1270 | " \n", 1271 | " \n", 1272 | " \n", 1273 | " \n", 1274 | " \n", 1275 | " \n", 1276 | " \n", 1277 | " \n", 1278 | " \n", 1279 | " \n", 1280 | " \n", 1281 | " \n", 1282 | " \n", 1283 | " \n", 1284 | " \n", 1285 | " \n", 1286 | " \n", 1287 | " \n", 1288 | " \n", 1289 | " \n", 1290 | " \n", 1291 | " \n", 1292 | " \n", 1293 | " \n", 1294 | " \n", 1295 | " \n", 1296 | " \n", 1297 | " \n", 1298 | " \n", 1299 | " \n", 1300 | "
Adj CloseCloseHighLowOpenVolume
EURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPC
Date
2000-01-03NaNNaN1455.219971NaNNaN1455.219971NaNNaN1478.000000NaNNaN1438.359985NaNNaN1469.250000NaNNaN9.318000e+08
2000-01-04NaNNaN1399.420044NaNNaN1399.420044NaNNaN1455.219971NaNNaN1397.430054NaNNaN1455.219971NaNNaN1.009000e+09
2000-01-05NaNNaN1402.109985NaNNaN1402.109985NaNNaN1413.270020NaNNaN1377.680054NaNNaN1399.420044NaNNaN1.085500e+09
2000-01-06NaNNaN1403.449951NaNNaN1403.449951NaNNaN1411.900024NaNNaN1392.099976NaNNaN1402.109985NaNNaN1.092300e+09
2000-01-07NaNNaN1441.469971NaNNaN1441.469971NaNNaN1441.469971NaNNaN1400.729980NaNNaN1403.449951NaNNaN1.225200e+09
.........................................................
2009-12-281.43750515.5136011127.7800291.43750515.5136011127.7800291.44150415.5913101130.3800051.43562715.4042611123.5100101.43748415.4834641127.5300290.068170566.02.716400e+09
2009-12-291.43430915.4271751126.1999511.43430915.4271751126.1999511.44560915.5626671130.3800051.43389715.3995291126.0799561.43750515.5601771128.5500490.057205620.02.491020e+09
2009-12-301.43420615.5101141126.4200441.43420615.5101141126.4200441.43620415.5101141126.4200441.42779615.3925551121.9399411.43480315.4047591125.5300290.058843737.02.277300e+09
2009-12-311.43270615.4416211115.0999761.43270615.4416211115.0999761.44389715.5766151127.6400151.43104515.4416211114.8100591.43420615.5604261126.5999760.048974884.02.076990e+09
2010-01-011.438994NaNNaN1.438994NaNNaN1.440196NaNNaN1.432706NaNNaN1.432706NaNNaN0.0NaNNaN
\n", 1301 | "

2572 rows × 18 columns

\n", 1302 | "
\n", 1303 | " \n", 1313 | " \n", 1314 | " \n", 1351 | "\n", 1352 | " \n", 1376 | "
\n", 1377 | "
\n", 1378 | " " 1379 | ] 1380 | }, 1381 | "metadata": {}, 1382 | "execution_count": 5 1383 | } 1384 | ] 1385 | }, 1386 | { 1387 | "cell_type": "code", 1388 | "metadata": { 1389 | "id": "wGUxxLf6qh8d", 1390 | "colab": { 1391 | "base_uri": "https://localhost:8080/", 1392 | "height": 742 1393 | }, 1394 | "outputId": "1a3cafbc-c67f-41dc-a373-7da52fdd83c2" 1395 | }, 1396 | "source": [ 1397 | "# Personalizar el intervalo de datos\n", 1398 | "yf.download(ticker_list, start=\"2000-01-01\", end=\"2010-01-01\", interval=\"1mo\")" 1399 | ], 1400 | "execution_count": 8, 1401 | "outputs": [ 1402 | { 1403 | "output_type": "stream", 1404 | "name": "stdout", 1405 | "text": [ 1406 | "[*********************100%***********************] 3 of 3 completed\n" 1407 | ] 1408 | }, 1409 | { 1410 | "output_type": "execute_result", 1411 | "data": { 1412 | "text/plain": [ 1413 | " Adj Close Close \\\n", 1414 | " EURUSD=X GOOG ^GSPC EURUSD=X GOOG \n", 1415 | "Date \n", 1416 | "2000-01-01 NaN NaN 1394.459961 NaN NaN \n", 1417 | "2000-02-01 NaN NaN 1366.420044 NaN NaN \n", 1418 | "2000-03-01 NaN NaN 1498.579956 NaN NaN \n", 1419 | "2000-04-01 NaN NaN 1452.430054 NaN NaN \n", 1420 | "2000-05-01 NaN NaN 1420.599976 NaN NaN \n", 1421 | "... ... ... ... ... ... \n", 1422 | "2009-09-01 1.465502 12.349959 1057.079956 1.465502 12.349959 \n", 1423 | "2009-10-01 1.473297 13.352950 1036.189941 1.473297 13.352950 \n", 1424 | "2009-11-01 1.503895 14.520573 1095.630005 1.503895 14.520573 \n", 1425 | "2009-12-01 1.432706 15.441621 1115.099976 1.432706 15.441621 \n", 1426 | "2010-01-01 1.387694 NaN NaN 1.387694 NaN \n", 1427 | "\n", 1428 | " High Low \\\n", 1429 | " ^GSPC EURUSD=X GOOG ^GSPC EURUSD=X \n", 1430 | "Date \n", 1431 | "2000-01-01 1394.459961 NaN NaN 1478.000000 NaN \n", 1432 | "2000-02-01 1366.420044 NaN NaN 1444.550049 NaN \n", 1433 | "2000-03-01 1498.579956 NaN NaN 1552.869995 NaN \n", 1434 | "2000-04-01 1452.430054 NaN NaN 1527.189941 NaN \n", 1435 | "2000-05-01 1420.599976 NaN NaN 1481.510010 NaN \n", 1436 | "... ... ... ... ... ... \n", 1437 | "2009-09-01 1057.079956 1.483746 12.627668 1080.150024 1.420313 \n", 1438 | "2009-10-01 1036.189941 1.505911 13.988567 1101.359985 1.451379 \n", 1439 | "2009-11-01 1095.630005 1.514532 14.621694 1113.689941 1.462908 \n", 1440 | "2009-12-01 1115.099976 1.513775 15.591310 1130.380005 1.422192 \n", 1441 | "2010-01-01 NaN 1.457705 NaN NaN 1.385406 \n", 1442 | "\n", 1443 | " Open Volume \\\n", 1444 | " GOOG ^GSPC EURUSD=X GOOG ^GSPC EURUSD=X \n", 1445 | "Date \n", 1446 | "2000-01-01 NaN 1350.140015 NaN NaN 1469.250000 NaN \n", 1447 | "2000-02-01 NaN 1325.069946 NaN NaN 1394.459961 NaN \n", 1448 | "2000-03-01 NaN 1346.619995 NaN NaN 1366.420044 NaN \n", 1449 | "2000-04-01 NaN 1339.400024 NaN NaN 1498.579956 NaN \n", 1450 | "2000-05-01 NaN 1361.089966 NaN NaN 1452.430054 NaN \n", 1451 | "... ... ... ... ... ... ... \n", 1452 | "2009-09-01 11.272498 991.969971 1.422030 11.449086 1019.520020 0.0 \n", 1453 | "2009-10-01 12.019946 1019.950012 1.454334 12.278975 1054.910034 0.0 \n", 1454 | "2009-11-01 13.156686 1029.380005 1.473297 13.376860 1036.180054 0.0 \n", 1455 | "2009-12-01 14.425430 1085.890015 1.503443 14.648344 1098.890015 0.0 \n", 1456 | "2010-01-01 NaN NaN 1.432706 NaN NaN 0.0 \n", 1457 | "\n", 1458 | " \n", 1459 | " GOOG ^GSPC \n", 1460 | "Date \n", 1461 | "2000-01-01 NaN 2.149440e+10 \n", 1462 | "2000-02-01 NaN 2.091200e+10 \n", 1463 | "2000-03-01 NaN 2.615620e+10 \n", 1464 | "2000-04-01 NaN 2.010646e+10 \n", 1465 | "2000-05-01 NaN 1.989830e+10 \n", 1466 | "... ... ... \n", 1467 | "2009-09-01 2.050842e+09 1.122955e+11 \n", 1468 | "2009-10-01 3.098551e+09 1.134110e+11 \n", 1469 | "2009-11-01 1.642381e+09 8.498153e+10 \n", 1470 | "2009-12-01 1.711202e+09 8.951533e+10 \n", 1471 | "2010-01-01 NaN NaN \n", 1472 | "\n", 1473 | "[121 rows x 18 columns]" 1474 | ], 1475 | "text/html": [ 1476 | "\n", 1477 | "
\n", 1478 | "
\n", 1479 | "
\n", 1480 | "\n", 1497 | "\n", 1498 | " \n", 1499 | " \n", 1500 | " \n", 1501 | " \n", 1502 | " \n", 1503 | " \n", 1504 | " \n", 1505 | " \n", 1506 | " \n", 1507 | " \n", 1508 | " \n", 1509 | " \n", 1510 | " \n", 1511 | " \n", 1512 | " \n", 1513 | " \n", 1514 | " \n", 1515 | " \n", 1516 | " \n", 1517 | " \n", 1518 | " \n", 1519 | " \n", 1520 | " \n", 1521 | " \n", 1522 | " \n", 1523 | " \n", 1524 | " \n", 1525 | " \n", 1526 | " \n", 1527 | " \n", 1528 | " \n", 1529 | " \n", 1530 | " \n", 1531 | " \n", 1532 | " \n", 1533 | " \n", 1534 | " \n", 1535 | " \n", 1536 | " \n", 1537 | " \n", 1538 | " \n", 1539 | " \n", 1540 | " \n", 1541 | " \n", 1542 | " \n", 1543 | " \n", 1544 | " \n", 1545 | " \n", 1546 | " \n", 1547 | " \n", 1548 | " \n", 1549 | " \n", 1550 | " \n", 1551 | " \n", 1552 | " \n", 1553 | " \n", 1554 | " \n", 1555 | " \n", 1556 | " \n", 1557 | " \n", 1558 | " \n", 1559 | " \n", 1560 | " \n", 1561 | " \n", 1562 | " \n", 1563 | " \n", 1564 | " \n", 1565 | " \n", 1566 | " \n", 1567 | " \n", 1568 | " \n", 1569 | " \n", 1570 | " \n", 1571 | " \n", 1572 | " \n", 1573 | " \n", 1574 | " \n", 1575 | " \n", 1576 | " \n", 1577 | " \n", 1578 | " \n", 1579 | " \n", 1580 | " \n", 1581 | " \n", 1582 | " \n", 1583 | " \n", 1584 | " \n", 1585 | " \n", 1586 | " \n", 1587 | " \n", 1588 | " \n", 1589 | " \n", 1590 | " \n", 1591 | " \n", 1592 | " \n", 1593 | " \n", 1594 | " \n", 1595 | " \n", 1596 | " \n", 1597 | " \n", 1598 | " \n", 1599 | " \n", 1600 | " \n", 1601 | " \n", 1602 | " \n", 1603 | " \n", 1604 | " \n", 1605 | " \n", 1606 | " \n", 1607 | " \n", 1608 | " \n", 1609 | " \n", 1610 | " \n", 1611 | " \n", 1612 | " \n", 1613 | " \n", 1614 | " \n", 1615 | " \n", 1616 | " \n", 1617 | " \n", 1618 | " \n", 1619 | " \n", 1620 | " \n", 1621 | " \n", 1622 | " \n", 1623 | " \n", 1624 | " \n", 1625 | " \n", 1626 | " \n", 1627 | " \n", 1628 | " \n", 1629 | " \n", 1630 | " \n", 1631 | " \n", 1632 | " \n", 1633 | " \n", 1634 | " \n", 1635 | " \n", 1636 | " \n", 1637 | " \n", 1638 | " \n", 1639 | " \n", 1640 | " \n", 1641 | " \n", 1642 | " \n", 1643 | " \n", 1644 | " \n", 1645 | " \n", 1646 | " \n", 1647 | " \n", 1648 | " \n", 1649 | " \n", 1650 | " \n", 1651 | " \n", 1652 | " \n", 1653 | " \n", 1654 | " \n", 1655 | " \n", 1656 | " \n", 1657 | " \n", 1658 | " \n", 1659 | " \n", 1660 | " \n", 1661 | " \n", 1662 | " \n", 1663 | " \n", 1664 | " \n", 1665 | " \n", 1666 | " \n", 1667 | " \n", 1668 | " \n", 1669 | " \n", 1670 | " \n", 1671 | " \n", 1672 | " \n", 1673 | " \n", 1674 | " \n", 1675 | " \n", 1676 | " \n", 1677 | " \n", 1678 | " \n", 1679 | " \n", 1680 | " \n", 1681 | " \n", 1682 | " \n", 1683 | " \n", 1684 | " \n", 1685 | " \n", 1686 | " \n", 1687 | " \n", 1688 | " \n", 1689 | " \n", 1690 | " \n", 1691 | " \n", 1692 | " \n", 1693 | " \n", 1694 | " \n", 1695 | " \n", 1696 | " \n", 1697 | " \n", 1698 | " \n", 1699 | " \n", 1700 | " \n", 1701 | " \n", 1702 | " \n", 1703 | " \n", 1704 | " \n", 1705 | " \n", 1706 | " \n", 1707 | " \n", 1708 | " \n", 1709 | " \n", 1710 | " \n", 1711 | " \n", 1712 | " \n", 1713 | " \n", 1714 | " \n", 1715 | " \n", 1716 | " \n", 1717 | " \n", 1718 | " \n", 1719 | " \n", 1720 | " \n", 1721 | " \n", 1722 | " \n", 1723 | " \n", 1724 | " \n", 1725 | " \n", 1726 | " \n", 1727 | " \n", 1728 | " \n", 1729 | " \n", 1730 | " \n", 1731 | " \n", 1732 | " \n", 1733 | " \n", 1734 | " \n", 1735 | " \n", 1736 | " \n", 1737 | " \n", 1738 | " \n", 1739 | " \n", 1740 | " \n", 1741 | " \n", 1742 | " \n", 1743 | " \n", 1744 | " \n", 1745 | " \n", 1746 | " \n", 1747 | " \n", 1748 | " \n", 1749 | " \n", 1750 | " \n", 1751 | " \n", 1752 | " \n", 1753 | " \n", 1754 | " \n", 1755 | " \n", 1756 | " \n", 1757 | " \n", 1758 | " \n", 1759 | " \n", 1760 | " \n", 1761 | " \n", 1762 | " \n", 1763 | " \n", 1764 | " \n", 1765 | " \n", 1766 | " \n", 1767 | " \n", 1768 | " \n", 1769 | " \n", 1770 | " \n", 1771 | " \n", 1772 | " \n", 1773 | " \n", 1774 | " \n", 1775 | " \n", 1776 | " \n", 1777 | " \n", 1778 | " \n", 1779 | " \n", 1780 | " \n", 1781 | " \n", 1782 | " \n", 1783 | " \n", 1784 | "
Adj CloseCloseHighLowOpenVolume
EURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPCEURUSD=XGOOG^GSPC
Date
2000-01-01NaNNaN1394.459961NaNNaN1394.459961NaNNaN1478.000000NaNNaN1350.140015NaNNaN1469.250000NaNNaN2.149440e+10
2000-02-01NaNNaN1366.420044NaNNaN1366.420044NaNNaN1444.550049NaNNaN1325.069946NaNNaN1394.459961NaNNaN2.091200e+10
2000-03-01NaNNaN1498.579956NaNNaN1498.579956NaNNaN1552.869995NaNNaN1346.619995NaNNaN1366.420044NaNNaN2.615620e+10
2000-04-01NaNNaN1452.430054NaNNaN1452.430054NaNNaN1527.189941NaNNaN1339.400024NaNNaN1498.579956NaNNaN2.010646e+10
2000-05-01NaNNaN1420.599976NaNNaN1420.599976NaNNaN1481.510010NaNNaN1361.089966NaNNaN1452.430054NaNNaN1.989830e+10
.........................................................
2009-09-011.46550212.3499591057.0799561.46550212.3499591057.0799561.48374612.6276681080.1500241.42031311.272498991.9699711.42203011.4490861019.5200200.02.050842e+091.122955e+11
2009-10-011.47329713.3529501036.1899411.47329713.3529501036.1899411.50591113.9885671101.3599851.45137912.0199461019.9500121.45433412.2789751054.9100340.03.098551e+091.134110e+11
2009-11-011.50389514.5205731095.6300051.50389514.5205731095.6300051.51453214.6216941113.6899411.46290813.1566861029.3800051.47329713.3768601036.1800540.01.642381e+098.498153e+10
2009-12-011.43270615.4416211115.0999761.43270615.4416211115.0999761.51377515.5913101130.3800051.42219214.4254301085.8900151.50344314.6483441098.8900150.01.711202e+098.951533e+10
2010-01-011.387694NaNNaN1.387694NaNNaN1.457705NaNNaN1.385406NaNNaN1.432706NaNNaN0.0NaNNaN
\n", 1785 | "

121 rows × 18 columns

\n", 1786 | "
\n", 1787 | " \n", 1797 | " \n", 1798 | " \n", 1835 | "\n", 1836 | " \n", 1860 | "
\n", 1861 | "
\n", 1862 | " " 1863 | ] 1864 | }, 1865 | "metadata": {}, 1866 | "execution_count": 8 1867 | } 1868 | ] 1869 | }, 1870 | { 1871 | "cell_type": "markdown", 1872 | "metadata": { 1873 | "id": "CxtUKbrErCQx" 1874 | }, 1875 | "source": [ 1876 | "# Algunos otros apuntes\n", 1877 | "* **Puntos Fuertes**\n", 1878 | "> * Utilización muy sencilla\n", 1879 | "> * Muy fácil de encontrar el símbolo propuesto yendo al sitio web de Yahoo Finanzas \n", 1880 | "> * Hay muchos datos. Muy útil para crear una cartera \n", 1881 | "\n", 1882 | "* **Puntos Débiles**\n", 1883 | "> * Hay muchos errores en los datos. Por lo tanto, tenemos que utilizar otra fuente de datos para el algoritmo de trading real\n", 1884 | "\n", 1885 | "
\n", 1886 | "\n", 1887 | "Importar directamente desde el brocker (Lo veremos en las siguientes parte)\n", 1888 | "* AlphaVantage\n", 1889 | "* MorningStar" 1890 | ] 1891 | }, 1892 | { 1893 | "cell_type": "code", 1894 | "metadata": { 1895 | "id": "7tftxVo-WJlC" 1896 | }, 1897 | "source": [], 1898 | "execution_count": null, 1899 | "outputs": [] 1900 | } 1901 | ] 1902 | } --------------------------------------------------------------------------------