Compare stock indices of different sizes Python












-1















I am using Python to try and do some macroeconomic analysis of different stock markets. I was wondering about how to properly compare indices of varying sizes. For instance, the Dow Jones is around 25,000 on the y-axis, while the Russel 2000 is only around 1,500. I know that the website tradingview makes it possible to compare these two in their online charter. What it does is shrink/enlarge a background chart so that it matches the other on a new y-axis. Is there some statistical method where I can do this same thing in Python?










share|improve this question



























    -1















    I am using Python to try and do some macroeconomic analysis of different stock markets. I was wondering about how to properly compare indices of varying sizes. For instance, the Dow Jones is around 25,000 on the y-axis, while the Russel 2000 is only around 1,500. I know that the website tradingview makes it possible to compare these two in their online charter. What it does is shrink/enlarge a background chart so that it matches the other on a new y-axis. Is there some statistical method where I can do this same thing in Python?










    share|improve this question

























      -1












      -1








      -1








      I am using Python to try and do some macroeconomic analysis of different stock markets. I was wondering about how to properly compare indices of varying sizes. For instance, the Dow Jones is around 25,000 on the y-axis, while the Russel 2000 is only around 1,500. I know that the website tradingview makes it possible to compare these two in their online charter. What it does is shrink/enlarge a background chart so that it matches the other on a new y-axis. Is there some statistical method where I can do this same thing in Python?










      share|improve this question














      I am using Python to try and do some macroeconomic analysis of different stock markets. I was wondering about how to properly compare indices of varying sizes. For instance, the Dow Jones is around 25,000 on the y-axis, while the Russel 2000 is only around 1,500. I know that the website tradingview makes it possible to compare these two in their online charter. What it does is shrink/enlarge a background chart so that it matches the other on a new y-axis. Is there some statistical method where I can do this same thing in Python?







      python plot statistics correlation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 3:51









      yqz09yqz09

      14




      14
























          2 Answers
          2






          active

          oldest

          votes


















          0















          I know that the website tradingview makes it possible to compare these two in their online charter. What it does is shrink/enlarge a background chart so that it matches the other on a new y-axis.




          These websites rescale them by fixing the initial starting points for both indices at, say, 100. I.e. if Dow is 25000 points and S&P is 2500, then Dow is divided by 250 to get to 100 initially and S&P by 25. Then you have two indices that start at 100 and you then can compare them side by side.



          The other method (works good only if you have two series) - is to set y-axis on the right hand side for one series, and on the left hand side for the other one.






          share|improve this answer































            0














            You have multiple possibilities here. Let's say you define your axis by the following call



            fig, ax = plt.subplots()


            Then, you can change the scale of the y axis to logarithmic using



            ax.set_yscale('log')


            You can also define two y axes inside the same plot with different scales with the call



            ax2 = ax.twinx()


            and then plot, let's say, big values on ax and small ones on ax2. That will only work well if you have two ranges of values at most.
            Another solution is to create a new axis which zooms inside your plot



            from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
            ax2 = zoomed_inset_axes(ax, zoom, bbox_to_anchor=(, ),
            bbox_transform=ax.transAxes, loc='', borderpad=)


            A last thing would be to directly scale your data. For example, if DowJones varies between 20,000 and 30,000, then you can apply the following transformation



            DowJones = (DowJones - min(DowJones)) / (max(DowJones) - min(DowJones))


            and then your values will vary between 0 and 1. Applying similar transformations to other variables will then allow you to compare variations more easily on the same graph without making any change to the axes.






            share|improve this answer

























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312182%2fcompare-stock-indices-of-different-sizes-python%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0















              I know that the website tradingview makes it possible to compare these two in their online charter. What it does is shrink/enlarge a background chart so that it matches the other on a new y-axis.




              These websites rescale them by fixing the initial starting points for both indices at, say, 100. I.e. if Dow is 25000 points and S&P is 2500, then Dow is divided by 250 to get to 100 initially and S&P by 25. Then you have two indices that start at 100 and you then can compare them side by side.



              The other method (works good only if you have two series) - is to set y-axis on the right hand side for one series, and on the left hand side for the other one.






              share|improve this answer




























                0















                I know that the website tradingview makes it possible to compare these two in their online charter. What it does is shrink/enlarge a background chart so that it matches the other on a new y-axis.




                These websites rescale them by fixing the initial starting points for both indices at, say, 100. I.e. if Dow is 25000 points and S&P is 2500, then Dow is divided by 250 to get to 100 initially and S&P by 25. Then you have two indices that start at 100 and you then can compare them side by side.



                The other method (works good only if you have two series) - is to set y-axis on the right hand side for one series, and on the left hand side for the other one.






                share|improve this answer


























                  0












                  0








                  0








                  I know that the website tradingview makes it possible to compare these two in their online charter. What it does is shrink/enlarge a background chart so that it matches the other on a new y-axis.




                  These websites rescale them by fixing the initial starting points for both indices at, say, 100. I.e. if Dow is 25000 points and S&P is 2500, then Dow is divided by 250 to get to 100 initially and S&P by 25. Then you have two indices that start at 100 and you then can compare them side by side.



                  The other method (works good only if you have two series) - is to set y-axis on the right hand side for one series, and on the left hand side for the other one.






                  share|improve this answer














                  I know that the website tradingview makes it possible to compare these two in their online charter. What it does is shrink/enlarge a background chart so that it matches the other on a new y-axis.




                  These websites rescale them by fixing the initial starting points for both indices at, say, 100. I.e. if Dow is 25000 points and S&P is 2500, then Dow is divided by 250 to get to 100 initially and S&P by 25. Then you have two indices that start at 100 and you then can compare them side by side.



                  The other method (works good only if you have two series) - is to set y-axis on the right hand side for one series, and on the left hand side for the other one.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 15 '18 at 4:33









                  Askar AkhmedovAskar Akhmedov

                  355




                  355

























                      0














                      You have multiple possibilities here. Let's say you define your axis by the following call



                      fig, ax = plt.subplots()


                      Then, you can change the scale of the y axis to logarithmic using



                      ax.set_yscale('log')


                      You can also define two y axes inside the same plot with different scales with the call



                      ax2 = ax.twinx()


                      and then plot, let's say, big values on ax and small ones on ax2. That will only work well if you have two ranges of values at most.
                      Another solution is to create a new axis which zooms inside your plot



                      from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
                      ax2 = zoomed_inset_axes(ax, zoom, bbox_to_anchor=(, ),
                      bbox_transform=ax.transAxes, loc='', borderpad=)


                      A last thing would be to directly scale your data. For example, if DowJones varies between 20,000 and 30,000, then you can apply the following transformation



                      DowJones = (DowJones - min(DowJones)) / (max(DowJones) - min(DowJones))


                      and then your values will vary between 0 and 1. Applying similar transformations to other variables will then allow you to compare variations more easily on the same graph without making any change to the axes.






                      share|improve this answer






























                        0














                        You have multiple possibilities here. Let's say you define your axis by the following call



                        fig, ax = plt.subplots()


                        Then, you can change the scale of the y axis to logarithmic using



                        ax.set_yscale('log')


                        You can also define two y axes inside the same plot with different scales with the call



                        ax2 = ax.twinx()


                        and then plot, let's say, big values on ax and small ones on ax2. That will only work well if you have two ranges of values at most.
                        Another solution is to create a new axis which zooms inside your plot



                        from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
                        ax2 = zoomed_inset_axes(ax, zoom, bbox_to_anchor=(, ),
                        bbox_transform=ax.transAxes, loc='', borderpad=)


                        A last thing would be to directly scale your data. For example, if DowJones varies between 20,000 and 30,000, then you can apply the following transformation



                        DowJones = (DowJones - min(DowJones)) / (max(DowJones) - min(DowJones))


                        and then your values will vary between 0 and 1. Applying similar transformations to other variables will then allow you to compare variations more easily on the same graph without making any change to the axes.






                        share|improve this answer




























                          0












                          0








                          0







                          You have multiple possibilities here. Let's say you define your axis by the following call



                          fig, ax = plt.subplots()


                          Then, you can change the scale of the y axis to logarithmic using



                          ax.set_yscale('log')


                          You can also define two y axes inside the same plot with different scales with the call



                          ax2 = ax.twinx()


                          and then plot, let's say, big values on ax and small ones on ax2. That will only work well if you have two ranges of values at most.
                          Another solution is to create a new axis which zooms inside your plot



                          from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
                          ax2 = zoomed_inset_axes(ax, zoom, bbox_to_anchor=(, ),
                          bbox_transform=ax.transAxes, loc='', borderpad=)


                          A last thing would be to directly scale your data. For example, if DowJones varies between 20,000 and 30,000, then you can apply the following transformation



                          DowJones = (DowJones - min(DowJones)) / (max(DowJones) - min(DowJones))


                          and then your values will vary between 0 and 1. Applying similar transformations to other variables will then allow you to compare variations more easily on the same graph without making any change to the axes.






                          share|improve this answer















                          You have multiple possibilities here. Let's say you define your axis by the following call



                          fig, ax = plt.subplots()


                          Then, you can change the scale of the y axis to logarithmic using



                          ax.set_yscale('log')


                          You can also define two y axes inside the same plot with different scales with the call



                          ax2 = ax.twinx()


                          and then plot, let's say, big values on ax and small ones on ax2. That will only work well if you have two ranges of values at most.
                          Another solution is to create a new axis which zooms inside your plot



                          from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
                          ax2 = zoomed_inset_axes(ax, zoom, bbox_to_anchor=(, ),
                          bbox_transform=ax.transAxes, loc='', borderpad=)


                          A last thing would be to directly scale your data. For example, if DowJones varies between 20,000 and 30,000, then you can apply the following transformation



                          DowJones = (DowJones - min(DowJones)) / (max(DowJones) - min(DowJones))


                          and then your values will vary between 0 and 1. Applying similar transformations to other variables will then allow you to compare variations more easily on the same graph without making any change to the axes.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 15 '18 at 5:29

























                          answered Nov 15 '18 at 4:14









                          Patol75Patol75

                          6236




                          6236






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312182%2fcompare-stock-indices-of-different-sizes-python%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              這個網誌中的熱門文章

                              Xamarin.form Move up view when keyboard appear

                              Post-Redirect-Get with Spring WebFlux and Thymeleaf

                              Anylogic : not able to use stopDelay()