fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. int main() {
  6. // std::vector<int> scv = {
  7. // -3, 13, 6, -29, -31, 43, 46, 8, 7, 21, 12, 6, 31, 38, 2, 31,
  8. // 12, -8, 23, 14, -22, 37, 24, 19, -2, 24, 17, 31, -6, 2, 4, 11,
  9. // -13, 41, 17, 4, 15, -9, -32, 33, 23, -6, 18, 32, 9, -6, 23, 9,
  10. // -15, 20, 3, 19, -16, 11, 8
  11. // };
  12. std::vector<int> scv = {
  13. -2, 11, 9, -26, -33, 35, 32, -3, 2, 11,
  14. 13, -3, 25, 28, 2, 30, 14, -4, 17, 20,
  15. -15, 32, 15, 13, -2, 29, 19, 32, 11, 10,
  16. -5, -1, -18, 34, 12, 3, 14, -4, -34, 28,
  17. 19, -4, 16, 31, 11, -3, 16, 14, -11, 24,
  18. 11, 19, -20, 17, 15
  19. };
  20.  
  21. std::vector<int> vti = {
  22. -2, 11, 12, -25, -36, 30, 21, -11, -1, 5, 16, -11, 19, 19, 1, 28,
  23. 15, -2, 12, 24, -10, 29, 6, 8, -1, 34, 19, 30, 24, 19, -13, -9,
  24. -25, 30, 8, 2, 12, 1, -37, 26, 16, -2, 14, 31, 12, 0, 11, 19,
  25. -7, 28, 19, 18, -24, 22, 20
  26. };
  27.  
  28. int t = vti.size();
  29. vector<double> tmp(t,1.0);
  30. vector<vector<double>> telltale(t, tmp), xirr(t, tmp);
  31.  
  32. for(int l=0;l< t;l++)
  33. {
  34. for(int r=l; r<t;r++)
  35. {
  36. int cnt = r-l+1;
  37. double d= 1.0;
  38. for(int k=0; k<cnt;k++)
  39. {
  40. double scv_r = (100.0 +scv[l+k])/100,
  41. vti_r = (100.0 +vti[l+k])/100;
  42. d = (d*scv_r)/vti_r;
  43. }
  44. telltale[l][r]= d;
  45. }
  46. }
  47. for(int l=0;l< t;l++)
  48. {
  49. for(int r=l; r<t;r++)
  50. {
  51. int cnt = r-l+1;
  52. double d= 0.0;
  53. for(int k=0; k<cnt;k++)
  54. {
  55. d+= telltale[l+k][r];
  56. }
  57. d = d/cnt;
  58. xirr[l][r]= d;
  59. }
  60. }
  61. vector<vector<double>> distribution_telltale_rolling_period(t+1);
  62. for(int l=0;l<t;l++)
  63. {
  64. for(int r=l;r<t;r++)
  65. {
  66. distribution_telltale_rolling_period[r-l+1].push_back(telltale[l][r]);
  67. }
  68. }
  69.  
  70. double prev =1.0;
  71. for(int i=0;i< t;i++)
  72. {
  73. double perc = ((telltale[0][i]- prev)/prev)*100;
  74. prev = telltale[0][i];
  75. cout<< perc<<endl;
  76. }
  77.  
  78. // for(int i=1;i< (t+1);i++)
  79. // {
  80. // sort(distribution_telltale_rolling_period[i].begin(),
  81. // distribution_telltale_rolling_period[i].end());
  82. // //cout<<"\n"<<i;
  83. // for(int j=0; j< distribution_telltale_rolling_period[i].size();j++)
  84. // {
  85. // cout<<"(";
  86. // cout<<i<<","<<distribution_telltale_rolling_period[i][j]<<"),";
  87. // }
  88. // }
  89. return 0;
  90. }
  91.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
0
0
-2.67857
-1.33333
4.6875
3.84615
9.09091
8.98876
3.0303
5.71429
-2.58621
8.98876
5.04202
7.56303
0.990099
1.5625
-0.869565
-2.04082
4.46429
-3.22581
-5.55556
2.32558
8.49057
4.62963
-1.0101
-3.73134
0
1.53846
-10.4839
-7.56303
9.1954
8.79121
9.33333
3.07692
3.7037
0.980392
1.78571
-4.9505
4.7619
1.5873
2.58621
-2.04082
1.75439
0
-0.892857
-3
4.5045
-4.20168
-4.30108
-3.125
-6.72269
0.847458
5.26316
-4.09836
-4.16667