optimization

R optimisation max buy/sell dependent on stock level

﹥>﹥吖頭↗ 提交于 2020-06-01 05:03:19
问题 I would like to find a solution to an optimisation problem. The aim is to maximise profit by buying for low price and selling for a higher one. There are constraints such as maximum stock level, and max buy/sell number of units. Moreover, sell and buy limits depend on the inventory levels. I have asked a similar question albeit without the last condition here R optimisation buy sell. Here is an example: price = c(12, 11, 12, 13, 16, 17, 18, 17, 18, 16, 17, 13) capacity = 25 max_units_buy_30 =

How can I optimize a two variable function in R

纵饮孤独 提交于 2020-05-29 11:45:09
问题 I have been trying to optimize the following function, but without success: parametros <- data.frame(ap=c(11.1,7.07,6.3,4.75,4,3.35), fx=c(41.2012,39.3732,25.2912,10.3455,1.2253,0.4017)) xm<-11.2 fxcalc <- function(s,t){(1-(1-(parametros$ap/xm)^(s))^t)*100} suma <- function(s,t){(parametros$fx-fxcalc(s,t))^2} func <- function(s,t){sum(suma(s,t))} Being "func()" the function I am trying to minimize for "s" and "t". Apparently the function "optim()" wouldn't work with more than one variable.

How can I optimize a two variable function in R

与世无争的帅哥 提交于 2020-05-29 11:44:05
问题 I have been trying to optimize the following function, but without success: parametros <- data.frame(ap=c(11.1,7.07,6.3,4.75,4,3.35), fx=c(41.2012,39.3732,25.2912,10.3455,1.2253,0.4017)) xm<-11.2 fxcalc <- function(s,t){(1-(1-(parametros$ap/xm)^(s))^t)*100} suma <- function(s,t){(parametros$fx-fxcalc(s,t))^2} func <- function(s,t){sum(suma(s,t))} Being "func()" the function I am trying to minimize for "s" and "t". Apparently the function "optim()" wouldn't work with more than one variable.

solve linear equations given variables and uncertainties: scipy-optimize?

两盒软妹~` 提交于 2020-05-29 08:24:51
问题 I'd like to minimize a set of equations where the variables are known with their uncertainties. In essence I'd like to test the hypothesis that the given measured variables conform to the formula constraints given by the equations. This seems like something I should be able to do with scipy-optimize. For example I have three equations: 8 = 0.5 * x1 + 1.0 * x2 + 1.5 * x3 + 2.0 * x4 4 = 0.0 * x1 + 0.0 * x2 + 1.0 * x3 + 1.0 * x4 1 = 1.0 * x1 + 1.0 * x2 + 0.0 * x3 + 0.0 * x4 And four measured

solve linear equations given variables and uncertainties: scipy-optimize?

爱⌒轻易说出口 提交于 2020-05-29 08:23:49
问题 I'd like to minimize a set of equations where the variables are known with their uncertainties. In essence I'd like to test the hypothesis that the given measured variables conform to the formula constraints given by the equations. This seems like something I should be able to do with scipy-optimize. For example I have three equations: 8 = 0.5 * x1 + 1.0 * x2 + 1.5 * x3 + 2.0 * x4 4 = 0.0 * x1 + 0.0 * x2 + 1.0 * x3 + 1.0 * x4 1 = 1.0 * x1 + 1.0 * x2 + 0.0 * x3 + 0.0 * x4 And four measured

solve linear equations given variables and uncertainties: scipy-optimize?

柔情痞子 提交于 2020-05-29 08:23:28
问题 I'd like to minimize a set of equations where the variables are known with their uncertainties. In essence I'd like to test the hypothesis that the given measured variables conform to the formula constraints given by the equations. This seems like something I should be able to do with scipy-optimize. For example I have three equations: 8 = 0.5 * x1 + 1.0 * x2 + 1.5 * x3 + 2.0 * x4 4 = 0.0 * x1 + 0.0 * x2 + 1.0 * x3 + 1.0 * x4 1 = 1.0 * x1 + 1.0 * x2 + 0.0 * x3 + 0.0 * x4 And four measured

copy elision of return values and noexcept

江枫思渺然 提交于 2020-05-29 03:58:19
问题 I have a function template like this: template <typename T> constexpr auto myfunc() noexcept { return T{}; } Is this function template guaranteed to be noexcept because of copy elision? If an exception is thrown inside the constructor, does this happen inside or outside the function? 回答1: All that copy elision does is eliminate the actual copy or move. Everything happens "as-if" things happen without the copy-elision taking place (except for the copy itself, of course). The construction

Custom expected returns in the Portfolio Analytics package

北战南征 提交于 2020-05-28 15:51:50
问题 I have trouble incorporating custom expected returns in Portfolio Analytics package. Usually expected returns are some professional expectations / views or calculated separately from fundamental indicators. Portfolio Analytics allow to create custom moments function to calculate moments from past returns, but I don't understand how to incorporate already calculated returns to optimization problem. Any help is appreciated and here is small example dataset: #Download package and sample returns

Custom expected returns in the Portfolio Analytics package

谁说我不能喝 提交于 2020-05-28 15:44:46
问题 I have trouble incorporating custom expected returns in Portfolio Analytics package. Usually expected returns are some professional expectations / views or calculated separately from fundamental indicators. Portfolio Analytics allow to create custom moments function to calculate moments from past returns, but I don't understand how to incorporate already calculated returns to optimization problem. Any help is appreciated and here is small example dataset: #Download package and sample returns

C# Enum.HasFlag vs. Bitwise AND Operator Check

不想你离开。 提交于 2020-05-27 15:39:32
问题 If you have an enum that is used for bit flags, i.e., [Flags] internal enum _flagsEnum : byte { None = 0, //00000000 Option1 = 1, //00000001 Option2 = 1 << 1, //00000010 Option3 = 1 << 2, //00000100 Option4 = 1 << 3, //00001000 Option5 = 1 << 4, //00010000 Option6 = 1 << 5, //00100000 Option7 = 1 << 6, //01000000 Option8 = 1 << 7, //10000000 All = Byte.MaxValue,//11111111 } _flagsEnum myFlagsEnum = _flagsEnum.None; Is it faster to do.. bool hasFlag = myFlagsEnum.HasFlag(_flagsEnum.Option1);