Then, why exactly the kind of data which we have is unique in some sense and what difficulty it causes and then the kind of tricks or the theory which we use for getting better results and then some little bit of work on some more cutting edge and newer techniques like multiple learning and dig learning. So, essentially the idea is of machine learning is you have a set of, essentially you have a set of vectors, x is a matrix like each row is a vector and then those vectors get mapped to a function. So, essentially what you want to identify is what that function f is from the multiple points which are given to you from the data set. So, if fx is discrete 1, minus 1, 1, 2, 3, 4, then it's a classification problem between your specification problem and so on. So, for financial stuff, the problem is as simple as I am trying to predict how many of you know what nifty is. So, basically it's an index which is traded in Indian market. So, the problem could be as simple as I want to predict what's going to happen to nifty index from today to tomorrow. So, it's as simple as that. So, whether it is going to go up or whether it is going to go down and you know I mean like this problem if it can be solved with a reasonable success can make a lot of money obviously because if the market is going to go up, tomorrow you can buy it today and then sell it tomorrow at a higher price. It's going to go down then you can sell first and then buy tomorrow. So, it can make a lot of money also. So, essentially you know the thing which we will try to see is related instrument, financial instrument like nifty will go up or down in the next period with what probability that it will go up or down. Is it possible to design algorithms which will be more accurate on larger moves? Obviously you know if the move is larger then you have an opportunity to make more money on that. So, you know I mean can you design an algorithm which actually goes wrong but goes wrong on a smaller move and you know when the move is large it goes more right. How to select X for a given security? So, you have to predict nifty. How do I select the attributes? You know I mean what are the attributes that are important? For example, you know somebody was talking in the morning about like if you want to predict something about the user of a website then you see which website that user has previously visited and on this particular website what that user has searched and so on. So, these are like in machine learning terminology we call it attributes. So, how to select these attributes so that it becomes easy for predicting the you know binary move whether it is going to go up or down. So, that becomes you know so that is where all the domain knowledge this is selecting X is where all the domain knowledge comes into picture. So, everything else is sort of done automatically by the machine learning algorithm. So, your X is a parameter that you use right? Yeah. So, there is lot of thing that happens in financial instrument happens in real time. Yeah. Like if the finance minister says something. Yeah. That is an X. So, depending on what kind of problems you are focusing on that could be an input we are not using that we are not using text mining kind of a word. So, for example you know I mean what financial finance minister says or you know what company CEO says when the things come out. You know there are companies in the world not in India I think but like there are companies in the world who actually do text mining to analyze you know whether the see whatever CEO is saying whether it is a positive thing for future stock price or negative thing for future stock price and you know those can also be used as attributes over there. We are not doing that right now but you know that can be done. Another thing is which we are learning we should choose. You know I mean like here again as I said you know it becomes very important because any small improvement we can get in the predictive accuracy goes a very very long way in terms of making what we call a strategy of prediction from loss making to profit making and if it is already profit making then it is like profit in business and then you know that can be a brilliant brilliant and call the billions of dollars at me. So and like you know for learning algorithm how do we at least check whether it would have worked historically. So essentially you know I mean like financial markets have a history of let's say five or ten years like you know the relevant history or what would you would like to do is you know you would like to design an algorithm and then at least test whether it would have worked historically we had applied it at that particular time and you know I mean like if it would have worked historically then there is some chance not directly and it will work in future also but if it if it didn't even work historically then there is no chance that it will sort of work in future. So I just wanted to show this graph in terms of you know what we are trying to predict. So essentially you know so see these are the daily movements of nifty so nifty index and you can see how what I mean. Essentially what we are trying to each of this thing is actually a day and on that day we are trying to predict whether it is going to work or whether it is going to go down. So it just keeps like you know it looks like a random noise so you know I mean and that is what it makes it's so difficult to you know predict like what's going to happen. Also usually the financial instrument data, credit financial instrument data is what we call e-condition. What do I mean by e-condition? If you actually you know take all these returns. So return is simple basically tomorrow's price or today's price minus yesterday's price divided by yesterday's price that is a percentage difference. So if you take an average of that it is like you know over this 4 period it is 6.7 e raised to minus 4 but if you take a standard deviation of this data then it is 0.016. So if you take a ratio of standard deviation to mean that is 23. So because of this what happens is there are every day the index is moving a large amount but you know over a period of time because on a given day you may move positives or negative over a period of time actually most of the movements cancel out and then you know you get only like you know 12 or 13% for annum kind of return like over a long period of time. So for example you know I mean this is 1.6% so a daily move of nifty can be about 1.2% and you can imagine there are 250 trading days in a year so if you could capture every day's moves correctly then you would be making 1.3 multiplied by 250% return in one year. So nobody makes that kind of return right? I mean that is like 4-500% return only on one single instrument and because nobody can get it accurate 100% nobody can make that kind of return. And nobody can get accuracy to that level because of this move. Since the average is the signal is very very small and the noise is very very large. In 2006 you know what that means it is basically the fourth movement of the probability distribution that is very large. If you have a Gaussian distribution which all of us know this process should be 3 and this is where so that means there are many many very large moves. Also if you have about 6 sigma events and stuff like that then 6 sigma event is basically 3 and then 3 times more likely to have a 6 sigma event as compared to you know Gaussian distribution. So all these things are included in non-stationarity. Basically if you see there are small moves over here there are large moves over here because of that the distribution from which these moves are coming from also changes over a period of time. Any questions? So x axis is just space. So basically this is January 2003 I think. So that is January 1st January 2003 and this is like you know three days back when I actually created this presentation. Another thing is you know I mean like one of so this is what we call is the time series right. So one of the ways of analyzing whether there is a predictability in time series is what we call auto correlation. So if you actually do auto correlation of these returns then you will see that there is no auto correlation. So basically what happened yesterday is of hardly any you know I mean like information to decide what is going to happen today. And this is why you know most of the linear methods will become almost useless as far as you know I mean like especially if you do it as a univariate analysis. So if you just use nifty data of last 5-6 days and try to predict what's going to happen tomorrow that is not going to work very well because you know there is no auto correlation. So there is no dependency on what's going to happen tomorrow over last 1, 2, 3, 4, 5, 6 or whatever 20 days. Another thing is what happens is suppose you know by whatever method I want to do. If I am able to build a prediction system which does about 52% accuracy of prediction then because of the transaction cost etc. that actually system either loses money basically I have 100 moves on those I need to be right only in 52 times and then around 48 times so essentially I have a net gain of 4 moves right. So 4 moves multiplied by 1.1% on an average per day which means 4.5%. So 4.5% over 100 days is approximately the transaction cost you made up giving in reading this particular instrument and that essentially is breaking even the losing slight amount of money. But suppose you could build a system which is only 56% accuracy which means only 4% more accurate time you know the break-in system then this actually makes a phenomenal amount of profit. Why a phenomenal amount of profit? 56 minus 44 is 12. 12 multiplied by 1.1 is about 13. So basically 13% return for every 100 days. So in a year there are 450 days so basically in a year you would be able to make approximately 30% return on analyzing. So which is I mean anybody would love to have investment which actually generates 30% return year on year right. So the reason I am showing you these numbers is because you know it is we are playing so close to randomness essentially our system completely you know random would be 50% accurate and system which is you know slightly more predictable is 56% accurate and a system which is as close to randomness is able to make money. So it is very hard to actually differentiate multiple systems which are random from each other which is actually a real prediction and which actually is a random system and that is my next slide. So here what I did is I took that data of 50 and I randomly generated plus 1 and minus 1 for those 2,000 plus points 100 times. So basically I had these 100s quote unquote systems which were random systems and I chose the one which had the best accuracy out of that. So these are like you know there is more intelligence over here I am just creating a random signal of that thing and choosing the one which gives me the most accuracy so that is the blue line. So you can see you know it looks as if you are going to make money using that particular system but it is a randomly generated signal so you know it has made money in sample but obviously it is not going to work if you start using it out of sample. So that essentially is a big problem right because you could do so called machine learning and you could do all kinds of trading and technical indicators and this and that and you could maybe do it many many times you have a certain amount of data and you say that okay I mean if somebody any of you guys trade then you know you use moving average or something like that and you know you change 6 weeks moving average 4 weeks moving average you change it around and see which one gives you the better accuracy. So you can think of this if there was no predictability in financial markets and if you were doing this many many times so let's say you generate these 100 random systems just by this logic you are actually going to get one case which is going to give you a profitable system in sample but when you put it into the market it's not actually going to make money for you. Any questions on this? So okay so if this was much higher so basically this is the first line so let's say if it was at 0.4 that means what's going to happen tomorrow is positively automatically what happened yesterday so if yesterday's return was positive then it's going to happen that tomorrow's return is also going to be positive if it was below then it means it's going to be negative why is the strength by which you know the adjacent moves are correlated with each particular one? same about the 100 moves every time you are making the same amount of money you are making the 100 times sorry you are saying 100 means right? 100 means you are saying the same 6% is accurate so you are saying 100 times? no so what I am saying is if you have 100 moves the average size of each move is 1.1% average so some of them are much smaller but the average size is 1.1% so on an average if you were going wrong uniformly independent of the size of the move then what would happen is 56% accuracy system would actually end up giving you what we call edge of 56-44 which is 12% so basically for every 100 moves we are doing 12 moves better than you know I mean like basically there are next 12 moves which we are going to make money basically 44 moves are going to be positive by random chance 44 moves are going to be negative by random chance and 12 moves essentially we are going to be able to predict and so this 12 multiplied by 1.1 becomes approximately 13% so for 100 moves which is 100 days which is approximately half a year in half a year you actually are able to make 13% so just yeah in 100 moves you were saying about because I am like saying investing in one leg for 2 minutes so 100 moves should be equal right and you are calculating that to a 13% so every day I need to invest one leg so then I get yeah I mean there are different ways of investing actually we are not talking about investing right now but what you could do is you could invest 1 lakh rupees or 1 rupee every day and then in 100 days what you could end up doing is if you are investing 1 rupee then you would make 13% so that is all so the classification from the only classification is the direction of the 100 but doesn't classify the magnitude so if you have the top moves which are smaller in magnitude and the top moves are relatively larger in magnitude then you would have different results that is not I mean like see basically we are not actually talking about whether the move is up or move is down whether we are more accurate on what kind of moves because we can make money from up moves also and we can make money on down moves also so essentially you know as long as your accuracy is same for both kinds of moves you would on an average rate of making the same let me give this question which is the most if you consider the cases 36% you are accurately able to predict you know the direction which is what you are predicting not the magnitude not the magnitude because direction prediction is hard enough so magnitude prediction becomes even more difficult but there can be a regression type of models where you know you are trying to predict magnitude and then do investment based on that also but right now we are mainly focusing on direction prediction but we try to take care of magnitude in some other way so efficient markets are mostly like that mostly in academia nobody believes that otherwise this whole financial industry of real world dollars would not exist so that is mostly for academic reasons and that has been put there because you know I mean it makes you know it makes you know it makes you know it makes you know it makes you know it makes you know it makes because you know I mean it makes proving certain theorems easy and actually efficient markets mostly are used in a way that efficient market is an equilibrium state so that actually gives you a way of measuring whether the current condition of the market is actually much away from the equilibrium so you know it actually works as actually a trade generation mechanism because you know you are not you are not in the equilibrium state so you will be able to actually you know measure how far you are from the equilibrium state and then take a trade on it so it is probably a little complicated but you can talk offline later the absence of auto correlation does it imply that you cannot keep the stock distribution much longer? absence of auto correlation implies that we cannot use linear univariate methods to try and predict this particular security linear univariate so basically I mean you know I mean I could have a variable which is not dependent on itself at all but it is dependent on something else which I have access to so that is a multilateral problem but I can't use the same graph so I can't use you know last 4 days of nifty data and expect that and I will be able to predict I am sorry I can't use this for univariate univariate means if I am looking at only behavior of nifty then I don't have a chance of predicting nifty in theory by using linear methods nonlinear method there could be I mean because auto correlation only works for linear modeling methodologies so it's just a normal pseudo random number generator like you are trying to predict how it is so that is the nifty data is not normal I am only see basically I am randomly generating whether it is plus one or minus one so whether I want to go long today whether I want to buy the security today or whether I want to sell the security today so the random number generator normal random number generation which I am using actually has more relevance in this particular case because I am only doing the signals I am taking the sign of the random number that actually so that's what I am saying my simulation process and my historical data are not really connected so I mean we can maybe talk about this often later yeah so that I mean like that probably a little bit ahead you will get to see what kind of stuff which we are trying to do that doesn't mean that that's the only thing one can do okay so exactly to answer your so as I said you know I mean like the auto correlation essentially shows that you know you can't use historical data of 50 returns to try and predict what's going to happen tomorrow but it may be possible that you know I can predict what's going to happen to Nifty by using what's happening right now in US markets or in Asian markets right now or in European markets right now so one can actually use all these data together and then create that attribute matrix X and then try and see if there is any predictability in that so for example you know I mean like theoretically not theoretically but practically speaking if any of you are trading then you know that what happens in US market yesterday becomes very very important to what's going to happen to Indian markets today so just I mean like one things that that should be the case so you can use that particular fact in your data that you say okay I am going to use what happened in US markets yesterday as one of my attributes to try and predict what's going to happen to Nifty from today to tomorrow similarly you can do it let's say you know what is happening to gold is very important to you know what's going to happen to security markets because you know usually they happen opposite relationship whenever there is a danger that economy is going to fall into inflation or something like that gold is going to go up and then you know equity markets are going to go down there is an opposite relationship so let's use the gold what's happening to gold right now and then use you know some kind of machine building algorithm to actually understand what you know how that effect actually gets modulated another thing is you know as compared to you know most other problems one difference that we have is we have a time series data so essentially you know it's not like you know one instance of a user is completely independent of another instance of another user actually you know there is a time chronology which happens basically you know you highly should not be using you know what behavior market has in 2005 to analyze what behavior market would have had in 2003 because you know trying to predict what's happening in 2003 you know you did not have access to what is happening in 2005 so you know you should not be using that so that is what we end up doing it's called walk forward what we have done over here is we have arranged the data so this is each of this line is the row of X and this plus or minus is whether on that particular day market went up or down so that is 2003 and this is yesterday essentially so what we do is this so it takes a back testing process so we take some amount of data say 2 years of data you know then use that data build some models so let's say you know something simple like logistic regression or support vector machine or whatever you want to do build that model using that data then predict for today so no historically maybe you were right using your model or you were wrong you just keep track of that and then move your window forward by one point repeat the process and then what these signs are these are what actual movements where is what characterizes your back testing program so historically if we had applied this strategy then how it would have worked and whether it would have made money for us in the market or not and if you see each of these prediction is completely out of sample so you know so there is some hope that whatever we are doing over here actually has some hope of working in future so this is probably going to give to sleep I will not talk about it too much but you know I mean just to just as a preamble to my next slide essentially you know I mean like in machine learning this bias where I am straight up actually is something very very important I mean most of us actually don't pay attention to that because you know usually from prediction perspective most of the real world problems are fairly simple so whether you use linear models on that or you know whether you use nonlinear models on that doesn't really matter but since we are working here very close to randomness it becomes very important so what happens if you use something some very simple model like a linear regression model and then whatever comes out of that you take a sign of that so if you use that kind of a model then what we call is that model is extremely biased so there is no hope that whatever is the relationship among the variables which we are using to predict that actually will be sharply captured by a linear model because we know that the world is not linear now if you actually make the model extremely nonlinear then what happens is like there is a hope that the actual function which you are trying to approximate is part of this whole nonlinear class of the models which we are using but what happens is this set becomes very big and then it becomes very difficult to actually pinpoint which model you are trying to so this is a bias and this is a variance so because you have given a certain amount of data and we are trying to identify using that data what that model parameters are essentially this set which is the variance this becomes much much bigger as compared to that and the theory goes that bias plus variance is more or less difficult to manage it is difficult to come up with algorithms which reduce both bias as well as variance so what we try to do some of the things which we try to do to try and say let me try and emphasize over here the motivation is that if we can do something which robustly improves our prediction accuracy by even 1% or 1.5% that is actually a very big deal for us because it ends up increasing our returns by 4% or 5% per year and increasing annualized returns by 4% or 5% per year is actually can be a very large amount of money so what we do is I mean bagging probably you guys have heard about bagging so what bagging is essentially you have the data set you essentially sample some data sets from that use the same methodology and then whatever are the samples you essentially do the averaging of that and then use that as a prediction then multiple learners on those with different underlying theories so let's say you have a support vector machine larger simulation has a simple similar philosophy but then you have random forest or trees or you have a basin approach of things so you have been given a data you apply these various models to it you try and create the same thing out of that because in this scope also randomness sometimes SVM will be correct sometimes logistic regression will be correct sometimes your random forest will be great correct and then when you combine these there is a hope that you know I mean this combined consistency which is an averaging system works actually better in practice then multiple kernel learning I talk I don't know if I'm going to get time but I talk little bit more detail about that then combining unsupervised and supervised learning so essentially your data set may have some clusters so you can actually train your supervised learning model on one of the clusters and you might actually do better on that boosting if you know what it is it is not very useful because financial data is very noisy data and boosting generally doesn't work with noisy data sets in general you know whatever you find in theory generally you will see that things work a little bit worse on financial data because of the amount of noise that the data has also another interesting thing is market learns and trades against you so basically if you are running a successful algorithm for long enough time other players in the market so essentially financial market is trading for you to make money somebody has to boost the money obviously nobody likes to boost the money so they really permanently try and you know learn what you are trying to what you are doing which makes you make money like you know in the long term and then they learn that and they trade against you so basically if they know that you are going to take a long position they may actually before you actually take a long position and take the price of the security up before you actually buy no I have not used it yet but there are people who use it so there are the let's481s components of people use that too so essentially take a line from one of the movies three things are most important averaging, averaging, averaging so actually three things are like really bad also optimization, optimization, optimization so if you actually try and optimize your model a lot it actually works really badly for financial markets in out of central averaging is a really nice process too so as I said combining multiple methods generally you know so I am being very secretive not very but this is secretive over here I am not telling you these are the real research I am not telling you what assets I have applied it on and I am not telling you what methods I am using but still the point I am making over here is you know this is the kind of improvement we look for so like if you see this girl this is the averaging process, the black one and you know I really like this because across the methods it's actually outperforming the individual methods which are part of the averaging process so you know if actually this method performs very well on A6 but it performs badly on A1 generally I don't want to use it for A6 and discard it for A1 because you know I mean these are similar prediction processes and generally I want things which work across the board and this is my way of taking care of the fact that I am not over feeding the data and you know something is going to give me great results in sample but not so great results in out of sample I am sorry it is not in one case but in most of the cases where it is not better I think over here this one is good that is why so whatever Excel I mean I didn't change the numbers so now what I know quote unquote cutting edge method so these we really love right I mean basically because this is the cutting edge machine learning research and our data sets are not very large it's just that we have fairly small data sets like basically you know we may have 20-25 attributes and 2000-5000 you know sample points and from that we want to apply the best possible method which is out there which in a robust way actually guarantees us that our predictions are made so from that perspective you know we are doing what I would say a lot of core machine learning algorithms because our attention is not so much on you know I mean like how to clean the data and you know how to make sure you know some of the other things are like taken care of also another thing I should say we don't really do any fundamental research in our company essentially by cutting edge means you know whatever is just recently published in January 2014 or something like that that we try to implement in our work so I will rush through this because probably if you have heard about support vector machines you probably know about this so essentially you know it's basically a linear separator and then you know you orient the separator in such a way that the margin between the two sets is maximized that is the support vector machine logic it works very well in practice that was only linear if you want to actually solve some non-linear problem then you use coordinate for that so if you have this kind of a data set by the data set to classification generally you can actually transfer your data to some other domain and over there it's actually a linear separator this talks about the more mathematical part of the coordinate range so this kernel function which actually you know uses this is our original data set and then we are using some kind of a non-linear function to transform it into a non-linear space so that it becomes easier to separate the data in that space so there is a lot of theory behind this so essentially what it says is you know there is a theorem called Mercer's theorem which says that every machine semi-positive designate symmetric function is a kernel so essentially you know if you have this matrix if it's a positive symmetric matrix then it actually works as a kernel function on any data set now people use this fact and you know so this is actually the support vector machine so this is where the kernel function comes into picture and I am going through all this because you know I am going to motivate multiple kernel learning which we are trying to do so how to decide what kernel matrix to use there has been a lot of research and since the theory only specifies that K should be positive semi-definite people try to do something called semi-definite learning on semi-definite optimization on this you actually know essentially what you are doing you are trying to maximize you are trying to find the non-linear transformation mapping in such a way that the margin also gets maximized because of that non-linear mapping in addition to the margin of the data set so as you can imagine this is a very big flexibility that is there so what ended up happening is this problem actually overfitted so people could not get good out of sample results out of that and then recently there is something called ASO theory where you try and find a solution which is constrained in some way essentially one of the solution actually is equal to one and then people try to take use from that theory and then try to do the selection of kernel matrix and that is where multiple kernel learning came into picture so going back to our problem essentially what we want to do is let's say we have Nifty we want to do the Nifty prediction let's say we have a self-information attitude let's say last 4-5 days returns volume super interest whatever then there are supporting internet market variables maybe the inflation in the internet market for an exchange rate, USJ and R whatever that ladies now supporting all internet market variables so let's say US market, European market, Asian market so these x1, x2, x3 essentially you can define kernel 1, kernel 2, kernel 3 and then do x1 multiplied by kernel 1 plus x2 multiplied by kernel 1 plus x3 multiplied by kernel 1 and then work under this one arm of x which is x1, x2, x3 is equal to one and then you try and solve the joint optimization problem using that so that's the multiple kernel learning that's the fairly recent work which is out there in which we try to use it again same assets one kernel learning usually we end up using RDF kernel you know what that is and then multiple kernel learning we try to do on that and generally again the goal is to you know on everything you should do slightly later we have not been successful at it yet these are like bit lower than you know the one kernel learning but some improvements are there so we are not going to apply it into practice here because you know it's not consistently working as it is then if you have heard about something about deep learning that's actually a big deal in this race I don't understand that topic very well or essentially from a layman's perspective all I see that normal neural networks have one hidden layer deep learning networks have multiple hidden layers in between and what ends up happening is you know essentially each of these nodes starts becoming specialized for a particular type of sample so essentially Google actually did a big project like a couple of years back where they using this deep learning they identified which images had cats in it so that was actually something which we tried to do a little bit not at all successful at it but it's a race if you actually learn about it start a company you won't have a problem getting it funded somebody will probably in couple of years die for hundreds of million dollars also so somebody from you should try it and the good thing about this is that you know I will like what ends up happening is if you feed enough data to this then each of these nodes become specialized for a particular type of object so for financial data it could be like if you feed enough financial data then this node will become active for a certain kind of behavior of financial data this node will become active for certain other kinds of behavior of financial data and you know because of this I don't actually manually need to decide which attributes to use I can throw a lot of data to this thing and you know I mean hope that you know automatically it's going to understand what kind of combination of different data sets actually make things easier and then use that as a example yeah so people are talking about those correspondence I'm not sure how sort of relevant they are but you know I think Siri uses they claim to use some deep learning in recognizing the voice and stuff like that so so this is actually something you know it would be really good because this has become a real recently because it's almost uniformly breaking all the online competition records of accurate traditions of different problems so usually those records are held by support vector machines mostly and deep learning is actually going a few percentage points ahead of support vector machines and that actually is a very, very big thing so I don't understand about it enough so what happens is like if you put a lot of layers in the neural network it becomes extremely difficult to learn because you know it works on something called gradient descent and those gradients vanish when you actually start computing them because you have multiple layers those start vanishing and because of that it becomes computationally horrendous to keep track of you know all the calculations and then this Hinton is sort of considered as the father of this deep learning kind of a thing so he came up with a couple of you know new innovations which actually made that problem easier then that from that point onwards actually it started becoming a viable solution for different problems the evolution on the same I mean I don't know if there is like a fundamental difference between a simple neural network and a deep network other than you know the kind of algorithms you use to train them and make sure they don't overfit or you know they do the training so little bit about you know I mean I already talked obviously a little bit about you know what we actually do so we have multiple strategies which are running you know in the market and you know we are making money sometimes using money sometimes net net we are making a little bit more than we are using because we are in the market for last 4 years so I guess some money has been made and this is the kind of software we are able to do so this is the real graph actually this is the real money made this is the real behavior and this is how our portfolio has performed so you know I mean so this is our real there are no simulations and randomly generated signals and stuff like that that's it basically we have a small company of like 8 people and that is what we do day in and day out I mean just try and apply machine learning to financial prediction problems yeah sorry I didn't know what it is right? there are actually some of those A1 to A6 where come on what it is as you say this happening to other companies as well like you and you need them to see the performance their price will be 8000 if you can have historical data which is reliable and if you could find indicators so for example you know if you could find indicators of like you know how bad the whole prediction is in India so but if you had a reasonable and small prediction there actually it would be very nice to use that to actually do prediction of this now these predictions how you would use these are different story because you know vegetable is a large perishable so you couldn't actually buy it and hold it from experience other than the fact that you know when you're also reading you know non-label of things but that's another story so how you could use these predictions is a different story but the theory doesn't actually you know I mean like you could apply it if you I mean if you know that field well enough and is everything directed to make a difference? no I mean depends on so normally I would say you know I mean now in Nifty we are using about 20 different variables to try and create what's going to happen to Nifty today so you know so that will have some Indian market variables some you know inflation like variables some you know gold prices you know maybe copper prices maybe some global market whatever you can think of which actually you know I mean like so that process right now is manual so that is where domain knowledge comes into picture where you know actually I sit there and think you know I mean like what kind of variables would be relevant for predicting Nifty and you know then try out a few or there also I can't try I mean I can't say that okay these are like 2000 variables I will use 20 at a time and then you know I will put it through a simulation because that will become exactly same as you know doing 100 random simulations and choosing the one which is actually the best out of them so that is what I said you know optimization in this field actually is the worst possible thing you can you can't really do this where you know you are running 100 simulations and choosing the one which actually gives the best results and say that okay this is the one what I am going to include so how long do you think there are a day because like you said that an algorithm in a stock market situation has just like because there will be some others who start trading against that algorithm so how long do you think you like just saw that resistance so what is your strategy for so in theory machine learning should take care of that right because you know machine learning is what learns from the marketing so essentially somebody is trading against you but you are learning the fact that somebody is trading against you so you can incorporate that information in your machine learning your algorithm so for example let me give you a concrete example so let's say your signal is saying that if you buy something today and somebody already identified that you have a system actually which tends to say buy on such days so he comes to market one hour before and buys a lot of that quantity so by the time you buy it the price has already moved up but then if that happens enough times you will understand that somebody is actually doing that to you so now from here you should actually go short so you should sell that security because the price which has moved up they can apply this particular guy or multiple guys from there actually buy it tomorrow actually the price goes down so eventually that can happen so this process will keep on going until you know the market comes to complete equilibrium there is no under price or over price security but that something doesn't happen because there are so many different players with so many different philosophies and so many different horizons of you know there will be great people out there I mean I think still majority of them are human beings so that is where one tends to make money I mean it's not possible to make money and training against the machines here given that I am explaining there are no specific laws inside that rating there are no laws there is a lot of so there is a lot of the price of that how much they love you so it's very hard to actually do a general which actually will do better than inside of this but generally what we have observed is when we try to apply this kind of algorithm to use your stocks it was very difficult for us to make money because what happens if there are public investors who actually know the CEO of that company and they get the information so they move the stocks so it's very hard to put money on that but whenever we do this widespread security or something like that there it works because they are generally people who actually know the inside information but in reality it's very hard to do a general so that's why I am using that so so so so so so so so so so So this is actually up to now for us it has been mainly based on human intelligence deciding which attributes to use but that also process can be to an extent you know I mean like one can use statistical correlations and mathematical correlations for that or instead of auto correlations or you know I mean cross correlations one could use something like usual information which is more robust to know the effects of PCA PCA is something where you know you have a lot of variables and only some variables of course you think are important so you know so you do PCA and then you know it's a 20 dimensional system 20 dimensional PCA and then you see that only 10 of them actually explain the most of the variance and last 10 actually don't make any difference at all so and then you reject those Generally what we have seen is PCA doesn't work too well because the low information is what actually ends up making the statistical predictor So generally we have seen in our work at least that PCA has not worked too well Okay, thank you


Alright, next speaker is Zuck, he's going to be talking. So let's please give him a big DevCon welcome. Come on. Thank you. Hello and welcome to my talk on arm exploitation techniques. Thank you, crowd. I love you. Hello and welcome to my talk on arm exploitation technique. Thank you again. Can you hear me? You're in the back. Alright, we got it. Hello and welcome to my talk on arm exploitation technique. I actually said it three times now. In this talk I'll cover exploitation technique on both arm and x86 architecture from scratch actually. So if you've never done it before, it's the time to start actually. This is my first DevCon ever. So I'm really excited to be here with you. I'm really happy to attend this great conversation, this great event. Well, I had a buddy who had to go yesterday. He couldn't stay today. So I promised him I'll take a photo of you while you scream DevCon. So if you can do that for me, that would be awesome. Like five, four, three, two, one. Yeah. I'm going to pass it on that blog right there. So you can see yourself. I'm Isaac Avram. My nickname is Zook. You can call me Zook if you love me. I work for Samsung. I'm a researcher there. I do some neat research for them. I really like it. I'm also a partner at PIA. PIA is a pre-incident assessment. Just penetration testing, reverse engineering, custom stuff like that. You can follow me on Twitter under that account. It's actually a sticker name I borrowed the name from. That's the blog. The full presentation and the paper which will have like more technical details will be there. The updated one, not the one in the city. It's quite not updated. It doesn't got any Android info. So the updated one is going to be there in a few hours. For any request, talks, whatever Dirty offers, that's my email. Feel free. Well, like I said, the presentation is not enough. You need, if you really want, like, it's nice to know exploitation techniques and stuff. If you want like real more technical details, you can see the paper. It's on the city, but it's also will be in the website, the updated one. It'll be there in that website. All right. So that's what's going to be actually in this stock. We're going to start from the very beginning. And someone just told me to speak louder so everybody can hear me right there. All right, cool. Like, what's the calling convention? Why ARM exploitation is different from x86? What we need to adjust in order to make our exploit work from x86 on ARM? Some logic is different. Some logic is different.  All right, let's do it. So that's the best skills I can get in PowerPoint because, all right, if you don't like it, just leave it because I can get any better in PowerPoint. Anyway, why would someone want to hack a mobile phone or a ARM device or whatever? Let's stay on mobile phones. There's various reasons you want to do that. One of them is just, it's just like a regular computer these days. You can use it for botnets. You can make calls, send SMSes. That's someone who wants to attack from remote. You can just charge them. You can do whatever you want. It's a computer that can make calls. So that's it. Also, applications are very common these days. So if you download a malicious application for, let's say, a weather, some checks weather, and it actually wants to use your Bluetooth or send emails from you and stuff like that. And also, it only requests, in the manifest, just permissions for the, I don't know, nothing. And then he exploits some system APIs to privilege escalation and just use the Bluetooth model or your internet or your calls. Someone can steal your calls. And there's also the user itself that would want to hack a mobile phone. You would want to do that to reveal some stuff that the mobile operator didn't allow him to do. You can see that in iPhones. A lot of people do that. All right. So after the very beginning, we'll cover the status of Buffalo Flows on x86. These days, you can see on x86 many defenses from Buffalo Flows. It's really hard actually to exploit these days on x86 architecture. The stack and heap is not executable. You got stack cookies. ASLR is very, very, most of the places are randomized very good. It's really hard to bypass, especially if you've got all of the vectors. On ARM, it's quite different. The architecture is different. So you have to adjust stuff. It's not fully working. Also, the stack and heap, they're not executable on most devices these days. But you can see ASLR. Most of the time, there is a PAX patch for a Linux platform a few months ago. So now you can see ASLR being implemented, but it's not mainline yet. So let's cover x86 or Tulip C attack. I'm just beginning from scratch. If you want to exploit stack overflow on ARM architecture, on x86 architecture, it will be something like that. It's very easy to... Can you see my mouse monitor? All right. It's very easy to exploit. You just put the buffer here. Let's say you want to slash pin slash SH to execute. It's just very easy. You put the buffer here. You override the EBP. It doesn't really matter, actually, because it's good for framefaking and more advanced attacks. But in this case, it's not. You just override the EAP with the system function address. You can also put return address and just push parameter on the stack. So you put your parameter in the payload like that. It's very easy. I think x86 was meant to be hacked. I mean, look at that. You can push parameters through the stack in the same payload. I think someone up there wanted us to hack the x86 to make it easier somehow. All right. So for the demo, like I said, we would want to use the system functions. Just execute our command and we want to execute slash pin slash SH. All right. It will not work on ARM like that. It wasn't meant to be hacker-friendly like x86. I think that's my opinion. So, yeah, you know, just don't. Also, why wouldn't it work on ARM? Because if it worked, we wouldn't have this presentation right here. And it has different calling conventions. And it works differently because ARM assembly works differently. And we just want to cover that. So we're going to the technical part. Actually, when I edited this presentation yesterday, I wanted to add this girl. I wanted to do a break before the technical details. Just put girls with tits or something. So you can have a break before I'm going to technical details. But I decided to remove it because there are some girls in the crowd. So that's, I'll get killed or something. All right. So this is the basics of ARM assembly. That's what actually you need to know for this presentation. You can also always become better, that one. The ARM assembly is unlike x86 assembly. In x86, if you want to push parameter, you can do it through the stack. In ARM, you just need to put it through the registers. So let's say if I wanted to put slash b in s h to push it somehow, I would need to put it on r zero. And I can do it through the payload like that. So that's less sucker friendly. Also, the registers can be edited. Like PC is similar to EIP. It's the instruction pointer. And you can actually move address to PC and will be the next instruction. What you also need to know is, well, r zero to r three are the most important registers. The rest, r 13 is the stack pointer and l r link register is r 14. r 15 is like I said, the EIP of ARM, it's PC. So let's start it exploiting. All right. So the libc overrides the return address and pass parameters to a vulnerable function. But we can't pass parameters on the vulnerable function because we need to store it on the r zero register, for instance, in this one. So we're quite screwed. And we can only override existing variables from local function. So it usually depends on which function you're as the vulnerability in it. All right. And we can also override the PC, the program counter. So that's what we'll use in order to get full control of the application. So there's no really ready to libc attack on ARM. We'll have to make some adjustments. So, all right. Why is it actually passable? So when entering a vulnerable function, the pushed parameter, it's usually it's not all cases, but it's most of them. The r 14 is being popped into the PC at the end of the function. So if you can override the r 14 at the end of the function, it will be being popped to the PC, the r 15. So you get control of the code. If you can control it, we can own it, actually. So let's do it like a POC in a program that is very hacker friendly. All right. It gets the PC. Right. It gets the buffer here. And the stack pointer is pointing to the beginning of our buffer. It's very convenient. Our zero is pointing to the beginning of the buffer. Also very convenient. So let's just put a command here. And after we override the PC, just we'll put there the system address of the function. So we'll see PS is being... I'm actually on my screen. All right. It's mirrored. You can see PS function is being executed. But that's a lie because that's very convenient hacking friendly program that I made especially for that. So that's not a real life scenario. Anyway, that's the POC that it can work. Okay. Let's face it. It's not real life scenario. In order to have that scenario, we need a function that returns void that after the overflow nothing happens. So our zero will not be deleted. And it should be small. There's another problem with that. The buffer should be small. Like 16 bytes in order to have a free space of the system function not using the same stack pointer space. So it will not override each other. So there is actually almost no chance in the world for that to happen. And if it happened to you, you're very lucky. It's like ringing the jackpot in Wheel of Fortune outside. So, yeah, you don't want that scenario. All right. So what do we need actually for successful exploitation? We need several stuff. So let's do it. We need parameter adjustments and variable adjustments. Parameter adjustments will be just register adjustments. R0 to R3. We must modify that in order to continue exploiting and do whatever we want. We also would like to get back the control to PC. So after we execute some command, we won't still control the flow of the buffer. And we also might want to do a stack lifting because, like I said, you don't have to count on that the buffer to be 16 bytes or if it's a longer buffer you're screwed. You don't want to do that. In the 16 bytes you just get four bytes of buffer that you can execute. And that's not enough unless it's a local attack. So like everybody is just making attacking names. So we just made a new one. Because it's, I don't know, I don't really put a lot of thought of that. But it just makes a lot of stuff. We're trying to program it. We're trying to stack lifting parameter adjustments. And that's it. I mean, it's not really a name, just like a joke. Like everybody in the security community just make up names. So this is for Zook, but don't tell anyone, right? So I won't put my name outside. So how can we control the R0, R1? You're probably fascinated about that. So like amazingly fascinating. R0, yeah. All right. So we need to actually jump into a pop instruction. We'll do return oriented programming. There have been several return oriented programming in Black Hat this year. And I think in DEF CON also. Very interesting. You can put that with this attack and do some more complex attacks. You can do actually whatever you want with that. So we'll need to jump into a pop instruction. Which also pops the PC. Or we can control it later. And we can control the R0 or maybe more, right? So I just looked like a quick regular expression on libc. And you can see like LDM is like pop in Intel. It's similar. I don't want to get into details what's different. But you can see it's popping R0 and R1. So if we jump right here, this address will be able to pop R0 and R1. We'll put any values that we want in there. Also you can see the stack pointer is lifting itself by 12 bytes. So there will be actually R0, R1 and extra 4 bytes. And then you can see pop PC. So we got 4 bytes of junk. So what we want to do after the buffer, we got AAAs. R4, R11, it all depends how it's compiled. And then we'll be jumping, actually it's a mistake here. It's not 4, it's 48. So we'll be jumping here to the LDM instruction. And then we'll pop R0. We'll put it inside the slash bin slash SH address. R1 is not really matter for that one, but it's just 4 bytes. And then we got 4 bytes of junk. It doesn't really matter what you put there. And then we'll call system. So that's the original idea of how you can control the R0 and R1 instructions. But that's only good for local attackers. So let's we can do some more complex return-oriented programming payloads, but let's just keep it that way in the system function. It's very easy. So if we can control R0 to point to a relative path to be in the beginning of our buffer, we can actually put any command. Let's say we want to put like netcat with reverse shell. We can do that if R0 is pointing to the beginning of our buffer. So what we need in this one is actually to have like R0 to point to the relative color to the beginning of the path and then we'll call system. But like I said before, we need the size of the buffer to be a certain type. So it will not work because it's for short buffer, we only get the words of unwritten commands. For long buffer, we get none. So that's not enough. We have to stack life. So that's another thing in our attack we need to remember. Sometimes we just got a stack lift ourselves in order to execute the full payload without being controlled by the lack of the creators of libc and the one who compiled it. So our commands are actually very easy, very nice for exploitation. There are several variations of the same stuff. You can do many instructions. It's much more better than x86 in my opinion. So let's see what we can do in that one. We can abuse the current stack pointer. We can just lift ourselves and then just go back. So let's just a quick look. WPrintf function, epilogue. You can see that you can pop LR. If we jump right here, we will jump right here. And then the SP adds to itself 16 bytes. And then the next instruction will be BXLR. BX means branch. It checks the first bit. But in this case, just say it's like a call. Advanced call. So like x86 advanced call. So we'll get our stack lifted by 16 bytes just by coming to that one. And then we'll put a new instruction right here where we want to jump next time.  We only need to lift our stack 384 bytes so the system will not override ourselves and we can execute whatever payload we want. So if we do that, our payload will look like something like that. Like net cut, reverse shell. And that one is actually very important because it ignores the rest of the command until a null byte. And then we'll override the function and just go back and forth, back and forth until we lift it enough of the stack and execute. And then when we finish, we'll just go to our zero adjustment. Maybe that was a better idea to just put it right here. But anyway, we'll go to our zero adjustment. Again, our one adjustment, four bytes of junk and then we'll call system. And we can execute whatever we want, whatever size we want of the buffer. So another interesting parts to adjust parameters will be, I just seen it on M count epilogue. You can see you can pop any, all zero to all three, whatever you want. And R11, LR. And then you branch to LR. So you can pop and adjust multiple parameters in the same jump, in the same return oriented, in the same widget of this one. What we want to do next would be, as a remote attackers, would be actually to enable the stack and execute whatever we want. That can be easily done by calling and protect and changing our place in the memory to be executable. And then we'll have to jump on it. There is a good section of that on Perk magazine, the Alphanumeric armshell codes. So yeah. All right. So yesterday I was very bored. It was like 3 a.m. And well, that's the Android device. I'm going to demo on that one. Actually, we went pretty fast. It's cool. So let's see if we can get a shell out of Android application. There are several limitations on Android devices. First of all, you don't want it to be like a Dalvik application. You want it to be a native Android application, for instance, something that had been compiled with NDK. NDK is the native development kit for Android. And well, it's actually pretty hard to compile dynamically. There's lots of tutorials in the Internet, but it took some time. It's not user-friendly. And also Android Lipsy had been compiled differently. The BNSH is actually nothing in Android. There is slash system, slash BNSH. They recompiled their Lipsy. And they did, I don't know if they did it by mistake or by luck, but like by mistake or they're really meant to do it. But Lipsy of Android is much more harder to exploit because it has no pop R0 instructions and stuff like that. So you have to be a little bit more complicated to do that. But it's the same technique. So it works on every ARM architecture. So we don't get things on R0 immediately. But we can do that. And the slash BNSH is actually on a different path. But for instance, the system function is being implemented that it executes execve function with the full path of the BNSH in regular Lipsy. So it has to do that. You're also, so they just modify the variable and they just put system slash BNSH. So that string should also be in the same library. So we're cool with that. All right. So don't worry. It's all the same. Also here in Android. We'll get the slash system BNSH to R0. And we'll not pop R0, but we'll do a trick to do that. As you can see that, I hope that some people can see the trick here. I'll give you like 10 seconds to think about it before I say what it is. It's the mal info function, just a function in Android Lipsy that I took from that one. And you can see that you can pop to, that's a pop instruction if you're not familiar with ARM architecture. So you can actually pop to R4 and get the PC back. So let's do that. We'll pop to R4 instruction so we can control the R4 register. That's the first step we want to do. So after we control the R4 register and we control the PC, which means the next instruction, we might want to go here. So we just control the R4 instruction and then we move the R4 to R0. And then we can put some more four bytes of junk on R4 and we can go to system. So our payload will look like that. If that thing is the LDMD R4, we'll just put this, slash system, slash BNSH address in R4 and then we'll jump, like you can see, it's four bytes offset between that one. So we'll just jump to the first instruction and that will move the R4 to R0 and then we can put some more four bytes of junk that will be on the next R4, the second phase of this attack and then we'll go to system. So, well, I'm quite, I did it too hairy. I was too hairy to do the conversation. So let's show the demo then. So what I did here was actually compiling, yeah, I can read it. A native application for Android, just to run C application on Android, what it do is just calling a vulnerable function. That's after the function. So you're not supposed to see that if the payload that succeeded or the program had crashed, because after the function we would get a segmentation fault. So we go to the STACO, which means stack overflow, and we got two buffers, a small buffer and a big buffer. What we do is actually read from that place, slash SD card, slash buffer, and we'll just put the stuff in it on the small buffer via memcpy. I use memcpy because there's actually, I think there was a null in one of the parameters. So they were lucky on this version but it was an honest mistake by them, I think. So I used memcpy to copy the buffer to the small buffer. Small buffer is 16 bytes and the big buffer is, I don't know, 256. So what should happen if we succeed in this one is actually getting a shell. I put my shell code is on that place and it has the same technique I described here. So what we're going to do is put AAAs and then we're going to adjust the R4. We're going to jump again. We're going to adjust the R4 to slash system slash bin SH. We're going to jump again to the move instruction. So the R0 will contain our parameter and then we'll jump back and do the system. All right, so let's do it. That's this device right here. It's the G1, I think. The only Android device I had on my desk. Let me find it. I was a bit drunk yesterday. No, not really. So that's our function. That's our binary. It has the same technique. It's just the C code that you just saw earlier. It was an item to compile it on Android. But here we go. I'm going to execute it and we're going to get a shell. So we got our shell, like you can see. And if you can see what executed is the buff one executed a shell that executed a shell. So we made it. We won. Victory. All right. I feel like dumb. All right, thank you. And so we actually made it and when we're going to exit the binary, we're supposed to see a segmentation fault. And it's not going to get into the printf that after the function. Because the path has been, the path of the execution has been altered. So we're going to exit out of the shell. If I'm not joking with you, it's supposed to see a segmentation fault. So we just stop it and now... All right. So we did it. We got a shell. That was the least complex one, but this stuff works. So that's the whole point of the talk, right? So you can do whatever you want actually on Android. So I'm about to finish right now. I did it a bit earlier. You might want to catch some other talk anyway. The buffer holes on ARM are actually a real threat. We need some more security mechanism set up on that one. And like fully ASL ARM mainline, we want to do that. And if you're writing an application for ARM, don't count on it being unexploitable, because it can be exploitable like you can see. Sometimes it can be even easier. Sometimes it's harder. It's not a hacker's heaven like this, but it can be done. If you want to prevent it, we want not a single unrandomized static code and stack cookies, and like the most vectors we can to prevent buffer holes, the better. If anyone got questions, I'll be at Q&A 114. You can download the full talk and the paper, like I said. And if anyone wants a business card or something, I got like a full pack here. Anyway, special thanks to some guys, Ilan from Samsung Israel and Moshe Verde and Matthew from InGuardians. Help me a lot. Some references, and that's it. Thank you.


So, now, welcome to this 33rd lecture. So, in this lecture, we will see modeling of rotating machine. So, actually, we have already seen in time harmonic simulation when we analyzed torque-speed characteristic of a motor, right. That time we had, what did we do? We took a one condition of the stator and motor, the rotor. So, it was like a static condition, is it not? And then in that condition, we varied the slip, right. And based on that, we then calculated rotor loss and then from rotor loss, we calculated torque. And so, that was like a static condition or quasi-static condition. So, if we have that kind of, you know, fixed rotor structure in your simulation, then, you know, you have, you can, you have the option of modeling a section of the motor using either Neumann or Dirichlet conditions, right. For example, here, this case A and this figure, you have one pole of the machine, you can see here, is it not? This is the one pole. In this case, the outermost boundary is typically always A equal to 0 because you have to contain all the flux within the stator structure. That is why A equal to 0 and this is the end of the boundary. So, we define A equal to 0. Now, here on this, these two sides, you have homogeneous Neumann condition because of flux condoms. Sir, can you see here? They are going normally on this, right. And actually, it will be like that. Here, we are imposing, that is why you are getting it. So, this is homogeneous Neumann condition on both these sides. But if the same condition, if you model two half poles, instead of one full pole, if you model two half poles, that means then the flux is, is one half pole and is another half pole and the flux is basically getting combined like this, right. So, the flux is flowing like this. So, this, this, here in this case you have two half poles. Then again, here in this case, A is equal to 0 on the outermost boundary and then A is equal to 0 on this also because there is a flux parallel condition here. Can you see here? There is a flux parallel condition whereas here it was for flux normal, right. So, here you have flux parallel condition, right. So, then here in this case, when you are modeling two half poles, the way they are modeled, then you have flux parallel condition at these two boundaries and then you will have A equal to 0 on these and this. Third condition is if you want to further simplify, you can cut this model further like this at this symmetry line because now you can see here on this symmetry line here, the flux is normal, is it not? Everywhere the flux is normal. So, then you can cut it here and impose A by Dab by N equal to 0, again homogeneous Neumann condition, right. So, the model becomes still simpler. So, this was one fourth model, this becomes one eighth model. So, here you have deleclate and Neumann condition applied on these two boundaries respectively, okay. Depending upon which section of this model you consider, either you will have homogeneous Neumann condition or deleclate condition or combination deleclate and Neumann condition, depending upon the section of the model being, the whole model being considered. Going further, here we have modeled two poles of a 6 pole permanent magnet synchronous motor. This flux plot is for a section of the motor with magnets on its rotor surface and here we have imposed homogeneous Neumann boundary conditions on these two boundaries and we have imposed A equal to 0 on this outermost boundary and this innermost boundary. It should be noted that A is equal to Zubis impose on this innermost boundary which is the outer boundary of the shaft because we are considering the shaft as made from a non magnetic material. This simulation is for a static condition. If the rotor is moved as shown in this simulation, you can see that the flux plot is distorted. On the outermost and the innermost boundaries we can still define A equal to 0, but on these two boundaries here, these two boundaries one is this and one is this, the flux is neither parallel nor perpendicular. You can see that the flux is going in arbitrary directions. Therefore, in this case for these two boundaries deleclate or Neumann boundary conditions are not applicable. However, we still want to simplify the model and how to do that we will see now. So, what we can do in that case, we can use periodic and anti periodic boundary condition. Now, what are these? First let us consider periodic boundary condition. Again, this is consider this model of rotating machine and this is 120 degrees mechanical. This is 120 degrees mechanical and then if we consider even number of poles, then we have these equation A z rho phi 2k phi by P is equal to A z rho phi. That means what we are doing is we are equating the potential values on this boundary to the potential values on this boundary. So, remember that on these both these boundaries there is no neither Neumann or nor deleclate. But what we are saying is we this potential values repeat after these many degrees. Now, here in this expression K is the number of poles to be considered and K in this case is even number and then that becomes periodic boundary condition. So, for example, here again here on this boundary A can be defined as 0, A equal to 0 on this boundary whereas here these boundary and these boundary. So, you have A 2 and A 1 we are saying that A 2 we are forcing A 2 to be equal to A 1. So, now let us see two examples for a 6 pole machine and if we want to model two poles as actually shown here you have two poles here of the machine being modeled. Then you have if you substitute it here now K is 2 and capital P is 6. So, this becomes 2 pi by 3 capital P is 6 K is 2. So, this becomes 2 pi by 3. So, that means whatever is A z at 5 plus 2 pi by 2 pi by 3 that is 120 degrees is equal to A z at 5. So, here if for example, if phi is equal to 0 if suppose this phi equal to 0 then phi plus 2 pi by 3 that means 120 degrees the conditions will repeat. So, for a now let us consider a two pole machine. So, for a two pole machine and if we have to model both the poles K is even number and K is 2 then obviously you know you have to model all 360 degrees is it not and which is obvious from this P is equal to 2 K is equal to 2. So, this 2 gets cancelled and then what you remain what remains is 2 pi. So, that means effectively you have to model the whole 2 pi. So, that does not actually give you any advantage, but just for confirming that this formula is indeed right I have just shown it for a two pole machine. But definitely this here you can see effectively you are modeling only one-third of the geometry and you will get the full flux plot. We will see later how do we obtain that. Now, in this slide we will understand anti-periodic boundary conditions which are applicable when we have odd number of poles. The corresponding equation is this which equates potentials on two boundaries but with negative sign. For the shown section of a permanent magnet say synchronous motor A that is magnetic vector potential on this boundary equals negative of magnetic vector potential on this boundary. Let us understand intuitively why these two potentials should be equal and opposite. Here a section with one pole is modeled and flux pattern will be such that half the flux will take path this way and the other half will take path this way. Fictitious current sources producing this pattern would be placed here with dot so that this flux goes like this and here with cross so that the flux completes path like this. So that means here current is coming out of the paper here current the fictitious current is going into the paper as for the right hand hold. Since the fictitious current sources are oppositely directed the corresponding magnetic vector potential values on these two boundaries will also have opposite sign. Now let us see two specific examples here. For a six pole machine with one pole being modeled that is p is equal to 6 and k is equal to 1. We will get pi by 3 here with this expression if we substitute k is equal to 1 and p is equal to 6. So here we will get pi by 3 and hence we need to model 60 mechanical degrees with anti-privileged boundary conditions specified on this boundary in terms of potential on this boundary. On the other hand for a two pole machine with one pole being modeled that is p is equal to 2 and k is equal to 1. We will get pi here and we need to model 180 mechanical degrees with anti-privileged boundary conditions. So going further now in this geometry regarding boundary conditions are applied only to boundary two. However, leaving boundary one without applying a boundary condition leads to automatic imposition of homogenous Neumann boundary conditions. Refer L12 slide 6 and L22 slide 7. It should be noted that imposition of homogenous Neumann boundary condition means forcing dabaz by daban equal to 0 on that boundary which implies forcing flux counters perpendicular to the boundary. However, this is not what we want as explained earlier since under rotation flux is neither perpendicular nor parallel to the boundary. Therefore, we need to consider this counter integral which is obtained after writing weighted residual statement for either ith node of a finite element which was discussed in L22. In this case of modeling a rotating structure this integral does not lead to the boundary condition matrix capital B subscript small b discussed in L28 because in this problem a constant value of non-homogenous Neumann boundary condition is not applied. This term in fact leads to a square matrix whose number of rows and columns equals the number of nodes in the entire problem domain with non-zero entries only for the nodes on boundary 1. Let us understand this. Consider a part of boundary 1 with 3 elements as shown here. For element 1 let node 1 be the local node number 1, node 2 be the local node number 2 and node 5 be the local node number 3 and then approximating the magnetic vector potential in element 1 as this we know very well now which in turn is given by this with a1, a2 and a3 given by these expressions. This we have seen number of times earlier. For simplicity to explain the mathematical formulation consider the boundary 1 as horizontal line in which case a in hat will be minus a y hat in the negative y direction. Normal to this boundary will be in negative y direction and d tau will be dx and this in fact is the initial position of the rotor structure. The angle of the rotor part of the boundary 1 changes with the rotor angle and a in hat then will be in an arbitrary direction but the part that corresponds to the stator will always be horizontal this part. So the close counter integral for node 1, close counter integral for node 1 is then reduced to because this is because the value of the integral for the 2 inner edges of the element 1 this edge and this edge they get cancelled when we form the global level matrices. You can refer L28 for this and hence the integration will be only for node 1 to node 2. So integration will be non-zero only for this edge and for these 2 edges the integration will reduce to 0. So going further since a in hat is equal to minus a y hat as seen on the previous slide and d tau is equal to dx the integral i on the previous slide reduces to this expression. So shooting the approximate function of a z 1 and remembering that n3 that is shape function of node 3 of element 1 is equal to 0 on boundary 1 because node number 3 is global node number 5. So shape function of this node on this segment will be 0 and hence the integral i the differential term in the integral i which is this that gets simplified as given here. So d by double y double y of a of a z of element 1 is double y double y of a z of element 1 and that gets simplified to this their n3 is 0 that is why the third term is not there. Also a1 and a2 of element 1 are nodal potentials and they are independent of x and y and ni as given by this expression is a function of x and y. Therefore the differential term in the above integral this differential term reduces to this is straight forward and then substituting this term in the integral we get i is equal to this and then since only n is a function of n1 is a function of x so only that appears under the integral sign and this bracketed term with these two terms being added is taken outside this integral. So moving further this now integral i we can simplify further by putting the expression for n1 of 1 and then we integrate and we can get then this entire expression as given here you can easily verify this by putting the expression of n1 and then integrating with respect to dx. Now this whole expression is rearranged here so that then eventually we can write it in matrix multiplication form with this whole matrix multiplied to this column and this CB11 CB12 and CB13 are basically these three terms CB11 will be the coefficient of a1 CB12 will be coefficient of a2 and CB13 of course is 0 because the node 3 which is the global node number 5 has no contribution to the integral as explained on the previous slide. Thus at the element level we get this equation when you apply the FEM procedure for Poisson's equation right see when our normal Poisson's equation is generally leading to the equation CA is equal to BJ. Now here because of periodic bonding conditions we have one more term here CB into A at the element level. Now as explained on slide 4A this will be 3 by 3 matrix the square matrix 3 by 3 and when we form global system of equations by combining all these element level matrices this will be n by n matrix. So periodic bonding conditions are taken into account by adding this term at the element level and the corresponding term at the global level and then we can solve the problem as usual by using the finite element procedure and get the solution. Now next we will go how to let us understand how to model rotation. Now here this is the air gap. Now in the air gap we can you see here there is a you know gate curve so which separates what is called as fixed mesh and a moving mesh. So on the right hand side of this gate curve there will be fixed mesh and that mesh will be fixed to the stator part and on the left side of this gate curve in the gap you will have one layer of mesh which will be attached to the rotor and it will move along in the rotor. So this is what you know we will have so we will have to have at least one two layers in the air gap to have rotation effectively modeled. So now what happens in that air gap? Now this is that air gap and this is that in the earlier slide this was that gate curve middle one. This mesh is attached to the stator and it is fixed this lower one is attached to the rotor and it moves along with the rotor. So this was at the initial instant now this is at the next instant rotor has moved so this has moved so this point has moved to this point this is a point B point A is this. So point B when you are in this position point B is actually joined to the nearest point on this fixed mesh. Now in this case nearest point is still A and not this this point is further from B as compared to A. So that is why B joined still joined to A and that is how and then the other nodes are respectively joined to the other respective nodes. Now when actually this moves further when it comes here for example now this node will be closer as compared to node A and this is joined to B joined to the next node and similarly the other node. Effectively then what we are doing here one more node gets added. So the main thing in this moving band method is the number of elements remain fixed the number of nodes go on increases goes on increases the number goes number of nodes goes on increases. When it moves further when this mesh the motion makes B point come here right one more node will get added here so and this goes on and this will come continue up to when this point comes here. So moment you solve for from this point to this point that means corresponding to time when condition was this to the time when B comes here and this whole this whole thing becomes like this will become like this. So that will complete our one set of simulation here you can see here at t is equal to 0 you have we have created this mesh right and then we will see what happens now here this is the air gap and these are the you know slots and you can see here in each of the slot there are two coils right ok. Now you can see in this case now the rotor has moved so is the corresponding moving mesh associated moving mesh in the air gap it has moved but in this position still there is no node is added no new node is added yet right it has just this mesh has just got sort of tilted and got distorted in the next position and you can see here now you can see there are two nodes are added here one is here another is here the two nodes have been added right and this has moved on them. So this how it you know goes the node in nodes increase elements remain the same. So boundary condition is on this whatever is A on this is the same as A on this if it is even periodicity and this A will be negative of this A if it is odd periodicity poles are even then it will be this A and this A and this A will be same look the number of poles modeled are odd number of poles are not actually odd number of modeled poles are if they are odd then it is anti periodic boundary condition right ok. So for even here I showed the very first case here you know you can for example here you have cut is it not. So depending upon how many poles or fraction of poles you model that is in your hand you can actually reduce the geometric dependence of if you can exploit the boundary condition is it not. So you can either model even number of poles or odd number of poles right if you can exploit the boundary condition. So this flux plot is for a section of 6 pole permanent magnetic synchronous motor considering a rotation with magnets placed on its rotor and AC windings on its stator in the considered section two poles of the motor are modeled the fluid solution is obtained after imposing boundary conditions as discussed earlier because of periodic boundary conditions whatever flux you see here inside and rotor inside rotor and stator parts appears here on this side here in both parts and continuity of flux is maintained as will be demonstrated on the next slide. Now here we see the complete flux plot using the periodic boundary conditions we have solved for 120 mechanical degrees but the so but using that solution we have obtained flux plot for entire 360 degrees the flux pattern in the region of 120 degrees gets repeated twice in the remaining 240 degrees and the flux continuity is maintained at the interfaces as you can see. Before going further let us refresh ourselves in the procedure we studied in L24 for calculating flux linkages of a coil in a rotating machine for a coil fit two coil sides one and two as shown here which are one pole pitch apart coils total flux linkages given by this formula where in AC1 and AC2 are the average values of magnetic vector potentials of the two coil sides because of symmetry AC1 is equal to minus AC2 and after some mathematical manipulations we get the formula given here and for lecture L24 for this and this is for jet phase coil of the considered machine here factor 2 appears if we are modeling only one coil side if both coil sides are modeled then the factor 2 will not appear how do we intuitively understand this formula let us see we know that flux is integral of a dot tl so summation i goes from 1 to 3 ai e by 3 gives the average a over the triangular element under consideration and then summation of this average a multiplied by the element area or all elements in the coil side and then divided by the coil sides cost section area gives the average value of a over the coil side containing n e triangular elements this overall average multiplied by length L gives the flux which when multiplied by number of turns n and the number of pole pairs n p gives the total flux linkage of the coil the element level g j e matrix is given by this expression and when we assemble element level matrices by executing the summation of all elements of the coil side we get the flux linkage in terms of global a and a and g matrices now let us go further flux linkage is expression in the previous slide is modified here by dropping 2 because in the simulation shown on slide 10 of the lecture we are modeled 1 pole pair if you model only a single pole then you have to use 2 in the expression and hence now by dropping the factor 2 and following the same procedure discussed in the previous slide we get the expression of the flux linkage as this and element level matrices as this and then now the discuss formulation is applied to calculate flux linkages with stator coils for the PMSM geometry shown in slide 10 the flux linkages of phases a a b and c are shown in this figure it should be noted that the flux linkages are calculated for different rotor positions which are indicated on the x axis here this means that at every rotor position we calculate flux linkages using the magnetic static formulation. Thank you.