Search code examples
rquantitative-finance

sum function with variables R


I am new in R and I am trying to create the function below for several terms. Is there any way to create the sum of this function: (1,000 * ( 1.1 )^ −2 + 2,000 * ( 1.1 )^−4) where the numbers 1.000,2000 are variables and the numbers 2,4 correspond to these variables? (For example 1000—>2 and 2000—>4) (This example has just 2 terms and 4 variables and I want to create the sum for terms=variables/2)


Solution

  • Do you mean something like this?

    a <- c(1000, 2000)
    b <- c(2, 4)
    sum(a * 1.1^(-b))