Cody

Problem 45776. Algorithmic Trading - 1 (optimize simple trading strategy)

Solution 3215788

Submitted on 15 Oct 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, sign in.

Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('algo_trading_01.m'); filetext(find(filetext == '%', 1, 'last') : end) = []; assert(isempty(strfind(filetext, '>')), 'File handling is forbidden.'); assert(isempty(strfind(filetext, 'eval')), 'Eval forbidden.'); assert(isempty(strfind(filetext, 'regexp')), 'Regexp forbidden.'); assert(isempty(strfind(filetext, '!')), 'Shell commands are forbidden.'); assert(isempty(strfind(filetext, 'mlock')), 'mlock is forbidden.'); assert(isempty(strfind(filetext, 'munlock')), 'munlock is forbidden.'); assert(isempty(strfind(filetext, '@')), 'Anonymous functions are forbidden.');

2   Pass
P = [111.03 112.59 112.97 113.10 113.78 114.64 115.27 114.90 114.63 114.37 114.82 113.21 113.39 112.96 113.83 113.83 111.92 112.67 114.25 114.36 114.20 114.30 112.82 111.83 110.96 112.15 112.06 112.78 111.81 109.96 108.83 109.75 110.45 109.99 110.04 109.10 109.65 109.27 109.62 109.81 110.27 111.85 112.24 112.87 112.86 112.71 113.13 112.09 112.98 114.70 114.86 113.79 114.35 113.22 114.02 114.00 113.83 113.63 113.20 113.77 114.75 114.39 113.84 113.45 113.92 114.53 112.94 112.88 111.89 112.22 111.44 111.73 111.78 111.86 111.52 110.80 110.71 110.24 111.64 109.58 109.88 108.96 108.75 109.77 110.10 110.57 110.84 111.07 110.21 110.20 108.40 106.85 107.00 108.38 108.16 106.98 107.19 108.30 108.91 110.03 109.71 110.48 110.20 110.35 111.10 111.10 111.45 110.53 111.11 111.32 112.58 112.12 112.86 112.58 112.48 113.06 113.43 113.66 112.80 113.14 113.15 112.47 112.96 111.55 110.95 111.46 110.75 111.28 111.84 111.76 113.65 113.84 113.90 114.68 113.45 112.51 112.97 112.53 111.54 110.64 111.26 111.68 110.74 110.52 111.24 109.99 109.86 111.54 112.88 113.22 113.20 113.51 113.55 114.98 116.55 117.28 117.11 116.88 116.97 117.86 118.79 118.73 117.88 118.58 118.74 117.42 117.98 118.16 118.44 118.35 117.81 117.89 119.23 119.33 119.25 119.21 118.10 118.79 119.21 119.33 120.37 120.79 120.88 120.81 119.44 119.47 120.39 120.68 120.77 120.52 121.18 121.36 121.13 120.87 120.30 118.83 118.01 118.61 118.44 119.00 118.18 118.57 117.62 118.24 119.47 118.22 117.50 116.78 116.55 116.88 117.23 117.43 117.43 118.16 118.91 119.27 118.96 120.23 120.07 120.21 119.31 119.74 120.77 120.68 121.13 121.21 120.23 120.39 118.60 119.45 120.24 121.43 120.63 121.23 121.17 121.22 122.73 122.79 122.33 120.97 121.24 120.39 121.14 120.14 119.12 119.36 118.54 118.10 116.90 117.00 117.14 117.31 116.53 118.18 117.96 117.43 117.63 118.19 118.60 119.24 118.00 118.09 118.70 117.30 115.77 114.15 114.50 115.41 113.80 116.01 115.57 116.33 115.20 115.65 114.20 115.75 116.40 116.60 117.50 117.46 117.09 117.82 116.60 117.24 115.95 115.72 116.80 117.58 118.79 119.29 119.12 119.78 119.50 119.41 120.05 120.25 119.48 120.50 120.76 120.15 120.04 120.13 119.91 120.48 120.20 120.58 120.86 121.09 121.40 121.36 121.40 121.47 121.57 119.86 118.98 119.15 120.15 119.83 119.18 119.53 120.49 119.48 119.95 121.32 121.94 122.26 122.43 122.91 122.84 122.35 123.02 123.44 122.72 123.54 123.19 123.34 123.79 124.57 123.74 123.65 124.39 124.72 123.72 122.88 122.65 123.39 123.33 123.82 123.06 123.82 122.21 122.20 122.19 122.47 122.47 122.24 121.15 121.59 120.76 121.69 121.05 122.58 122.49 122.27 123.70 123.91 123.50 124.60 124.35 123.66 123.21 123.15 123.50 123.09 122.05 120.91 121.34 121.44 121.58 121.55 121.67 122.66 123.04 122.60 121.22 119.63 119.20 119.61 118.60 118.43 117.50 117.43 118.67 119.11 117.82 119.78 117.67 118.13 119.96 119.72 119.37 118.10 119.80 120.13 120.49 121.75 122.27 122.11 122.23 122.23 122.39 123.34 123.76 123.69 123.24 123.49 124.64 125.13 125.76 126.30 127.03 127.13 126.23 126.09 125.41 126.69 126.85 126.58 126.82 126.08 126.00 126.33 126.45 127.31 127.81 127.44 126.36 125.71 125.83 126.03 126.69 126.76 125.47 125.75 125.19 124.51 126.70 127.30 127.38 128.44 128.77 128.90 129.31 128.80 128.68 128.33 127.82 128.31 125.97 126.42 126.55 126.66 127.36 128.54 128.44 127.50 128.39 126.90 126.27 126.60 125.48 126.62 126.41 126.64 126.41 127.75 128.20 129.16 128.81 128.49 129.27 129.08 129.41 129.46 128.23 129.37 129.36 128.76 128.17 127.97 128.24 127.38 128.59 128.83 130.18 130.76 131.03 130.62 130.41 129.59 130.38 130.11 130.21 130.02 129.22 130.03 129.80 129.83 129.73 130.56 131.01 130.87 129.54 129.74 128.64 128.88 128.71 128.66 130.70 130.95 131.13 131.15 130.91 130.37 130.40 131.03 131.47 130.40 131.38 130.89 131.36 132.52 132.36 132.62 132.55 130.95 129.24 129.50 129.31 126.85 126.21 127.10 126.13 125.17 126.17 127.73 128.38 126.10 127.51 128.73 129.00 127.12 126.81 125.86 125.75 125.35 123.99 122.55 123.50 126.12 124.65 123.67 124.09 125.01 124.46 124.44 124.99 123.91 124.75 127.27 127.28 127.80 127.07 127.44 126.61 126.85 127.41 126.05 124.00 123.52 123.34 123.97 125.69 124.83 123.95 126.21 126.66 126.83 126.71 127.98 127.85 127.22 128.08 128.42 128.20 127.90 127.41 126.98 127.37 127.01 127.11 128.63 129.70 130.03 130.69 130.13 130.12 129.76 129.65 129.81 130.43 130.58 130.66 130.64 131.42 131.67 130.51 129.91 130.28 130.41 131.69 132.22 132.23 131.96 132.14 131.81 132.51 131.87 131.47 132.48 133.58 133.74 133.69 133.58 133.08 133.36 134.92 135.18 135.01 135.09 135.27 135.11 136.28 136.63 136.84 136.41 136.59 136.81 136.84 137.47 137.88 138.35 138.78 137.91 137.81 137.79 136.86 136.78 136.54 138.08 138.61 138.91 138.18 138.24 138.58 139.62 140.02 140.38 140.42 140.50 140.64 140.92 140.35 138.42 139.02 140.47 140.53 140.22 141.29 141.90 141.78 141.16 141.42 141.83 141.72 141.87 143.12 142.34 141.95 142.22 142.14 141.62 140.75 141.58 142.51 142.21 141.62 141.37 141.67 140.54 141.19 141.07 141.54 142.16 143.24 142.96 143.02 142.54 142.82 142.38 142.80 143.95 142.26 142.13 142.05 142.79 143.75 144.61 144.81 144.85 144.89 145.21 145.02 143.94 143.45 144.66 145.61 145.80 145.73 146.04 145.98 145.87 145.30 145.17 139.50 140.93 140.51 138.67 137.35 139.70 139.56 140.74 140.78 140.99 138.25 139.28 139.47 138.53 140.20 140.97 143.29 143.18 143.39 143.20 142.86 141.82 141.97 142.00 142.16 143.69 143.85 144.24 144.44 144.61 144.02 144.66 145.32 146.70 147.09 147.27 147.23 148.62 148.06 148.12 149.48 149.65 149.53 148.29 148.67 149.54 150.35 150.92 150.95 150.75 151.16 149.58 150.86 150.53 150.57 151.60 151.30 152.62 152.54 152.42 152.44 151.06 151.69 152.24 153.48 153.32 154.08 154.10 153.49 151.84 149.10 151.04 151.30 149.65 151.89 152.86 153.07 152.89 153.27 151.14 151.98 150.55 149.83 148.29 150.40 150.38 150.43 151.79 152.34 152.18 152.98 153.10 150.92 151.99 154.39 154.85 154.83 154.75 154.47 155.07 153.50 153.97 151.30 151.61 148.02 145.11 147.38 145.72 146.43 147.60 143.80 146.21 147.77 149.83 145.39 144.71 145.23 143.01 141.04 142.10 144.71 144.64 144.93 146.65 146.52 148.33 146.95 143.72 146.54 146.15 147.59 149.08 147.79 148.13 146.07 145.79 147.49 147.87 148.91 148.90 148.10 152.46 153.36 152.28 151.97 151.69 151.39 152.19 153.09 152.58 154.30 154.09 153.78 154.02 155.85 155.02 156.48 156.22 155.47 156.33 155.01 153.78 154.25 153.69 149.67 150.54 151.76 151.48 151.84 153.62 154.13 153.06 154.65 151.03 151.20 150.05 152.07 147.91 147.16 145.14 143.70 148.08 147.67 145.54 145.79 143.76 144.64 141.68 144.13 140.95 142.57 147.13 147.18 148.66 147.68 146.36 148.81 150.94 150.91 152.08 147.91 149.37 149.06 147.17 145.07 145.88 145.88 146.80 148.13 149.23 149.55 147.67 147.30 146.21 144.93 144.86 141.31 141.19 138.91 140.37 141.29 140.15 141.28 138.17 136.98 133.43 132.06 130.72 133.86 134.99 133.04 135.24 135.91 134.91 137.37 139.58 137.82 134.13 133.05 133.93 133.07 133.75 134.99 136.37 135.17 135.14 135.52 135.92 134.79 135.62 137.33 138.36 138.22 136.87 133.82 133.50 132.99 133.83 131.06 129.71 128.00 132.60 131.36 131.65 129.61 128.30 133.63 130.32 132.08 134.72 134.85 133.20 132.78 131.51 131.97 136.61 136.70 137.04 136.89 136.96 136.82 135.83 136.02 133.38 132.93 133.24 136.85 137.05 138.48 138.55 137.94 137.72 138.32 139.60 139.63 139.08 138.26 141.12 141.51 140.83 142.05 139.52 139.16 138.90 140.46 140.48 140.77 142.53 142.66 143.05 141.89 139.49 139.51 137.64 138.66 139.30 140.00 140.35 138.90 138.09 138.02 140.78 136.29 136.62 135.94 133.94 134.45 136.15 136.23 135.57 134.25 134.42 131.58 131.45 131.19 131.81 128.23 127.53 127.98 128.38 126.18 126.31 125.02 127.24 124.79 125.30 123.84 122.72 120.99 123.96 125.20 125.98 126.05 127.48 128.17 125.51 125.48 123.64 126.28 128.53 126.83 126.16 124.99 128.36 128.93 127.01 129.37 130.71 129.35 128.57 129.54 130.17 128.39 126.99 127.58 127.80 129.65 127.02 127.39 128.63 130.19 128.79 127.99 127.88 124.03 124.42 126.99 123.22 123.72 125.51 126.09 120.09 122.10 116.61 120.07 124.12 121.31 118.55 118.93 120.79 120.85 111.38 115.99 116.06 111.85 110.34 104.72 100.03 97.51 90.70 88.50 101.35 99.85 90.02 93.77 93.21 98.81 95.86 90.64 91.69 87.04 83.95 93.76 93.08 96.30 96.83 97.11 100.41 96.19 90.86 93.86 92.63 89.77 85.82 91.17 86.62 85.47 87.08 81.50 75.45 79.52 85.03 85.66 88.97 90.09 82.11 85.27 87.32 85.30 87.93 91.00 89.50 90.11 87.94 88.99 87.75 91.88 90.99 89.29 88.19 87.06 86.16 86.66 87.16 86.91 88.97 90.24 92.96 92.85 93.47 90.67 91.04 89.09 86.95 87.11 84.37 84.40 85.06 80.57 84.05 82.75 83.11 83.68 84.53 87.39 84.55 82.83 82.58 83.74 83.33 84.57 86.98 87.10 83.11 83.60 83.66 82.76 79.22 79.03 78.18 77.42 74.65 77.48 76.87 75.62 73.93 70.60 70.07 71.73 68.80 68.92 68.11 72.17 72.64 75.50 76.09 75.86 78.18 79.93 78.94 76.71 82.22 80.60 81.45 83.11 81.61 78.79 79.52 81.06 83.43 84.26 83.60 81.65 82.53 85.81 85.83 84.35 85.25 86.50 87.08 83.43 85.06 84.54 85.37 86.66 85.84 85.57 87.39 87.42 87.89 90.88 90.57 92.14 90.86 92.98 91.24 90.97 88.68 89.44 88.71 91.23 91.12 90.51 89.21 89.02 91.30 89.67 90.92 92.53 94.77 94.85 93.65 94.53 94.55 94.16 94.64 94.40 94.82 95.08 92.90 91.64 91.55 92.22 92.04 89.28 89.35 90.12 92.08 91.84 92.70 91.95 92.33 89.81 89.80 88.06 88.00 88.17 87.96 90.10 90.61 93.26 93.11 94.13 95.13 95.57 95.55 97.66 98.06 98.35 97.89 97.65 98.67 98.81 100.44 100.70 100.41 99.89 101.20 100.99 99.73 100.80 101.57 100.79 98.31 99.09 99.96 100.99 102.97 102.96 103.16 103.17 103.40 103.38 102.46 100.20 99.82 100.65 102.06 102.94 103.73 104.79 104.77 105.28 105.72 107.32 107.16 106.72 106.45 107.07 106.18 105.01 104.45 106.32 106.00 105.59 102.97 102.49 104.02 105.51 105.80 106.61 107.26 107.68 107.46 109.31 109.71 108.89 109.79 109.21 108.23 109.33 108.08 106.91 106.42 104.41 106.65 103.56 104.32 104.65 104.92 106.85 107.13 109.57 109.59 110.15 109.03 109.62 111.21 111.34 111.27 109.82 109.43 110.82 110.99 111.38 109.57 109.94 111.30 111.25 110.38 111.01 110.84 109.61 110.02 110.64 111.11 111.87 111.35 111.52 110.18 110.21 111.33 111.73 111.95 112.48 112.72 112.56 112.52 111.44 113.33 113.63 113.71 114.19 114.57 114.73 113.66 114.62 114.93 113.64 115.06 113.89 111.70 109.21 109.77 109.31 109.83 108.57 107.39 109.06 110.38 109.83 106.44 106.66 105.89 107.22 107.01 108.13 108.04 109.74 110.26 110.91 111.14 111.16 109.81 110.82 110.67 110.74 111.89 112.20 112.30 112.64 114.25 114.27 114.46 114.97 115.45 115.46 115.49 116.41 117.10 117.04 115.97 116.59 117.41 116.84 116.65 116.58 117.32 117.40 117.00 117.80 118.76 119.04 118.36 118.77 119.55 119.74 119.83 121.19 121.29 119.36 119.81 120.88 120.66 121.02 121.81 121.35 118.48 119.38 120.86 118.81 120.35 117.52 116.82 112.94 111.26 116.16 115.83 117.45 115.99 113.89 113.95 112.40 111.76 107.54 109.11 107.71 107.82 107.17 110.76 109.37 107.53 110.33 110.71 106.82 105.49 106.62 106.05 109.15 109.68 109.51 112.00 111.96 112.14 111.73 111.41 109.57 109.23 107.42 107.87 107.53 104.21 103.22 102.76 102.20 102.87 106.11 107.16 107.96 108.03 109.66 109.65 109.68 106.66 107.29 108.48 107.07 109.46 110.41 111.56 111.55 110.83 110.29 110.27 112.76 112.22 112.97 112.85 112.39 112.99 112.38 109.30 108.63 108.31 108.26 109.59 109.79 107.88 107.53 107.12 105.53 105.94 105.23 106.86 105.31 105.31 108.46 109.47 110.89 109.64 110.41 110.92 111.48 112.72 112.65 113.08 113.05 112.49 114.21 113.98 113.42 112.50 114.82 114.27 114.67 114.47 114.13 114.61 113.75 116.04 116.03 115.89 116.54 116.65 117.01 117.92 117.46 117.70 118.28 116.73 117.87 118.13 118.35 118.70 118.72 118.38 118.40 118.49 118.53 119.47 119.95 122.26 122.72 122.49 121.61 122.10 121.64 120.20 120.03 118.16 118.22 119.96 120.29 120.19 118.45 120.20 118.80 119.16 118.49 121.01 122.56 122.89 122.76 122.83 123.28 123.76 124.48 124.56 124.67 124.10 124.82 124.30 124.60 125.39 125.78 125.60 125.65 125.83 125.92 125.72 125.75 127.05 126.98 127.64 127.39 127.14 126.98 127.43 128.58 128.37 129.30 129.52 128.25 128.08 128.37 129.10 129.17 129.67 129.99 127.72 128.68 130.74 130.49 130.78 131.15 131.97 132.57 132.27 132.32 133.11 133.43 133.01 133.85 134.25 134.53 131.83 131.02 130.93 132.33 133.15 130.93 131.21 133.47 132.47 131.43 132.58 132.39 129.94 130.84 130.05 128.56 126.18 127.85 127.76 129.74 129.29 129.66 130.90 131.30 130.98 131.86 132.77 132.59 133.15 133.26 133.24 133.66 133.32 132.86 132.46 131.47 131.46 131.56 132.04 130.56 131.31 133.10 133.78 133.64 134.79 135.67 136.11 136.43 136.22 135.73 134.83 133.61 134.20 134.72 135.87 134.44 135.08 134.04 133.19 133.17 134.36 134.68 133.61 132.06 131.95 132.39 133.00 133.51 134.90 131.87 131.73 130.42 129.04 128.96 128.42 129.40 127.60 127.70 129.32 127.02 127.30 127.05 127.70 129.45 128.67 128.30 126.81 127.94 129.61 130.72 131.97 133.92 133.81 133.97 135.36 134.40 131.97 131.40 131.84 130.93 131.69 130.61 132.73 132.65 134.49 134.58 133.83 133.33 130.60 130.22 129.33 128.78 125.49 126.17 120.26 120.08 112.26 117.48 112.29 117.33 118.12 120.62 119.59 119.67 114.51 112.64 112.73 116.44 118.08 116.28 117.97 121.36 121.68 122.22 120.94 117.85 116.99 120.29 119.04 115.92 116.67 117.74 119.37 121.43 121.52 120.31 120.17 116.63 112.86 113.54 116.24 117.54 115.14 116.05 113.15 109.93 112.34 114.42 116.49 115.71 119.58 119.70 120.75 120.51 122.57 120.23 122.58 121.13 121.66 123.97 125.49 123.05 124.30 128.63 128.60 125.50 122.00 123.99 126.25 125.48 126.26 127.88 123.16 124.32 126.66 125.46 126.08 124.08 122.11 121.98 119.66 119.19 116.56 116.34 119.71 120.05 124.99 124.97 124.86 126.22 126.26 126.73 123.95 126.05 124.21 123.05 121.74 122.18 121.59 120.29 123.93 124.17 125.27 126.39 126.49 124.83 126.12 125.50 127.50 127.70 128.04 127.71 128.02 129.13 129.20 129.51 128.84 129.34 130.77 131.46 131.95 131.61 131.46 132.56 131.88 131.82 131.37 131.32 132.47 132.68 134.54 134.45 134.79 135.19 135.36 134.36 135.36 135.19 134.56 136.05 136.41 136.47 136.03 136.63 136.93 137.16 137.56 137.02 137.73 137.31 136.75]'; S = [-0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.9925 -0.6468 -0.3903 -0.0948 0.3202 0.7198 0.8918 1.1003 1.1333 1.1927 1.2565 1.2770 1.3978 1.3730 1.2430 1.1895 1.2230 1.1477 1.1202 1.1160 1.1787 1.1620 1.1742 1.1207 1.0347 0.7572 0.5485 0.3680 0.2783 0.1508 -0.0607 -0.1102 -0.1905 -0.0945 -0.2120 -0.1925 -0.3035 -0.4732 -0.5750 -0.6235 -0.5205 -0.4098 -0.2358 -0.3013 -0.1688 -0.2310 -0.4048 -0.5210 -0.6405 -0.8120 -1.1995 -1.5742 -1.8782 -2.0262 -2.0672 -1.9927 -1.6977 -1.4632 -1.2952 -1.0902 -0.7600 -0.4218 -0.3040 -0.1285 -0.0208 0.2440 0.4102 0.6710 0.8532 0.9523 1.0170 1.0403 1.1808 1.1923 1.2420 1.1608 1.0513 0.9555 0.7868 0.6185 0.4198 0.1218 -0.1297 -0.2300 -0.3715 -0.2938 -0.1170 -0.0483 0.2205 0.4230 0.5125 0.6997 0.8075 0.7175 0.5037 0.1592 -0.1487 -0.5453 -1.0655 -1.4045 -1.7975 -2.2650 -2.4870 -2.5288 -2.4655 -2.4205 -2.4183 -2.3093 -2.0283 -1.6620 -1.0370 -0.4132 -0.0125 0.2803 0.5993 0.9908 1.3845 1.6610 1.8293 1.8310 1.6172 1.4765 1.3510 1.2408 1.0848 0.7497 0.4025 0.3090 0.1868 0.0553 0.0348 -0.1495 -0.2760 -0.3463 -0.3420 -0.1247 0.1428 0.2645 0.3757 0.3662 0.4075 0.6405 0.8360 1.0005 1.1012 1.1622 1.2312 1.2907 1.3440 1.4667 1.4172 1.1907 1.0287 0.8250 0.6815 0.3800 0.0795 -0.3075 -0.5920 -0.6970 -0.7315 -0.7562 -0.9365 -1.1222 -1.3765 -1.5150 -1.6250 -1.6367 -1.5905 -1.6197 -1.4912 -1.3470 -0.9895 -0.6465 -0.3352 -0.1870 -0.0740 0.1555 0.3102 0.4830 0.6005 0.6820 0.6100 0.4155 0.3482 0.4127 0.5557 0.5087 0.5550 0.5560 0.5592 0.8122 1.0747 1.4473 1.6230 1.7690 1.6983 1.8003 1.7280 1.5473 1.3940 1.0163 0.5990 0.1405 -0.1225 -0.3560 -0.5207 -0.8572 -0.9332 -0.9633 -1.0395 -1.0030 -0.8583 -0.5488 -0.1505 0.0722 0.3085 0.6802 0.7130 0.5817 0.3575 0.1087 -0.0558 -0.4632 -0.7070 -0.8590 -0.9915 -1.3285 -1.5407 -1.7550 -1.6445 -1.5162 -1.4715 -1.1322 -1.0395 -0.9580 -0.8553 -0.7730 -0.6680 -0.5158 -0.5698 -0.5808 -0.5130 -0.4635 -0.3913 -0.3490 -0.3120 -0.1640 -0.1370 0.1393 0.4465 0.5860 0.7188 0.8105 0.7770 0.7840 0.7253 0.6855 0.7505 0.7138 0.6618 0.7583 0.7335 0.6955 0.6667 0.6392 0.6325 0.6652 0.5020 0.3035 0.0630 -0.0995 -0.3060 -0.6312 -0.8927 -1.0610 -1.3677 -1.6315 -1.5600 -1.3515 -1.1492 -1.0360 -0.8232 -0.5173 -0.2965 -0.1138 0.2205 0.4292 0.6098 0.6733 0.7610 0.8787 1.0292 1.0540 1.0967 1.1565 1.2595 1.3155 1.2100 1.1020 1.0930 0.9695 0.8310 0.7393 0.7122 0.4530 0.1742 -0.0210 -0.0997 -0.1505 -0.2703 -0.4810 -0.7235 -0.9423 -1.1267 -1.1820 -1.0827 -0.9745 -0.9405 -0.7650 -0.5300 -0.2435 0.0745 0.4405 0.6732 0.9832 1.1435 1.3497 1.5432 1.5130 1.3308 1.2340 1.0060 0.8130 0.7183 0.6258 0.6638 0.7043 0.6753 0.6415 0.5555 0.4535 0.3378 0.0932 -0.1385 -0.5015 -0.9938 -1.3685 -1.6645 -1.9688 -1.9333 -2.0910 -2.2455 -2.1245 -2.0253 -1.9028 -1.9183 -1.8975 -1.9000 -1.7518 -1.6888 -1.3405 -1.0222 -0.8825 -0.7362 -0.6107 -0.2780 -0.0563 0.0943 0.1780 0.1395 0.1540 0.2615 0.4095 0.5667 0.8392 1.0010 1.0585 1.1517 1.2110 1.3480 1.3525 1.3558 1.3213 1.1818 1.0098 0.8190 0.7112 0.7045 0.7892 0.7047 0.5167 0.2910 0.0642 -0.0768 -0.1288 -0.1653 -0.3427 -0.5040 -0.7690 -1.0500 -1.0042 -0.8735 -0.7797 -0.6145 -0.4267 -0.2512 0.1247 0.4435 0.7795 1.1745 1.2792 1.3812 1.2570 1.0900 0.8602 0.5902 0.3090 0.2085 0.1230 -0.0245 -0.0255 -0.2650 -0.3278 -0.3858 -0.6143 -0.6848 -0.8163 -1.0260 -1.2172 -1.1790 -1.1600 -0.9160 -0.6627 -0.5112 -0.1930 -0.0272 0.2150 0.3860 0.4888 0.5550 0.5848 0.4735 0.3725 0.3010 0.1348 -0.0705 -0.2258 -0.3753 -0.2793 -0.2785 -0.2178 -0.1100 0.0365 0.1427 0.3285 0.5887 0.7632 0.8350 0.6775 0.5580 0.3833 0.2668 0.1760 0.2188 0.2403 0.2635 0.1555 0.0472 -0.0838 -0.2768 -0.5143 -0.7255 -0.7232 -0.7435 -0.7362 -0.6635 -0.4985 -0.4080 -0.1635 0.1557 0.5070 0.7830 0.9722 1.0425 1.1230 1.2955 1.5337 1.8142 2.0750 2.1173 1.9880 1.9663 1.8563 1.5245 1.0978 0.6737 0.2035 -0.3615 -0.8788 -1.0388 -0.9378 -1.1073 -1.1533 -0.8168 -0.3730 -0.2090 0.0212 0.2560 0.3045 0.1685 -0.1525 -0.3752 -0.6468 -0.7592 -1.0917 -1.3910 -1.5768 -1.5290 -1.5748 -1.5940 -1.4157 -1.2687 -1.1352 -0.9648 -0.6638 -0.2078 0.0720 0.3350 0.5688 0.8385 1.0780 1.2603 1.1213 0.6850 0.2273 -0.2413 -0.4900 -0.8478 -1.1360 -1.2615 -1.4605 -1.5228 -1.3773 -1.0870 -0.7783 -0.5815 -0.4887 -0.2523 0.1092 0.1995 0.2050 0.1303 0.1163 -0.1010 -0.2955 -0.2320 -0.1665 -0.1625 -0.0857 -0.0715 -0.0067 0.1078 0.1575 0.2327 0.4247 0.4735 0.4435 0.3855 0.3460 0.3567 0.2327 0.1075 0.0415 -0.0205 -0.0310 -0.0547 -0.1028 -0.1617 -0.2917 -0.4817 -0.4437 -0.4122 -0.4582 -0.4050 -0.3730 -0.3827 -0.4130 -0.4307 -0.5282 -0.5595 -0.5127 -0.3847 -0.2125 -0.1113 -0.0953 -0.1170 -0.0298 0.1187 0.3030 0.4350 0.4347 0.4490 0.4750 0.5520 0.6178 0.7540 0.7913 0.6955 0.5920 0.5535 0.4010 0.2315 0.0805 -0.0070 -0.1118 -0.1960 -0.3820 -0.5060 -0.5993 -0.5790 -0.4143 -0.1827 0.0753 0.1953 0.2618 0.2995 0.3783 0.2685 0.1938 0.1723 0.1415 0.0763 0.0715 0.0940 0.0975 0.0025 -0.0053 0.2075 0.4160 0.4915 0.6965 0.8245 0.7925 0.7080 0.6605 0.6315 0.5105 0.4255 0.4575 0.4375 0.2117 0.0670 -0.0538 -0.2975 -0.4505 -0.5860 -0.6168 -0.6468 -0.6475 -0.6502 -0.6115 -0.5845 -0.5222 -0.3815 -0.2902 -0.0645 -0.0790 -0.1765 -0.3910 -0.5040 -0.5373 -0.4440 -0.3348 -0.0125 0.2285 0.3823 0.7258 1.0148 1.1758 1.4035 1.5978 1.7358 1.8570 2.1008 2.3018 2.4565 2.5847 2.7732 2.4135 2.0282 1.5375 0.7962 -0.0685 -0.7228 -1.3405 -1.8090 -2.1958 -2.5475 -2.6435 -2.7825 -2.8622 -2.8617 -2.5935 -2.4807 -2.1078 -1.8565 -1.6180 -1.4310 -1.0008 -0.7780 -0.5968 -0.3188 -0.1965 -0.1740 -0.3360 -0.4555 -0.5910 -0.7330 -0.8630 -0.8487 -0.7682 -0.5525 -0.3035 -0.2682 -0.1877 -0.0345 0.0275 0.1192 0.3995 0.6982 0.8832 0.8135 0.7410 0.7285 0.8095 0.7965 0.8295 0.8095 0.7367 0.4740 0.3605 0.3582 0.3675 0.4465 0.3820 0.4025 0.4878 0.5348 0.5230 0.5250 0.5013 0.5420 0.7575 0.8670 1.1225 1.2630 1.3580 1.2568 0.9018 0.8978 0.8370 0.5433 0.3485 0.2570 0.0680 -0.0545 -0.1130 -0.2785 -0.0718 -0.2090 -0.4092 -0.5935 -0.8088 -1.0833 -1.4200 -1.5203 -1.5975 -1.3570 -1.0518 -0.6293 -0.3108 0.2357 0.7407 1.3202 1.8810 2.2652 2.4737 2.9253 3.1810 3.4640 3.7490 4.0168 3.6058 2.8135 2.2163 1.4358 0.6728 0.0228 -0.8960 -1.5850 -1.7362 -1.7692 -1.8815 -1.7867 -1.9012 -2.0940 -2.5365 -2.8785 -2.5610 -2.5345 -2.6465 -2.8255 -2.5583 -2.0613 -1.8515 -1.8320 -1.2988 -0.9925 -0.8690 -0.5253 -0.4010 -0.4195 -0.5890 -1.1055 -1.2485 -0.9838 -0.8515 -0.8380 -1.0447 -0.9880 -0.7612 -0.7070 -0.4727 -0.1402 0.0213 0.2203 0.4623 0.7515 1.3163 1.3590 1.2070 1.2485 1.4498 1.6193 2.0288 2.2603 2.4258 2.6725 2.6370 2.4915 2.5375 2.5483 2.0242 1.6862 1.3237 0.9920 0.7975 0.6810 0.7912 0.8880 1.1907 1.1487 1.5925 1.8367 2.0417 1.8498 1.5158 0.8720 0.0455 -0.2607 -0.8267 -1.2617 -1.6965 -2.1480 -2.7808 -3.2740 -3.4140 -3.7180 -3.7145 -3.6625 -3.5945 -3.1898 -2.8910 -2.5165 -1.9648 -0.8550 -0.0565 1.2133 1.8770 2.3700 2.7260 2.7832 2.6415 2.6538 2.5590 2.3048 2.2110 2.1463 2.5685 2.7130 2.8110 2.9718 3.1068 3.2430 3.0833 2.8040 2.2258 1.5975 0.9410 0.4637 0.2820 -0.0755 -0.4168 -1.1888 -1.7233 -2.4185 -2.6535 -2.9440 -3.5005 -3.7325 -3.9975 -3.9900 -3.6107 -2.6902 -1.8815 -1.3135 -1.1610 -0.9892 -0.7022 -0.6432 -0.5512 -0.2090 -0.1625 -0.2742 -0.3155 0.1115 0.4485 0.8017 1.3560 1.7777 2.1107 2.2052 2.0770 1.8677 1.6657 1.5350 1.2470 0.7910 -0.0677 -0.6157 -1.3745 -1.9925 -2.4892 -3.1030 -3.0910 -3.4677 -3.2910 -2.7340 -2.0015 -1.9747 -1.8610 -1.9672 -1.8045 -0.9888 -0.6658 0.0037 0.4165 0.4952 0.5527 0.6840 0.8257 0.7515 0.5695 -0.1188 -0.2767 -0.4707 -0.4930 -0.6052 -0.7977 -0.7872 -0.8625 -0.5050 -0.0432 0.3648 0.3485 0.5873 0.7370 0.7977 1.1415 1.2390 1.2402 1.1200 1.1747 1.2847 1.4120 1.5462 1.5803 1.7270 1.6935 1.7505 1.8080 1.7383 1.6328 1.6070 1.6125 1.5630 1.3908 1.1058 0.9005 1.2803 1.2980 1.5342 1.5735 1.4342 1.2095 1.1430 1.1675 1.3072 1.3097 1.0970 1.1212 1.1460 1.1482 1.3525 1.0682 0.5427 -0.0282 -0.4850 -0.9472 -1.3952 -1.6335 -1.7390 -2.1400 -2.5112 -2.5847 -2.7832 -3.2758 -3.5425 -3.4673 -3.3733 -3.1343 -2.9382 -2.4253 -2.2865 -2.0162 -1.8445 -1.2040 -0.6567 -0.3935 -0.4110 -0.5042 -0.4015 -0.3318 -0.2820 0.0450 0.6778 0.9688 0.9918 1.2848 1.6070 1.9345 1.7292 1.5555 1.6123 1.7875 1.5173 1.5930 1.8015 1.9013 1.8675 1.9547 2.2275 2.0660 1.8775 1.9810 1.8260 1.7665 1.8815 1.8882 1.6345 1.8125 1.4815 2.0323 3.0283 3.1808 3.4273 3.8725 4.2458 4.5865 4.4865 4.6545 5.5183 5.6198 5.3205 4.7825 3.7862 2.5142 0.1985 -2.3468 -2.6028 -3.6465 -5.5623 -6.5040 -7.4113 -7.3158 -6.9245 -6.8418 -6.0203 -5.2288 -6.0728 -5.8950 -4.6532 -3.2667 -1.8715 -1.3827 -0.1695 1.0628 1.5238 2.9115 4.2658 4.1845 3.7638 3.3200 2.2365 1.3688 0.2793 -1.1378 -2.5593 -3.8568 -4.4435 -4.7328 -4.3840 -4.4045 -4.8560 -4.9313 -4.7298 -4.2018 -2.7190 -1.3745 -0.7558 -0.1245 -0.1440 -0.3192 0.3245 1.0252 1.4092 1.7800 1.9075 1.5697 1.2625 0.9680 0.9133 0.4903 0.5315 0.4155 0.6620 1.1290 1.7245 2.0245 2.5735 2.9350 2.9530 3.0880 2.7887 2.2677 1.5530 0.4457 -0.3615 -1.0513 -1.6163 -1.8630 -1.8485 -1.5703 -1.3113 -1.1805 -1.1990 -0.6247 -0.4145 0.1435 1.0215 1.9358 2.3218 2.5595 3.0143 3.5805 3.6675 3.5543 3.3295 2.8215 1.8020 1.0120 0.4040 -0.2662 -1.0882 -2.2820 -3.1200 -3.7730 -4.6040 -5.3805 -5.9335 -6.3880 -6.7440 -6.7585 -6.5348 -5.9243 -4.9770 -4.1425 -3.1838 -2.4590 -1.0878 -0.3955 0.2987 0.8372 1.2390 1.2717 1.2292 1.1297 1.3027 1.7600 1.5237 1.1957 0.9115 0.7042 0.5773 0.5717 0.6455 0.7340 0.6620 0.2003 -0.0315 -0.0050 0.0413 -0.1180 -0.4800 -0.5805 -0.6142 -0.7163 -0.7830 -0.2803 -0.0013 0.4737 0.7360 1.0845 1.3597 1.6485 1.4555 1.3570 1.2302 1.0450 0.8488 0.4465 0.0670 -0.4745 -0.6737 -0.9660 -0.9340 -0.7918 -0.2513 0.0230 0.1622 0.4470 0.8705 1.2642 1.5715 2.0005 2.4488 2.7303 2.6663 2.4263 2.2863 2.0733 1.8058 1.2703 0.6905 0.2128 -0.1517 -0.6237 -0.8075 -0.8828 -1.0045 -1.4240 -1.7935 -1.9935 -2.1985 -2.5190 -3.0380 -3.3593 -3.7318 -3.7450 -3.8043 -3.5318 -3.1465 -2.5663 -2.0403 -1.3417 -0.5460 0.1223 0.6050 0.7788 1.0630 1.2588 1.5118 1.7633 1.9688 1.9150 1.8897 1.8372 1.7178 1.7373 1.7153 1.5608 1.0268 0.5378 0.2045 0.0230 -0.0788 -0.1465 -0.0972 -0.1505 -0.1940 -0.1448 0.0522 -0.0440 -0.2420 -0.4205 -0.6993 -0.8402 -0.9055 -0.8075 -0.7355 -0.6160 -0.4030 0.1573 0.7460 1.2108 1.4775 1.6618 1.6513 1.4295 1.2000 1.1335 1.0053 0.7055 0.1325 -0.4075 -0.7388 -0.9938 -1.1370 -1.1478 -0.9395 -0.8600 -0.7568 -0.4145 0.2080 0.7890 1.2588 1.5320 1.7043 1.9295 1.9390 1.7430 1.5323 0.9150 0.4888 -0.1687 -0.8282 -1.4090 -1.8847 -2.2977 -2.5790 -2.4950 -2.3215 -1.8620 -1.7340 -1.2175 -0.5768 0.0282 0.6300 0.8920 1.0475 1.1335 1.2157 1.2900 1.3220 1.2727 1.1612 1.0140 0.7233 0.6905 0.6065 0.2805 0.0138 -0.2705 -0.2860 -0.2575 -0.3680 -0.4655 -0.6000 -0.7958 -0.8718 -0.7528 -0.6173 -0.5280 -0.4687 -0.4565 -0.2993 -0.2767 0.0900 0.4255 0.6978 1.0415 1.3583 1.5833 1.7068 2.0228 2.3375 2.6608 2.9193 3.0478 2.9403 2.5250 2.0895 1.5455 1.1450 0.5447 -0.1950 -0.5995 -1.0260 -1.3808 -1.8613 -2.1005 -2.5075 -2.6907 -2.9480 -3.0055 -2.9425 -2.8717 -2.8897 -2.8265 -2.3775 -1.9415 -1.6187 -1.3097 -1.0225 -0.8682 -0.6677 -0.6127 -0.5970 -0.5945 -0.4838 -0.4210 -0.1645 0.0850 0.3637 0.5277 0.5782 0.6875 0.8787 1.0052 0.8870 0.8242 0.8330 0.7442 0.6530 0.5483 0.4883 0.3160 0.0510 -0.1515 -0.1377 -0.0575 -0.1420 -0.1630 -0.0272 0.1363 0.3060 0.6260 1.1058 1.3665 1.4540 1.6295 1.8335 2.0863 2.3910 2.6025 2.5722 2.5325 2.7220 2.8555 3.1312 3.0327 2.9045 2.2525 1.4082 1.1700 1.1228 1.1210 0.9327 0.7922 0.4802 0.3128 0.1078 -0.1420 -0.1107 -0.7605 -1.3385 -2.1535 -2.4443 -2.6362 -2.9837 -2.9595 -2.7655 -2.5128 -2.5928 -2.2983 -2.1177 -1.5682 -1.4077 -1.1840 -0.4857 -0.1060 0.2742 0.9643 1.6620 2.0645 2.4505 2.4050 2.2303 2.0480 1.2850 0.3700 -0.6490 -1.6220 -2.5305 -2.9590 -3.1650 -3.1000 -3.2325 -3.1878 -2.8025 -2.3265 -2.0175 -1.5912 -1.1020 -0.9385 -0.6252 -0.2845 0.1553 0.3898 0.5023 0.5970 0.9553 1.5210 1.9450 2.4918 2.7805 2.8760 2.9412 2.9632 2.7515 2.5277 2.2585 1.7682 1.4865 1.1367 0.5947 -0.0428 -0.7638 -1.5638 -2.0493 -2.4650 -2.7050 -3.0605 -3.5352 -3.7100 -3.6642 -3.4282 -3.2240 -2.7922 -2.3232 -1.7422 -1.1902 -0.5325 0.1533 0.4475 0.5518 0.6753 0.8905 0.9833 0.9495 1.0380 0.9243 0.8860 0.7165 0.5197 0.4037 0.0617 -0.0675 -0.1333 -0.0428 -0.0963 -0.0492 -0.0610 0.0455 0.0950 0.1230 0.3317 0.1768 0.1353 0.1445 0.1328 0.1922 0.2587 0.1847 0.0922 0.0345 -0.0885 0.0910 0.1557 0.4520 0.7752 1.0357 1.2005 1.4092 1.5582 1.5737 1.5692 1.2815 0.9625 0.5570 0.1425 -0.2472 -0.7475 -1.1113 -1.5495 -1.8097 -2.1310 -2.0225 -1.7690 -1.6572 -1.5937 -1.5145 -1.1877 -0.9767 -0.5285 -0.0950 0.3943 0.5587 0.6587 0.6663 0.6695 0.7117 0.7065 0.6135 0.4915 0.4195 0.3472 0.2612 0.1317 0.1475 0.1228 0.0603 0.0535 0.0545 -0.0087 -0.0420 0.0253 0.0935 0.2433 0.2880 0.2222 0.0750 -0.0523 -0.0715 -0.0702 -0.0775 -0.1580 -0.4417 -0.6595 -0.6718 -0.5752 -0.4655 -0.3733 -0.2158 0.0203 0.1180 0.2303 0.6683 1.0073 1.0990 1.3723 1.6628 1.9588 1.9633 1.8918 1.7677 1.7767 1.7465 1.4917 1.2995 1.2307 1.0200 0.6285 0.6240 0.7102 0.5587 0.3505 -0.0122 -0.2810 -0.8113 -1.3995 -1.8840 -2.0367 -2.3168 -2.5510 -2.3978 -2.2965 -2.1043 -1.7613 -1.1542 -0.7515 -0.2453 0.0657 0.3422 0.6197 0.7878 0.8500 0.8905 0.7953 0.6338 0.4243 0.2163 -0.1992 -0.5392 -0.8177 -0.9265 -0.9842 -0.8370 -0.5438 -0.2043 0.2150 0.6140 1.1067 1.4455 1.4907 1.5097 1.5740 1.7167 1.6315 1.6095 1.4775 1.2720 1.1170 1.1218 1.3253 1.3628 1.1648 0.8613 0.7565 0.6997 0.7988 1.0745 1.0975 1.0187 0.8252 0.5805 0.4357 0.2080 -0.0195 -0.5673 -1.1385 -1.6778 -2.1500 -2.5920 -2.8512 -2.9192 -2.8365 -2.7555 -2.7987 -2.7760 -2.7300 -2.7157 -2.4092 -1.9970 -1.3307 -0.7152 -0.1557 0.5545 1.2245 1.7815 2.2162 2.5090 2.7340 2.9390 2.9915 3.1390 3.4327 3.5880 3.8355 4.1822 4.5780 4.6985 4.9815 5.1370 5.3060 4.8695 4.5098 3.4478 2.3478 0.5048 -0.7770 -2.3142 -3.2427 -3.9500 -4.3915 -4.7037 -5.0337 -5.2335 -5.6020 -5.2332 -5.0032 -4.1437 -3.9245 -3.5828 -3.1673 -2.5407 -1.8422 -0.7822 0.0660 0.7730 1.4168 1.7657 1.9075 2.0312 1.6672 1.5127 1.3287 1.4272 1.6367 1.9777 1.5827 0.9437 0.5042 0.2715 0.0052 -0.5350 -1.1625 -2.1918 -3.4177 -4.2430 -4.5295 -4.3268 -4.3013 -4.1585 -4.0678 -3.5993 -3.3335 -2.6305 -1.8403 -1.0698 -0.4935 -0.0487 0.6488 1.1110 1.2983 1.4670 2.0478 2.4398 2.8813 2.7820 3.0325 3.4843 3.4713 3.2953 3.4620 3.0843 2.4440 1.9872 1.8162 2.0485 1.9775 1.4250 1.0340 0.3035 -0.5445 -1.2307 -2.0270 -2.6300 -3.1320 -3.2690 -3.2043 -2.8733 -2.3965 -1.7198 -1.0688 -0.3675 0.5723 0.9668 1.2223 0.9015 0.5010 0.0537 -0.6027 -0.9370 -1.2620 -1.2615 -1.4440 -1.4530 -1.5823 -1.4548 -1.4953 -1.3098 -0.8730 -0.7563 -0.5618 -0.4455 -0.3618 -0.2523 0.0087 0.0877 0.2007 0.2992 0.3965 0.5048 0.5543 0.5730 0.5918 0.4658 0.3848 0.3303 0.2593 0.1733 0.0343 -0.0150 -0.0170 0.0280 0.0352 0.1430 0.1792 0.4022 0.5975 0.6087 0.7365 0.7217 0.6433 0.5030 0.3983 0.3343 0.3918 0.3910 0.3553 0.5063 0.4380 0.2272 -0.1898 -0.4525 -0.6055 -0.7447 -0.8853 -0.8055]'; n=length(P); tic; t = algo_trading_01(P,S); assert(toc < 5,'Time out')

3   Fail
assert(isscalar(t),'Need to return a scalar value')

Unrecognized function or variable 't'. Error in Test3 (line 1) assert(isscalar(t),'Need to return a scalar value')

4   Fail
D = P(2:end)./P(1:end-1)-1; R = D.*(S(1:n-1) > t); cR = cumprod(R+1)-1; CAGR = (1+cR(end))^(252/n)-1; assert(CAGR > 0.12, 'Solution is sub-optimal');

The end operator must be used within an array index expression. Error in Test4 (line 1) D = P(2:end)./P(1:end-1)-1;

Suggested Problems

More from this Author10

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!