Using python and yahoo finance to calculate price changes in Nasdaq in the last 33 years

As every trader on the planet knows that markets are moving up more often than down, I wanted to get more precise info. I wrote simple python script that consumes closing price of each month since 1990 July  till 2023 July. 

Simple summary for Nasdaq index (Us100) 

In total 392 months we had 83 months that generated negative return if position was held for a 12 months and 297 positive return for the same hold position time.

% ratio of long positions  78.15789473684211

% ratio of short positions  21.842105263157897


Here is a python code if you want to play around and change some parameters etc.


For full python code visit - https://www.mycompiler.io/view/6DTBdux1AIx


Results


Total months 392
586.340027  position entry  12
+ % change 36.24859794878033 



620.210022  position entry  13
+ % change 33.21616915116537 



633.469971  position entry  14
+ % change 28.47332521781052 



603.77002  position entry  15
+ % change 20.118592837716594 



578.679993  position entry  16
+ % change 16.23695187955115 



585.309998  position entry  17
+ % change 13.531293377975063 



563.599976  position entry  18
+ % change 15.55712681577545 



580.830017  position entry  19
+ % change 13.56507165503466 



563.119995  position entry  20
+ % change 6.6486721005174125 



583.27002  position entry  21
+ % change 9.667909041510491 



605.169983  position entry  22
+ % change 10.276452029511855 



652.72998  position entry  23
+ % change 19.73709802635386 



676.950012  position entry  24
+ % change 13.385033369347227 



696.340027  position entry  25
+ % change 10.932877911382795 



670.77002  position entry  26
+ % change 5.560780578714603 



690.130005  position entry  27
+ % change 12.513582132977966 



661.419983  position entry  28
+ % change 12.509448176137134 



700.530029  position entry  29
+ % change 16.447550601717325 



703.950012  position entry  30
+ % change 19.937500334895944 



704.700012  position entry  31
+ % change 17.577691626319996 



742.840027  position entry  32
+ % change 24.193638666161963 



762.780029  position entry  33
+ % change 23.533653501040988 



779.26001  position entry  34
+ % change 22.340428710052755 



754.390015  position entry  35
+ % change 13.475792756880537 



776.799988  position entry  36
+ % change 12.85401358682822 



800.469971  position entry  37
+ % change 13.008600918522154 



792.5  position entry  38
+ % change 15.360249842271287 



743.460022  position entry  39
+ % change 7.17321919429314 



733.840027  position entry  40
+ % change 9.86864184774156 



735.190002  position entry  41
+ % change 4.71442387759784 



705.960022  position entry  42
+ % change 0.2847200885831416 



722.159973  position entry  43
+ % change 2.4177414496496916 



765.619995  position entry  44
+ % change 2.975362209551496 



764.289978  position entry  45
+ % change 0.1975623184215044 



777.48999  position entry  46
- % change -0.2276582364745212 



750.320007  position entry  47
- % change -0.5424362887873675 



751.960022  position entry  48
- % change -3.3033625822198305 



755.200012  position entry  49
- % change -5.9944330350460815 



793.72998  position entry  50
+ % change 0.15496201869557139 



817.210022  position entry  51
+ % change 9.024607874914192 



843.97998  position entry  52
+ % change 13.05006701699251 



864.580017  position entry  53
+ % change 14.96564950101084 



933.450012  position entry  54
+ % change 24.37088082655679 



1001.210022  position entry  55
+ % change 27.871280037985873 



1020.109985  position entry  56
+ % change 24.94730899041244 



1043.540039  position entry  57
+ % change 26.75987988612289 



1036.060059  position entry  58
+ % change 24.95705405819528 



1059.199951  position entry  59
+ % change 29.16162748198617 



1052.130005  position entry  60
+ % change 28.52974267186687 



1059.790039  position entry  61
+ % change 28.740601042769377 



1100.050049  position entry  62
+ % change 27.84601203176711 



1101.400024  position entry  63
+ % change 25.80261447315894 



1190.52002  position entry  64
+ % change 29.10829168584666 



1243.430054  position entry  65
+ % change 30.46814219917512 



1185.02002  position entry  66
+ % change 21.22917788342512 



1080.589966  position entry  67
+ % change 7.345981963337982 



1141.5  position entry  68
+ % change 10.634254489706523 



1226.920044  position entry  69
+ % change 14.946369642975691 



1221.51001  position entry  70
+ % change 15.182024664701688 



1292.609985  position entry  71
+ % change 18.057266825151437 



1291.030029  position entry  72
+ % change 18.504606293708452 



1379.849976  position entry  73
+ % change 23.195270686441642 



1309  position entry  74
+ % change 15.962563101604282 



1221.699951  position entry  75
+ % change 9.846929018989542 



1260.76001  position entry  76
+ % change 5.571241905110873 



1400.319946  position entry  77
+ % change 11.203860406913044 



1442.069946  position entry  78
+ % change 17.825066440986635 



1593.810059  position entry  79
+ % change 32.20083159231711 



1587.319946  position entry  80
+ % change 28.086331752048686 



1685.689941  position entry  81
+ % change 27.21555642242514 



1593.609985  position entry  82
+ % change 23.34950072492173 



1600.550049  position entry  83
+ % change 19.239639784610066 



1570.349976  position entry  84
+ % change 17.787114418372173 



1619.359985  position entry  85
+ % change 14.790411719355909 



1770.51001  position entry  86
+ % change 26.06650103040084 



1835.680054  position entry  87
+ % change 33.44701064121275 



1868.410034  position entry  88
+ % change 32.52230575421969 



1778.869995  position entry  89
+ % change 21.280366191122354 



1894.73999  position entry  90
+ % change 23.89087929684748 



1872.390015  position entry  91
+ % change 14.878308139236687 



1499.25  position entry  92
- % change -5.874266866766722 



1693.839966  position entry  93
+ % change 0.4811567304818166 



1771.390015  position entry  94
+ % change 10.036187880397412 



1949.540039  position entry  95
+ % change 17.9011450402943 



2192.689941  position entry  96
+ % change 28.38248825623632 



2505.889893  position entry  97
+ % change 35.377847625166986 



2288.030029  position entry  98
+ % change 22.618585090257138 



2461.399902  position entry  99
+ % change 25.42129978519842 



2542.860107  position entry  100
+ % change 26.523286560018377 



2470.52002  position entry  101
+ % change 27.99613115460606 



2686.120117  position entry  102
+ % change 29.4618294242126 



2638.48999  position entry  103
+ % change 29.035546009405177 



2739.350098  position entry  104
+ % change 45.26986524670203 



2746.159912  position entry  105
+ % change 38.31968930147284 



2966.429932  position entry  106
+ % change 40.28545910047135 



3336.159912  position entry  107
+ % change 41.56335156514524 



4069.310059  position entry  108
+ % change 46.11642000219477 



3940.350098  position entry  109
+ % change 36.40438461871923 



4696.689941  position entry  110
+ % change 51.28420104920015 



4572.830078  position entry  111
+ % change 46.17337928557948 



3860.659912  position entry  112
+ % change 34.13405570648462 



3400.909912  position entry  113
+ % change 27.357087252360014 



3966.110107  position entry  114
+ % change 32.27318343333124 



3766.98999  position entry  115
+ % change 29.957605488619844 



4206.350098  position entry  116
+ % change 34.875841663714986 



3672.820068  position entry  117
+ % change 25.23020836423942 



3369.629883  position entry  118
+ % change 11.965704394840804 



2597.929932  position entry  119
- % change -28.41608508785602 



2470.52002  position entry  120
- % change -64.71471698496902 



2772.72998  position entry  121
- % change -42.11084838488311 



2151.830078  position entry  122
- % change -118.26490804354302 



1840.26001  position entry  123
- % change -148.48825998234892 



2116.23999  position entry  124
- % change -82.4301558539209 



2110.48999  position entry  125
- % change -61.14314344603928 



2160.540039  position entry  126
- % change -83.57031276475225 



2027.130005  position entry  127
- % change -85.82873228202253 



1805.430054  position entry  128
- % change -132.98327668140172 



1498.800049  position entry  129
- % change -145.05070375801677 



1690.199951  position entry  130
- % change -99.36279615949415 



1930.579956  position entry  131
- % change -34.567331641767026 



1950.400024  position entry  132
- % change -26.667349753888224 



1934.030029  position entry  133
- % change -43.36540479847948 



1731.48999  position entry  134
- % change -24.27620664442882 



1845.349976  position entry  135
+ % change 0.2758265947488762 



1688.22998  position entry  136
- % change -25.352589106372815 



1615.72998  position entry  137
- % change -30.621453839706554 



1463.209961  position entry  138
- % change -47.6575540480482 



1328.26001  position entry  139
- % change -52.61545102152101 



1314.849976  position entry  140
- % change -37.31072646724526 



1172.060059  position entry  141
- % change -27.877410162647653 



1329.75  position entry  142
- % change -27.106595299868403 



1478.780029  position entry  143
- % change -30.552206422852635 



1335.51001  position entry  144
- % change -46.041587812584055 



1320.910034  position entry  145
- % change -46.41648403134169 



1337.52002  position entry  146
- % change -29.455257798683277 



1341.170044  position entry  147
- % change -37.592543485112316 



1464.310059  position entry  148
- % change -15.291837928977866 



1595.910034  position entry  149
- % change -1.2419212598296172 



1622.800049  position entry  150
+ % change 9.834242246809294 



1735.02002  position entry  151
+ % change 23.44411046046604 



1810.449951  position entry  152
+ % change 27.3744090371709 



1786.939941  position entry  153
+ % change 34.40965574119428 



1932.209961  position entry  154
+ % change 31.179839311469117 



1960.26001  position entry  155
+ % change 24.562046797047092 



2003.369995  position entry  156
+ % change 33.33682678021741 



2066.149902  position entry  157
+ % change 36.06901257641664 



2029.819946  position entry  158
+ % change 34.10646975680079 



1994.219971  position entry  159
+ % change 32.74713604801223 



1920.150024  position entry  160
+ % change 23.73980987435595 



1986.73999  position entry  161
+ % change 19.6719227461667 



2047.790039  position entry  162
+ % change 20.753592014127385 



1887.359985  position entry  163
+ % change 8.071590274814485 



1838.099976  position entry  164
+ % change 1.5042720940658951 



1896.839966  position entry  165
+ % change 5.793848029876439 



1974.98999  position entry  166
+ % change 2.166088396225239 



2096.810059  position entry  167
+ % change 6.5122755594334905 



2175.439941  position entry  168
+ % change 7.909661984090604 



2062.409912  position entry  169
- % change -0.18134076927380643 



2051.719971  position entry  170
+ % change 1.067398344293833 



1999.22998  position entry  171
+ % change 0.25059693232491853 



1921.650024  position entry  172
+ % change 0.07805791800099393 



2068.219971  position entry  173
+ % change 3.9396187128298434 



2056.959961  position entry  174
+ % change 0.4457997323167168 



2184.830078  position entry  175
+ % change 13.61525072340202 



2152.090088  position entry  176
+ % change 14.590007813836461 



2151.689941  position entry  177
+ % change 11.844177459953096 



2120.300049  position entry  178
+ % change 6.853278104131191 



2232.820068  position entry  179
+ % change 6.091400330427345 



2205.320068  position entry  180
+ % change 1.3549111275760586 



2305.820068  position entry  181
+ % change 10.556337824361407 



2281.389893  position entry  182
+ % change 10.06710526353682 



2339.790039  position entry  183
+ % change 14.555154664456621 



2322.570068  position entry  184
+ % change 17.261913839492397 



2178.879883  position entry  185
+ % change 5.078752292101458 



2172.090088  position entry  186
+ % change 5.300430568513321 



2091.469971  position entry  187
- % change -4.463851180964432 



2183.75  position entry  188
+ % change 1.4497956267887844 



2258.429932  position entry  189
+ % change 4.726291902510966 



2366.709961  position entry  190
+ % change 10.411495961080297 



2431.77002  position entry  191
+ % change 8.181281550629526 



2415.290039  position entry  192
+ % change 8.69336467296216 



2463.929932  position entry  193
+ % change 6.416978906200487 



2416.149902  position entry  194
+ % change 5.5774688850410605 



2421.639893  position entry  195
+ % change 3.3799349868903095 



2525.090088  position entry  196
+ % change 8.020308699576184 



2604.52002  position entry  197
+ % change 16.3423638033698 



2603.22998  position entry  198
+ % change 16.561728902645786 



2546.27002  position entry  199
+ % change 17.861422607489207 



2596.360107  position entry  200
+ % change 15.891867460433136 



2701.5  position entry  201
+ % change 16.400890912456042 



2859.120117  position entry  202
+ % change 17.222436828455916 



2660.959961  position entry  203
+ % change 8.613054850846742 



2652.280029  position entry  204
+ % change 8.935330636612807 



2389.860107  position entry  205
- % change -3.0993372701208086 



2271.47998  position entry  206
- % change -6.368971915834365 



2279.100098  position entry  207
- % change -6.254213894557963 



2412.800049  position entry  208
- % change -4.653930566958472 



2522.659912  position entry  209
- % change -3.2449918282920676 



2292.97998  position entry  210
- % change -13.530427771113814 



2325.550049  position entry  211
- % change -9.49108668269302 



2367.52002  position entry  212
- % change -9.665814230369213 



2091.879883  position entry  213
- % change -29.142214232957464 



1720.949951  position entry  214
- % change -66.1361572623677 



1535.569946  position entry  215
- % change -73.28809852859675 



1577.030029  position entry  216
- % change -68.18196104241716 



1476.420044  position entry  217
- % change -61.8685764062954 



1377.839966  position entry  218
- % change -64.85804128576135 



1528.589966  position entry  219
- % change -49.09819825416804 



1717.300049  position entry  220
- % change -40.49962034328225 



1774.329956  position entry  221
- % change -42.175354897744846 



1835.040039  position entry  222
- % change -24.955310580010735 



1978.5  position entry  223
- % change -17.541068941117004 



2009.060059  position entry  224
- % change -17.842172482311046 



2122.419922  position entry  225
+ % change 1.4389253834001647 



2045.109985  position entry  226
+ % change 15.850493928325326 



2144.600098  position entry  227
+ % change 28.398308503667703 



2269.149902  position entry  228
+ % change 30.501284749410974 



2147.350098  position entry  229
+ % change 31.244558333775714 



2238.26001  position entry  230
+ % change 38.44146972004383 



2397.959961  position entry  231
+ % change 36.25456676255154 



2461.189941  position entry  232
+ % change 30.224806286090704 



2257.040039  position entry  233
+ % change 21.386863974901775 



2109.23999  position entry  234
+ % change 12.999940845991642 



2254.699951  position entry  235
+ % change 12.249964829133935 



2114.030029  position entry  236
+ % change 4.965396354831065 



2368.620117  position entry  237
+ % change 10.394245714328697 



2507.409912  position entry  238
+ % change 18.437349425298116 



2498.22998  position entry  239
+ % change 14.155217287080998 



2652.870117  position entry  240
+ % change 14.46434231894964 



2700.080078  position entry  241
+ % change 20.47087360495684 



2782.27002  position entry  242
+ % change 19.55273952885421 



2781.070068  position entry  243
+ % change 13.775636630238255 



2873.540039  position entry  244
+ % change 14.3498991628284 



2835.300049  position entry  245
+ % change 20.395019927571692 



2773.52002  position entry  246
+ % change 23.950792682578147 



2756.379883  position entry  247
+ % change 18.200681810737187 



2579.459961  position entry  248
+ % change 18.04369670539732 



2415.399902  position entry  249
+ % change 1.9367304337996187 



2684.409912  position entry  250
+ % change 6.593627866175157 



2620.340088  position entry  251
+ % change 4.66008624449972 



2605.149902  position entry  252
- % change -1.8317646506008936 



2813.840088  position entry  253
+ % change 4.0428740241901036 



2966.889893  position entry  254
+ % change 6.222673562493412 



3091.570068  position entry  255
+ % change 10.043440490445322 



3046.360107  position entry  256
+ % change 5.673001941001323 



2827.340088  position entry  257
- % change -0.2815353212648263 



2935.050049  position entry  258
+ % change 5.50348465284382 



2939.52002  position entry  259
+ % change 6.23027350567253 



3066.959961  position entry  260
+ % change 15.895218920335946 



3116.22998  position entry  261
+ % change 22.48967767135081 



2977.22998  position entry  262
+ % change 9.835319070648348 



3010.23999  position entry  263
+ % change 12.952452405630293 



3019.51001  position entry  264
+ % change 13.72275987255296 



3142.129883  position entry  265
+ % change 10.448002063064308 



3160.189941  position entry  266
+ % change 6.116722463170452 



3267.52002  position entry  267
+ % change 5.384816341538435 



3328.790039  position entry  268
+ % change 8.484462182686794 



3455.909912  position entry  269
+ % change 18.18825837494806 



3403.25  position entry  270
+ % change 13.757436303533389 



3626.370117  position entry  271
+ % change 18.94043009510052 



3589.870117  position entry  272
+ % change 14.566269501610494 



3771.47998  position entry  273
+ % change 17.373816206761358 



3919.709961  position entry  274
+ % change 24.044635709718523 



4059.889893  position entry  275
+ % change 25.8541470498939 



4176.589844  position entry  276
+ % change 27.7039373560283 



4103.879883  position entry  277
+ % change 23.43514009715473 



4308.120117  position entry  278
+ % change 26.64573282138132 



4198.990234  position entry  279
+ % change 22.183195532528593 



4114.560059  position entry  280
+ % change 19.0973034475762 



4242.620117  position entry  281
+ % change 18.543027263923197 



4408.180176  position entry  282
+ % change 22.796939686614117 



4369.77002  position entry  283
+ % change 17.012334736096708 



4580.27002  position entry  284
+ % change 21.623177207355997 



4493.390137  position entry  285
+ % change 16.06604668167055 



4630.740234  position entry  286
+ % change 15.354570480534536 



4791.629883  position entry  287
+ % change 15.271212674336676 



4736.049805  position entry  288
+ % change 11.812797247388735 



4635.240234  position entry  289
+ % change 11.46349108515268 



4963.529785  position entry  290
+ % change 13.204507606273976 



4900.879883  position entry  291
+ % change 14.321706831352671 



4941.419922  position entry  292
+ % change 16.73324421020537 



5070.029785  position entry  293
+ % change 16.31962144380182 



4986.870117  position entry  294
+ % change 11.604271365064719 



5128.279785  position entry  295
+ % change 14.790725093014789 



4776.509766  position entry  296
+ % change 4.108433890303496 



4620.160156  position entry  297
+ % change 2.7438446876212486 



5053.75  position entry  298
+ % change 8.370215503339107 



5108.669922  position entry  299
+ % change 6.205921381506715 



5007.410156  position entry  300
+ % change 5.419175632634162 



4613.950195  position entry  301
- % change -0.46142758591262867 



4557.950195  position entry  302
- % change -8.898289201249145 



4869.850098  position entry  303
- % change -0.6371815225430317 



4775.359863  position entry  304
- % change -3.4774354973046426 



4948.049805  position entry  305
- % change -2.4652132619348217 



4842.669922  position entry  306
- % change -2.9777002629253397 



5162.129883  position entry  307
+ % change 0.6557389830789714 



5213.220215  position entry  308
+ % change 8.37698065666693 



5312  position entry  309
+ % change 13.024093448795181 



5189.140137  position entry  310
+ % change 2.609105428366278 



5323.680176  position entry  311
+ % change 4.038752270831377 



5383.120117  position entry  312
+ % change 6.979408834172229 



5614.790039  position entry  313
+ % change 17.825062683523793 



5825.439941  position entry  314
+ % change 21.757837327946444 



5911.740234  position entry  315
+ % change 17.62408520604155 



6047.609863  position entry  316
+ % change 21.037236674008646 



6198.52002  position entry  317
+ % change 20.17369002544579 



6140.419922  position entry  318
+ % change 21.134548068128034 



6348.120117  position entry  319
+ % change 18.68254242423625 



6428.660156  position entry  320
+ % change 18.90658257717364 



6495.959961  position entry  321
+ % change 18.22609696039042 



6727.669922  position entry  322
+ % change 22.868687121062354 



6873.970215  position entry  323
+ % change 22.553051446412187 



6903.390137  position entry  324
+ % change 22.02207886023753 



7411.47998  position entry  325
+ % change 24.24198602503679 



7273.009766  position entry  326
+ % change 19.903311992885346 



7063.450195  position entry  327
+ % change 16.305203961305775 



7066.27002  position entry  328
+ % change 14.415811370310475 



7442.120117  position entry  329
+ % change 16.710293269242598 



7510.299805  position entry  330
+ % change 18.240015958990064 



7671.790039  position entry  331
+ % change 17.253729771944297 



8109.540039  position entry  332
+ % change 20.727191368639847 



8046.350098  position entry  333
+ % change 19.268241104564478 



7305.899902  position entry  334
+ % change 7.914562035564007 



7330.540039  position entry  335
+ % change 6.228324537768753 



6635.279785  position entry  336
- % change -4.040678926698803 



7281.740234  position entry  337
- % change -1.7817134617658787 



7532.529785  position entry  338
+ % change 3.445323502295313 



7729.319824  position entry  339
+ % change 8.614854141918604 



8095.390137  position entry  340
+ % change 12.71242150883383 



7453.149902  position entry  341
+ % change 0.14798823510902356 



8006.240234  position entry  342
+ % change 6.194423530958967 



8175.419922  position entry  343
+ % change 6.160293756223274 



7962.879883  position entry  344
- % change -1.8417979192817724 



7999.339844  position entry  345
- % change -0.5876766697849499 



8292.360352  position entry  346
+ % change 11.896015225171436 



8665.469727  position entry  347
+ % change 15.405162444230868 



8972.599609  position entry  348
+ % change 26.049527738377442 



9150.94043  position entry  349
+ % change 20.426318041281366 



8567.370117  position entry  350
+ % change 12.07885638028635 



7700.100098  position entry  351
- % change -0.37947202800116464 



8889.549805  position entry  352
+ % change 8.93363202209991 



9489.870117  position entry  353
+ % change 21.462045211255866 



10058.76953  position entry  354
+ % change 20.405371550450464 



10745.26953  position entry  355
+ % change 23.916101879298317 



11775.45996  position entry  356
+ % change 32.37733464298579 



11167.50977  position entry  357
+ % change 28.3695290288517 



10911.58984  position entry  358
+ % change 24.004105051661295 



12198.74023  position entry  359
+ % change 28.96422447221831 



12888.28027  position entry  360
+ % change 30.381715628224764 



13070.69043  position entry  361
+ % change 29.988851935497944 



13192.34961  position entry  362
+ % change 35.058042196624285 



13246.87012  position entry  363
+ % change 41.87230622594796 



13962.67969  position entry  364
+ % change 36.33349756374738 



13748.74023  position entry  365
+ % change 30.97643887188346 



14503.9502  position entry  366
+ % change 30.648069034324184 



14672.67969  position entry  367
+ % change 26.766822713895156 



15259.24023  position entry  368
+ % change 22.830627328029156 



14448.58008  position entry  369
+ % change 22.70860037341468 



15498.38965  position entry  370
+ % change 29.595331602725572 



15537.69043  position entry  371
+ % change 21.489359792837632 



15644.96973  position entry  372
+ % change 17.620292704778542 



14239.87988  position entry  373
+ % change 8.210669330449436 



13751.40039  position entry  374
+ % change 4.0654098066008055 



14220.51953  position entry  375
+ % change 6.846792115758939 



12334.63965  position entry  376
- % change -13.198926650443346 



12081.38965  position entry  377
- % change -13.80098339928967 



11028.74023  position entry  378
- % change -31.510488936414095 



12390.69043  position entry  379
- % change -18.416966131886486 



11816.2002  position entry  380
- % change -29.13830141435823 



10575.62012  position entry  381
- % change -36.62158734952746 



10988.15039  position entry  382
- % change -41.046391794060604 



11468  position entry  383
- % change -35.48735987094525 



10466.48047  position entry  384
- % change -49.47689220691777 



11584.54981  position entry  385
- % change -22.921305648907214 



11455.54004  position entry  386
- % change -20.041485097895052 



12221.91016  position entry  387
- % change -16.35267600428835 



12226.58008  position entry  388
- % change -0.8838086308105172 



12935.29004  position entry  389
+ % change 6.601323877234072 



13787.91992  position entry  390
+ % change 20.01157321778237 



14032.80957  position entry  391
+ % change 11.701998319072173 



Total months in minus 83
Total months in plus 297
% ratio of long positions 78.15789473684211 % ratio of short positions 21.842105263157897




Comments