{"id":1924291,"date":"2014-02-20T20:30:08","date_gmt":"2014-02-20T15:00:08","guid":{"rendered":"http:\/\/stockviz.biz\/index.php\/?p=1924291"},"modified":"2014-02-20T20:30:08","modified_gmt":"2014-02-20T15:00:08","slug":"calculate-pes-indices","status":"publish","type":"post","link":"https:\/\/stockviz.biz\/index.php\/2014\/02\/20\/calculate-pes-indices\/","title":{"rendered":"Calculate PEs for all Indices"},"content":{"rendered":"<p><a href=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/02\/index-PE.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1924301\" alt=\"index PE\" src=\"http:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/02\/index-PE.png\" width=\"491\" height=\"217\" srcset=\"https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/02\/index-PE.png 491w, https:\/\/portalvhds29z8xdrqhczq.blob.core.windows.net\/wordpress\/2014\/02\/index-PE-300x132.png 300w\" sizes=\"auto, (max-width: 491px) 100vw, 491px\" \/><\/a><\/p>\n<p>Some investors like to use the PE ratio of an index to time their entry and exit. This is especially true about the widely tracked Nifty 50. However, there are advantages to rolling your own.<\/p>\n<h3>Annual vs. Quarterly EPS<\/h3>\n<p>The most popular approach of calculating PE is by dividing the price by the last reported annual EPS. This is probably fine most of the time. However, we prefer to add up the last 4 <strong>diluted<\/strong> quarterly EPS so that we have the latest numbers.<\/p>\n<h3>Closing vs. Live Prices<\/h3>\n<p>Once again, a matter of preference. Since most data points present the PE based on the last close, it may be useful to calculate it based on the live price, just to see the difference.<\/p>\n<h3>Other indices<\/h3>\n<p>Whereas the Nifty index PE can be obtained from a number sources, what about the other indices? And sector-wide PE estimates? By having a script handy, you can always have a ready reckoner of where things stand.<\/p>\n<h3>The Code<\/h3>\n<p>The StockViz API exposes the <a title=\"quarterly eps\" href=\"https:\/\/www.mashape.com\/drona\/stockviz#!endpoint-Quarterly-EPS\" target=\"_blank\">QuarterlyEps<\/a> endpoint that returns the quarterly basic and diluted EPS in descending order of periods. You can use this to calculate the annualized number, grab the live price and adjust it by the stock&#8217;s weight within the index to arrive at the index EPS.<\/p>\n<pre><small>for cc in constituents:\r\n\tticker = cc[\"SYMBOL\"]\r\n\t#print ticker,\r\n\r\n\tprice = common.getLivePrice(ticker)\r\n\t#print price,\r\n\r\n\tepss = common.getEps(ticker)\r\n\r\n\tannualEps = 0\r\n\tfor i in range(0,4):\r\n\t\tannualEps += epss[i][\"EPS_DILUTED_AEI\"]\r\n\r\n\t#print annualEps, price\/annualEps\r\n\r\n\tif annualEps != 0:\r\n\t\tindexPe += price\/annualEps * cc[\"WEIGHTAGE\"]\r\n\r\n\tindexPe \/= 100<\/small><\/pre>\n<p>You can download the entire code on <a href=\"https:\/\/github.com\/shyams80\/StockViz\/tree\/master\/equity\/03-index-pe\" target=\"_blank\">GitHub<\/a>.<\/p>\n<h6>Previously<\/h6>\n<ul>\n<li><a title=\"hack your own news reading app\" href=\"http:\/\/stockviz.biz\/index.php\/2014\/02\/18\/news-reading-sentiment-analysis-app\/\" target=\"_blank\">Build your own News Reading and Sentiment Analysis App<\/a><\/li>\n<li><a title=\"Permalink to Building a Cross-Over Trading System\" href=\"http:\/\/stockviz.biz\/index.php\/2014\/02\/19\/building-cross-trading-system\/\" target=\"_blank\">Building a Cross-Over Trading System<\/a><\/li>\n<li><a href=\"http:\/\/stockviz.biz\/index.php\/2014\/02\/20\/stochastic-macd-model-trading-nifty-stocks\/\" title=\"technical trading model\" target=\"_blank\">A Stochastic-MACD Model for Trading Nifty Stocks<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Some investors like to use the PE ratio of an index to time their entry and exit. This is especially true about the widely tracked Nifty 50. However, there are advantages to rolling your own. Annual vs. Quarterly EPS The most popular approach of calculating PE is by dividing the price by the last reported &hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3131,9],"tags":[3181],"class_list":["post-1924291","post","type-post","status-publish","format-standard","hentry","category-api","category-your-money","tag-api-valuation","entry"],"_links":{"self":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts\/1924291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/comments?post=1924291"}],"version-history":[{"count":0,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/posts\/1924291\/revisions"}],"wp:attachment":[{"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/media?parent=1924291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/categories?post=1924291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stockviz.biz\/index.php\/wp-json\/wp\/v2\/tags?post=1924291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}