Functions in Python Programming | Python for Beginners | Quantra Free Course смотреть онлайн
This video is from a free course on https://quantra.quantinsti.com/course/python-trading-basic
In the previous sections, we learnt how to import financial data, create data frames and visualise them. In this section, we will introduce you to the Python ‘Functions’. As the name suggests, a function performs some task. It works on an input, performs the action on it and saves the output.
In more technical terms, a function is a block of organised code which is used to perform a single action, every time it is called within the program. Functions provide for better modularity in coding and high degree of code re-usability.
They make programs less bulky and easy to comprehend. Functions, or as some programmers like to call them, ‘methods’ or ‘routines’ have already been used extensively in the course so far! For example, while manipulating a list we had used ‘pop()’ function to return an item at the given index in the list. If no index is specified, it removes and returns the last element from the list. You may have a look at the output.
Similarly, we have used various other functions like ’pd.read_csv()’ function to load csv data or the plot() and show() function to visualize the data. These are the standard functions supported by the Python library or specific packages. In addition to this, we might be required to create our own functions to perform a specific task repeatedly.
For example, let us create a simple mathematical function. The syntax for constructing a function is: Let us create ‘my_function’. This is a simple function which we have created to calculate the exponential of any number. Now, whenever we need to perform this particular calculation, all we need to do is call this function and insert the values for ‘x’ and ‘n’. But this is a very simple function. Let us get more ambitious and create a proper function which can be used for trading!
For example, for trading we might want to create technical indicators. Ideally, you should first check whether a library of already created technical indicator functions is available and make use of it. For instance, if you want to use Bollinger Bands, there is a library called ‘talib’ which has this function. However, for learning purposes, let us assume you need to create your own function which calculates Bollinger Bands. A word on Bollinger Bands first. They are two bands which are ‘x’ standard deviations away from the simple moving average of say, closing prices of a security. We first find the simple moving average and then plot two standard deviations away from it, above and below the average.
Let us create the code for this in Python that calculates Bollinger Bands on Closing prices. Can you identify the functions which are used within this function? They are rolling.mean() and rolling.std().
As an example, let us plot Bollinger Bands for a ‘Nifty index’ price series. Note, we have to input two parameters here, the dataset which has at least one column called ‘Close’ and ‘n’ which is the window for calculating the moving average and standard deviation. You are already familiar with the matplotlib package and plotting statements. Here are our Bollinger bands for a Nifty index price series. Similarly we can calculate and plot Bollinger bands for any security now.
All we need is to ‘call’ this function and feed appropriate data to it. You may have a look at the code snippet. All we have changed is the data frame as one of the parameters of the function. Here, we will be calculating Bollinger Bands for the Infosys stock.
This is how we can use a function to quickly perform some actions without having to repeat the entire code! In the IPython notebook on functions we will learn to create more such functions on our own!
Stay tuned for some Multiple Choice Questions! Keep Learning.
Quantra is an online education portal that specializes in Algorithmic and Quantitative trading. Quantra offers various bite-sized, self-paced and interactive courses that are perfect for busy professionals, seeking implementable knowledge in this domain.
Find more info on - https://quantra.quantinsti.com/
Like us on Facebook: https://www.facebook.com/goquantra/
Follow us on Twitter: https://twitter.com/GoQuantra
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Functions in Python Programming | Python for Beginners | Quantra Free Course» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.