| | 73 | '''Código en MMS_0.5''' |
| | 74 | |
| | 75 | El código que nos ocupa se separa en dos partes: |
| | 76 | |
| | 77 | (i) donde se definen constructores específicos para las transformaciones del proyecto: |
| | 78 | {{{ |
| | 79 | /////////////////////////////////////////////////////////////////////////////// |
| | 80 | @MMS.Transformation MMC_ExtendedNormalizeBoxCox(Real first, Real second, Date dat) |
| | 81 | ////////////////////////////////////////////////////////////////////////////// |
| | 82 | { |
| | 83 | @MMS.Transformation::Block(NameBlock { NameBlock args = [[ |
| | 84 | Text _.name = "MMC_ExtendedNormalizeBoxCox"<<first<<"_"<<second; |
| | 85 | Text _.grammar = "Serie"; |
| | 86 | Text _.contextExpression = " |
| | 87 | Real _.first = "<<first<<"; |
| | 88 | Real _.second = "<<second<<"; |
| | 89 | "; |
| | 90 | Text _.directExpression = If(first==0, |
| | 91 | "Serie (Serie s) { MMC_NomalizeExtendSerLastValue("+FormatDate(dat)+", Log(s + _.second)) }", |
| | 92 | "Serie (Serie s) { MMC_NomalizeExtendSerLastValue("+FormatDate(dat)+", ((s + _.second)**_.first - 1)/_.first ) }" |
| | 93 | ); |
| | 94 | Text _.inverseExpression = If(first==0, |
| | 95 | "Serie (Serie t) { MMC_NomalizeExtendSerLastValue("+FormatDate(dat)+", (Exp(t) - _.second) ) }", |
| | 96 | "Serie (Serie t) { MMC_NomalizeExtendSerLastValue("+FormatDate(dat)+", ((_.first * t + 1)**(1/_.first) - _.second) )}" |
| | 97 | ) |
| | 98 | ]] }) |
| | 99 | }; |
| | 100 | PutDescription(" |
| | 101 | Aplica una transformación logarítmica a la serie, la normaliza |
| | 102 | a la fecha dat y la extiende en previsión con el última dato", |
| | 103 | MMC_ExtendedNormalizeBoxCox |
| | 104 | ); |
| | 105 | }}} |
| | 106 | |
| | 107 | (ii) y donde se utilizan las transformaciones: |
| | 108 | {{{ |
| | 109 | Real model::CreateBaseExpTermOmega([[ |
| | 110 | ... |
| | 111 | @MMS.Transformation _.transformation = transformation; |
| | 112 | // donde: |
| | 113 | // transformation = MMC_ExtendedNormalizeBoxCox(0, 0, modelBegin) |
| | 114 | ... |
| | 115 | ]]); |
| | 116 | }}} |
| | 117 | |
| | 118 | '''Código en MMS_0.6''' |
| | 119 | |
| | 120 | Como alternativa a |
| | 121 | |
| | 122 | (i) los constructores específicos proponemos la creación de nuevas funciones: |
| | 123 | |
| | 124 | {{{ |
| | 125 | /////////////////////////////////////////////////////////////////////////////// |
| | 126 | Serie MMC_ExtendedNormalizeBoxCox(Serie s, Real first, Real second, Date dat) |
| | 127 | ////////////////////////////////////////////////////////////////////////////// |
| | 128 | { |
| | 129 | If(first==0, |
| | 130 | MMC_NomalizeExtendSerLastValue(dat, Log(s+ second)), |
| | 131 | MMC_NomalizeExtendSerLastValue(dat, ((s + second)**first - 1)/first) |
| | 132 | ) |
| | 133 | }; |
| | 134 | PutDescription(" |
| | 135 | Aplica una transformación logarítmica a la serie s, la normaliza |
| | 136 | a la fecha dat y la extiende en previsión con el último dato", |
| | 137 | MMC_ExtendedNormalizeBoxCox |
| | 138 | ); |
| | 139 | }}} |