Replies: 2 comments 1 reply
-
Hi @kennyd88, is the unit fund data included in the model point set? If so, you could implement something like this: input.py main = ModelPointSet(data=pd.DataFrame({
"id": [1, 2, 3],
"fund_value": [100, 300, 200]
})) model.py @variable()
def decrement():
total_fund = main.data["fund_value"].sum()
if total_fund < 500:
return 0.02
else:
return 0.01 The |
Beta Was this translation helpful? Give feedback.
-
The model processes model points sequentially, so it's not possible to directly use the aggregated output of all MPFs at the model point level. A feature allowing calculations to run in multiple loops would need to be developed and added to the package. If the decrement impacts the fund, then the new feature would be necessary. However, if the decrement does not affect the fund, you can use one of the simplified approaches shown below, which may work for your model. 1. Preprocess in pandas If the calculations are relatively straightforward, you can preprocess the input using pandas. input.py import pandas as pd
from cashflower import ModelPointSet
from settings import settings
main = ModelPointSet(data=pd.DataFrame({
"id": [1, 2, 3],
"fund_value": [100, 300, 200]
}))
# Fund value development (assumption: investment return = 0.5%, charge = 0.25)
rows = settings["T_MAX_CALCULATION"]+1
fund_value = pd.DataFrame(index=range(rows), columns=main.data["id"])
fund_value.iloc[0] = main.data["fund_value"]
for i in range(1, rows):
fund_value.iloc[i] = fund_value.iloc[i - 1] * 1.005 - 0.25
fund_value["total"] = fund_value.sum(axis=1)
assumption = {
"fund_value": fund_value
} model.py from cashflower import variable
from input import assumption
@variable()
def decrement(t):
total_fund = assumption["fund_value"]["total"].iloc[t]
if total_fund < 630:
return 0.02
else:
return 0.01 2. Split into two models Alternatively, you can split the model into two separate cash flow models. The first model will calculate the fund value, and the second will use the output from the first model to determine the decrement. fund/input.py import pandas as pd
from cashflower import ModelPointSet
main = ModelPointSet(data=pd.DataFrame({
"id": [1, 2, 3],
"fund_value": [100, 300, 200]
})) fund/model.py from cashflower import variable
from input import main
@variable()
def fund_value(t):
if t == 0:
return main.get("fund_value")
else:
return fund_value(t - 1) * 1.005 - 0.25 fund/run.py import os
from cashflower import run
from settings import settings
if __name__ == "__main__":
output = run(settings=settings, path=os.path.dirname(__file__))
output.to_csv("output/fund_value.csv") account/input.py import pandas as pd
assumption = {
"fund": pd.read_csv("../fund/output/fund_value.csv")
} account/model.py from cashflower import variable
from input import assumption
@variable()
def fund_value(t):
return assumption.get("fund")["fund_value"].iloc[t] |
Beta Was this translation helpful? Give feedback.
-
Hi,
Is it possible in cashflower to calculate the sum of a variable over all MPFs to determine MPF level calculations?
For example, I have a unit-linked fund and I want to use a different decrement assumption per MPF depending if the size of the unit fund exceeds a threshold.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions